@@ -6,6 +6,10 @@ import { ConfigurationError } from './errors';
6
6
import { validateChannelMapping } from './validators' ;
7
7
import { formatFromDiscordToIRC , formatFromIRCToDiscord } from './formatting' ;
8
8
9
+ // Usernames need to be between 2 and 32 characters for webhooks:
10
+ const USERNAME_MIN_LENGTH = 2 ;
11
+ const USERNAME_MAX_LENGTH = 32 ;
12
+
9
13
const REQUIRED_FIELDS = [ 'server' , 'nickname' , 'channelMapping' , 'discordToken' ] ;
10
14
const NICK_COLORS = [ 'light_blue' , 'dark_blue' , 'light_red' , 'dark_red' , 'light_green' ,
11
15
'dark_green' , 'magenta' , 'light_magenta' , 'orange' , 'yellow' , 'cyan' , 'light_cyan' ] ;
@@ -544,18 +548,17 @@ class Bot {
544
548
545
549
// discord matches channel names case insensitively
546
550
const chan = guild . channels . find ( x => Bot . caseComp ( x . name , channelName ) ) ;
547
- if ( chan ) return chan ;
548
-
549
- return match ;
551
+ return chan || match ;
550
552
} ) ;
551
553
552
554
// Webhooks first
553
555
const webhook = this . findWebhook ( channel ) ;
554
556
if ( webhook ) {
555
557
logger . debug ( 'Sending message to Discord via webhook' , withMentions , channel , '->' , `#${ discordChannel . name } ` ) ;
556
558
const avatarURL = this . getDiscordAvatar ( author , channel ) ;
559
+ const username = _ . padEnd ( author . substring ( 0 , USERNAME_MAX_LENGTH ) , USERNAME_MIN_LENGTH , '_' ) ;
557
560
webhook . client . sendMessage ( withMentions , {
558
- username : _ . padEnd ( author . substring ( 0 , 32 ) , 2 , '_' ) ,
561
+ username,
559
562
text,
560
563
avatarURL
561
564
} ) . catch ( logger . error ) ;
0 commit comments