@@ -9,6 +9,7 @@ import Bot from '../lib/bot';
9
9
import createDiscordStub from './stubs/discord-stub' ;
10
10
import ClientStub from './stubs/irc-client-stub' ;
11
11
import config from './fixtures/single-test-config.json' ;
12
+ import configMsgFormatDefault from './fixtures/msg-formats-default.json' ;
12
13
13
14
chai . should ( ) ;
14
15
chai . use ( sinonChai ) ;
@@ -569,4 +570,178 @@ describe('Bot', function () {
569
570
this . bot . sendToDiscord ( username , '#irc' , text ) ;
570
571
this . sendMessageStub . should . have . been . calledWith ( expected ) ;
571
572
} ) ;
573
+
574
+ it ( 'should successfully send messages with default config' , function ( ) {
575
+ const bot = new Bot ( configMsgFormatDefault ) ;
576
+ bot . connect ( ) ;
577
+
578
+ bot . sendToDiscord ( 'testuser' , '#irc' , 'test message' ) ;
579
+ this . sendMessageStub . should . have . been . calledOnce ;
580
+
581
+ const guild = createGuildStub ( ) ;
582
+ const message = {
583
+ content : 'test message' ,
584
+ mentions : { users : [ ] } ,
585
+ channel : {
586
+ name : 'discord'
587
+ } ,
588
+ author : {
589
+ username : 'otherauthor' ,
590
+ id : 'not bot id'
591
+ } ,
592
+ guild
593
+ } ;
594
+
595
+ bot . sendToIRC ( message ) ;
596
+ this . sendMessageStub . should . have . been . calledOnce ;
597
+ } ) ;
598
+
599
+ it ( 'should not replace unmatched patterns' , function ( ) {
600
+ const format = { discord : '{$unmatchedPattern} stays intact: {$author} {$text}' } ;
601
+ const bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
602
+ bot . connect ( ) ;
603
+
604
+ const username = 'testuser' ;
605
+ const msg = 'test message' ;
606
+ const expected = `{$unmatchedPattern} stays intact: ${ username } ${ msg } ` ;
607
+ bot . sendToDiscord ( username , '#irc' , msg ) ;
608
+ this . sendMessageStub . should . have . been . calledWith ( expected ) ;
609
+ } ) ;
610
+
611
+ it ( 'should respect custom formatting for Discord' , function ( ) {
612
+ const format = { discord : '<{$author}> {$ircChannel} => {$discordChannel}: {$text}' } ;
613
+ const bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
614
+ bot . connect ( ) ;
615
+
616
+ const username = 'test' ;
617
+ const msg = 'test @user <#1234>' ;
618
+ const expected = `<test> #irc => #discord: ${ msg } ` ;
619
+ bot . sendToDiscord ( username , '#irc' , msg ) ;
620
+ this . sendMessageStub . should . have . been . calledWith ( expected ) ;
621
+ } ) ;
622
+
623
+ it ( 'should successfully send messages with default config' , function ( ) {
624
+ this . bot = new Bot ( configMsgFormatDefault ) ;
625
+ this . bot . connect ( ) ;
626
+
627
+ this . bot . sendToDiscord ( 'testuser' , '#irc' , 'test message' ) ;
628
+ this . sendMessageStub . should . have . been . calledOnce ;
629
+
630
+ const guild = createGuildStub ( ) ;
631
+ const message = {
632
+ content : 'test message' ,
633
+ mentions : { users : [ ] } ,
634
+ channel : {
635
+ name : 'discord'
636
+ } ,
637
+ author : {
638
+ username : 'otherauthor' ,
639
+ id : 'not bot id'
640
+ } ,
641
+ guild
642
+ } ;
643
+
644
+ this . bot . sendToIRC ( message ) ;
645
+ this . sendMessageStub . should . have . been . calledOnce ;
646
+ } ) ;
647
+
648
+ it ( 'should not replace unmatched patterns' , function ( ) {
649
+ const format = { discord : '{$unmatchedPattern} stays intact: {$author} {$text}' } ;
650
+ this . bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
651
+ this . bot . connect ( ) ;
652
+
653
+ const username = 'testuser' ;
654
+ const msg = 'test message' ;
655
+ const expected = `{$unmatchedPattern} stays intact: ${ username } ${ msg } ` ;
656
+ this . bot . sendToDiscord ( username , '#irc' , msg ) ;
657
+ this . sendMessageStub . should . have . been . calledWith ( expected ) ;
658
+ } ) ;
659
+
660
+ it ( 'should respect custom formatting for Discord' , function ( ) {
661
+ const format = { discord : '<{$author}> {$ircChannel} => {$discordChannel}: {$text}' } ;
662
+ this . bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
663
+ this . bot . connect ( ) ;
664
+
665
+ const username = 'test' ;
666
+ const msg = 'test @user <#1234>' ;
667
+ const expected = `<test> #irc => #discord: ${ msg } ` ;
668
+ this . bot . sendToDiscord ( username , '#irc' , msg ) ;
669
+ this . sendMessageStub . should . have . been . calledWith ( expected ) ;
670
+ } ) ;
671
+
672
+ it ( 'should respect custom formatting for regular IRC output' , function ( ) {
673
+ const format = { ircText : '<{$nickname}> {$discordChannel} => {$ircChannel}: {$text}' } ;
674
+ this . bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
675
+ this . bot . connect ( ) ;
676
+
677
+ const guild = createGuildStub ( ) ;
678
+ const message = {
679
+ content : 'test message' ,
680
+ mentions : { users : [ ] } ,
681
+ channel : {
682
+ name : 'discord'
683
+ } ,
684
+ author : {
685
+ username : 'testauthor' ,
686
+ id : 'not bot id'
687
+ } ,
688
+ guild
689
+ } ;
690
+ const expected = '<testauthor> #discord => #irc: test message' ;
691
+
692
+ this . bot . sendToIRC ( message ) ;
693
+ ClientStub . prototype . say . should . have . been . calledWith ( '#irc' , expected ) ;
694
+ } ) ;
695
+
696
+ it ( 'should respect custom formatting for commands in IRC output' , function ( ) {
697
+ const format = { commandPrelude : '{$nickname} from {$discordChannel} sent command to {$ircChannel}:' } ;
698
+ this . bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
699
+ this . bot . connect ( ) ;
700
+
701
+ const text = '!testcmd' ;
702
+ const guild = createGuildStub ( ) ;
703
+ const message = {
704
+ content : text ,
705
+ mentions : { users : [ ] } ,
706
+ channel : {
707
+ name : 'discord'
708
+ } ,
709
+ author : {
710
+ username : 'testauthor' ,
711
+ id : 'not bot id'
712
+ } ,
713
+ guild
714
+ } ;
715
+ const expected = 'testauthor from #discord sent command to #irc:' ;
716
+
717
+ this . bot . sendToIRC ( message ) ;
718
+ ClientStub . prototype . say . getCall ( 0 ) . args . should . deep . equal ( [ '#irc' , expected ] ) ;
719
+ ClientStub . prototype . say . getCall ( 1 ) . args . should . deep . equal ( [ '#irc' , text ] ) ;
720
+ } ) ;
721
+
722
+ it ( 'should respect custom formatting for attachment URLs in IRC output' , function ( ) {
723
+ const format = { urlAttachment : '<{$nickname}> {$discordChannel} => {$ircChannel}, attachment: {$attachmentURL}' } ;
724
+ this . bot = new Bot ( { ...configMsgFormatDefault , format } ) ;
725
+ this . bot . connect ( ) ;
726
+
727
+ const attachmentUrl = 'https://image/url.jpg' ;
728
+ const guild = createGuildStub ( ) ;
729
+ const message = {
730
+ content : '' ,
731
+ mentions : { users : [ ] } ,
732
+ attachments : createAttachments ( attachmentUrl ) ,
733
+ channel : {
734
+ name : 'discord'
735
+ } ,
736
+ author : {
737
+ username : 'otherauthor' ,
738
+ id : 'not bot id'
739
+ } ,
740
+ guild
741
+ } ;
742
+
743
+ this . bot . sendToIRC ( message ) ;
744
+ const expected = `<otherauthor> #discord => #irc, attachment: ${ attachmentUrl } ` ;
745
+ ClientStub . prototype . say . should . have . been . calledWith ( '#irc' , expected ) ;
746
+ } ) ;
572
747
} ) ;
0 commit comments