File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,11 @@ class Bot {
141
141
const channel = this . discord . channels . get ( channelId ) ;
142
142
return `#${ channel . name } ` ;
143
143
} )
144
+ . replace ( / < @ & ( \d + ) > / g, ( match , roleId ) => {
145
+ const role = message . guild . roles . get ( roleId ) ;
146
+ if ( role ) return `@${ role . name } ` ;
147
+ return '@deleted-role' ;
148
+ } )
144
149
. replace ( / < ( : \w + : ) \d + > / g, ( match , emoteName ) => emoteName ) ;
145
150
}
146
151
Original file line number Diff line number Diff line change @@ -44,11 +44,22 @@ describe('Bot', function () {
44
44
return attachments ;
45
45
} ;
46
46
47
+ const getRole = ( key , value ) => {
48
+ if ( key !== '12345' && value === undefined ) return null ;
49
+ return {
50
+ name : 'example-role' ,
51
+ id : 12345
52
+ } ;
53
+ } ;
54
+
47
55
const createGuildStub = ( nickname = null ) => ( {
48
56
members : {
49
57
get ( ) {
50
58
return { nickname } ;
51
59
}
60
+ } ,
61
+ roles : {
62
+ get : getRole
52
63
}
53
64
} ) ;
54
65
@@ -413,4 +424,43 @@ describe('Bot', function () {
413
424
this . bot . sendToDiscord ( username , '#irc' , text ) ;
414
425
this . sendMessageStub . should . have . been . calledWith ( expected ) ;
415
426
} ) ;
427
+
428
+ it ( 'should convert role mentions from discord' , function ( ) {
429
+ const text = '<@&12345>' ;
430
+ const guild = createGuildStub ( ) ;
431
+ const message = {
432
+ content : text ,
433
+ mentions : { users : [ ] } ,
434
+ channel : {
435
+ name : 'discord'
436
+ } ,
437
+ author : {
438
+ username : 'test' ,
439
+ id : 'not bot id'
440
+ } ,
441
+ guild
442
+ } ;
443
+
444
+ this . bot . parseText ( message ) . should . equal ( '@example-role' ) ;
445
+ } ) ;
446
+
447
+ it ( 'should use @deleted-role when referenced role fails to exist' , function ( ) {
448
+ const text = '<@&12346>' ;
449
+ const guild = createGuildStub ( ) ;
450
+ const message = {
451
+ content : text ,
452
+ mentions : { users : [ ] } ,
453
+ channel : {
454
+ name : 'discord'
455
+ } ,
456
+ author : {
457
+ username : 'test' ,
458
+ id : 'not bot id'
459
+ } ,
460
+ guild
461
+ } ;
462
+
463
+ // Discord displays "@deleted-role" if role doesn't exist (e.g. <@&12346>)
464
+ this . bot . parseText ( message ) . should . equal ( '@deleted-role' ) ;
465
+ } ) ;
416
466
} ) ;
You can’t perform that action at this time.
0 commit comments