|
@@ -9,18 +9,12 @@ import (
|
9
|
9
|
"strings"
|
10
|
10
|
)
|
11
|
11
|
|
12
|
|
-type editableCommand interface {
|
13
|
|
- Command
|
14
|
|
- SetCode(StringCode)
|
15
|
|
- SetClient(*Client)
|
16
|
|
-}
|
17
|
|
-
|
18
|
12
|
type checkPasswordCommand interface {
|
19
|
13
|
LoadPassword(*Server)
|
20
|
14
|
CheckPassword()
|
21
|
15
|
}
|
22
|
16
|
|
23
|
|
-type parseCommandFunc func([]string) (editableCommand, error)
|
|
17
|
+type parseCommandFunc func([]string) (Command, error)
|
24
|
18
|
|
25
|
19
|
var (
|
26
|
20
|
NotEnoughArgsError = errors.New("not enough arguments")
|
|
@@ -79,7 +73,7 @@ func (command *BaseCommand) SetCode(code StringCode) {
|
79
|
73
|
command.code = code
|
80
|
74
|
}
|
81
|
75
|
|
82
|
|
-func ParseCommand(line string) (cmd editableCommand, err error) {
|
|
76
|
+func ParseCommand(line string) (cmd Command, err error) {
|
83
|
77
|
code, args := ParseLine(line)
|
84
|
78
|
constructor := parseCommandFuncs[code]
|
85
|
79
|
if constructor == nil {
|
|
@@ -155,7 +149,7 @@ func (cmd *PingCommand) String() string {
|
155
|
149
|
return fmt.Sprintf("PING(server=%s, server2=%s)", cmd.server, cmd.server2)
|
156
|
150
|
}
|
157
|
151
|
|
158
|
|
-func NewPingCommand(args []string) (editableCommand, error) {
|
|
152
|
+func NewPingCommand(args []string) (Command, error) {
|
159
|
153
|
if len(args) < 1 {
|
160
|
154
|
return nil, NotEnoughArgsError
|
161
|
155
|
}
|
|
@@ -180,7 +174,7 @@ func (cmd *PongCommand) String() string {
|
180
|
174
|
return fmt.Sprintf("PONG(server1=%s, server2=%s)", cmd.server1, cmd.server2)
|
181
|
175
|
}
|
182
|
176
|
|
183
|
|
-func NewPongCommand(args []string) (editableCommand, error) {
|
|
177
|
+func NewPongCommand(args []string) (Command, error) {
|
184
|
178
|
if len(args) < 1 {
|
185
|
179
|
return nil, NotEnoughArgsError
|
186
|
180
|
}
|
|
@@ -217,7 +211,7 @@ func (cmd *PassCommand) CheckPassword() {
|
217
|
211
|
cmd.err = ComparePassword(cmd.hash, cmd.password)
|
218
|
212
|
}
|
219
|
213
|
|
220
|
|
-func NewPassCommand(args []string) (editableCommand, error) {
|
|
214
|
+func NewPassCommand(args []string) (Command, error) {
|
221
|
215
|
if len(args) < 1 {
|
222
|
216
|
return nil, NotEnoughArgsError
|
223
|
217
|
}
|
|
@@ -237,7 +231,7 @@ func (m *NickCommand) String() string {
|
237
|
231
|
return fmt.Sprintf("NICK(nickname=%s)", m.nickname)
|
238
|
232
|
}
|
239
|
233
|
|
240
|
|
-func NewNickCommand(args []string) (editableCommand, error) {
|
|
234
|
+func NewNickCommand(args []string) (Command, error) {
|
241
|
235
|
if len(args) != 1 {
|
242
|
236
|
return nil, NotEnoughArgsError
|
243
|
237
|
}
|
|
@@ -287,7 +281,7 @@ func (cmd *RFC2812UserCommand) Flags() []UserMode {
|
287
|
281
|
return flags
|
288
|
282
|
}
|
289
|
283
|
|
290
|
|
-func NewUserCommand(args []string) (editableCommand, error) {
|
|
284
|
+func NewUserCommand(args []string) (Command, error) {
|
291
|
285
|
if len(args) != 4 {
|
292
|
286
|
return nil, NotEnoughArgsError
|
293
|
287
|
}
|
|
@@ -322,7 +316,7 @@ func (cmd *QuitCommand) String() string {
|
322
|
316
|
return fmt.Sprintf("QUIT(message=%s)", cmd.message)
|
323
|
317
|
}
|
324
|
318
|
|
325
|
|
-func NewQuitCommand(args []string) (editableCommand, error) {
|
|
319
|
+func NewQuitCommand(args []string) (Command, error) {
|
326
|
320
|
msg := &QuitCommand{}
|
327
|
321
|
if len(args) > 0 {
|
328
|
322
|
msg.message = args[0]
|
|
@@ -342,7 +336,7 @@ func (cmd *JoinCommand) String() string {
|
342
|
336
|
return fmt.Sprintf("JOIN(channels=%s, zero=%t)", cmd.channels, cmd.zero)
|
343
|
337
|
}
|
344
|
338
|
|
345
|
|
-func NewJoinCommand(args []string) (editableCommand, error) {
|
|
339
|
+func NewJoinCommand(args []string) (Command, error) {
|
346
|
340
|
msg := &JoinCommand{
|
347
|
341
|
channels: make(map[string]string),
|
348
|
342
|
}
|
|
@@ -389,7 +383,7 @@ func (cmd *PartCommand) String() string {
|
389
|
383
|
return fmt.Sprintf("PART(channels=%s, message=%s)", cmd.channels, cmd.message)
|
390
|
384
|
}
|
391
|
385
|
|
392
|
|
-func NewPartCommand(args []string) (editableCommand, error) {
|
|
386
|
+func NewPartCommand(args []string) (Command, error) {
|
393
|
387
|
if len(args) < 1 {
|
394
|
388
|
return nil, NotEnoughArgsError
|
395
|
389
|
}
|
|
@@ -414,7 +408,7 @@ func (cmd *PrivMsgCommand) String() string {
|
414
|
408
|
return fmt.Sprintf("PRIVMSG(target=%s, message=%s)", cmd.target, cmd.message)
|
415
|
409
|
}
|
416
|
410
|
|
417
|
|
-func NewPrivMsgCommand(args []string) (editableCommand, error) {
|
|
411
|
+func NewPrivMsgCommand(args []string) (Command, error) {
|
418
|
412
|
if len(args) < 2 {
|
419
|
413
|
return nil, NotEnoughArgsError
|
420
|
414
|
}
|
|
@@ -437,7 +431,7 @@ func (cmd *TopicCommand) String() string {
|
437
|
431
|
return fmt.Sprintf("TOPIC(channel=%s, topic=%s)", cmd.channel, cmd.topic)
|
438
|
432
|
}
|
439
|
433
|
|
440
|
|
-func NewTopicCommand(args []string) (editableCommand, error) {
|
|
434
|
+func NewTopicCommand(args []string) (Command, error) {
|
441
|
435
|
if len(args) < 1 {
|
442
|
436
|
return nil, NotEnoughArgsError
|
443
|
437
|
}
|
|
@@ -487,7 +481,7 @@ type ModeCommand struct {
|
487
|
481
|
}
|
488
|
482
|
|
489
|
483
|
// MODE <nickname> *( ( "+" / "-" ) *( "i" / "w" / "o" / "O" / "r" ) )
|
490
|
|
-func NewUserModeCommand(args []string) (editableCommand, error) {
|
|
484
|
+func NewUserModeCommand(args []string) (Command, error) {
|
491
|
485
|
cmd := &ModeCommand{
|
492
|
486
|
nickname: args[0],
|
493
|
487
|
changes: make(ModeChanges, 0),
|
|
@@ -564,7 +558,7 @@ type ChannelModeCommand struct {
|
564
|
558
|
}
|
565
|
559
|
|
566
|
560
|
// MODE <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
|
567
|
|
-func NewChannelModeCommand(args []string) (editableCommand, error) {
|
|
561
|
+func NewChannelModeCommand(args []string) (Command, error) {
|
568
|
562
|
cmd := &ChannelModeCommand{
|
569
|
563
|
channel: args[0],
|
570
|
564
|
changes: make(ChannelModeChanges, 0),
|
|
@@ -611,7 +605,7 @@ func (msg *ChannelModeCommand) String() string {
|
611
|
605
|
return fmt.Sprintf("MODE(channel=%s, changes=%s)", msg.channel, msg.changes)
|
612
|
606
|
}
|
613
|
607
|
|
614
|
|
-func NewModeCommand(args []string) (editableCommand, error) {
|
|
608
|
+func NewModeCommand(args []string) (Command, error) {
|
615
|
609
|
if len(args) == 0 {
|
616
|
610
|
return nil, NotEnoughArgsError
|
617
|
611
|
}
|
|
@@ -630,7 +624,7 @@ type WhoisCommand struct {
|
630
|
624
|
}
|
631
|
625
|
|
632
|
626
|
// WHOIS [ <target> ] <mask> *( "," <mask> )
|
633
|
|
-func NewWhoisCommand(args []string) (editableCommand, error) {
|
|
627
|
+func NewWhoisCommand(args []string) (Command, error) {
|
634
|
628
|
if len(args) < 1 {
|
635
|
629
|
return nil, NotEnoughArgsError
|
636
|
630
|
}
|
|
@@ -662,7 +656,7 @@ type WhoCommand struct {
|
662
|
656
|
}
|
663
|
657
|
|
664
|
658
|
// WHO [ <mask> [ "o" ] ]
|
665
|
|
-func NewWhoCommand(args []string) (editableCommand, error) {
|
|
659
|
+func NewWhoCommand(args []string) (Command, error) {
|
666
|
660
|
cmd := &WhoCommand{}
|
667
|
661
|
|
668
|
662
|
if len(args) > 0 {
|
|
@@ -694,7 +688,7 @@ func (msg *OperCommand) LoadPassword(server *Server) {
|
694
|
688
|
}
|
695
|
689
|
|
696
|
690
|
// OPER <name> <password>
|
697
|
|
-func NewOperCommand(args []string) (editableCommand, error) {
|
|
691
|
+func NewOperCommand(args []string) (Command, error) {
|
698
|
692
|
if len(args) < 2 {
|
699
|
693
|
return nil, NotEnoughArgsError
|
700
|
694
|
}
|
|
@@ -717,7 +711,7 @@ func (msg *CapCommand) String() string {
|
717
|
711
|
msg.subCommand, msg.capabilities)
|
718
|
712
|
}
|
719
|
713
|
|
720
|
|
-func NewCapCommand(args []string) (editableCommand, error) {
|
|
714
|
+func NewCapCommand(args []string) (Command, error) {
|
721
|
715
|
if len(args) < 1 {
|
722
|
716
|
return nil, NotEnoughArgsError
|
723
|
717
|
}
|
|
@@ -751,7 +745,7 @@ func (msg *ProxyCommand) String() string {
|
751
|
745
|
return fmt.Sprintf("PROXY(sourceIP=%s, sourcePort=%s)", msg.sourceIP, msg.sourcePort)
|
752
|
746
|
}
|
753
|
747
|
|
754
|
|
-func NewProxyCommand(args []string) (editableCommand, error) {
|
|
748
|
+func NewProxyCommand(args []string) (Command, error) {
|
755
|
749
|
if len(args) < 5 {
|
756
|
750
|
return nil, NotEnoughArgsError
|
757
|
751
|
}
|
|
@@ -775,7 +769,7 @@ func (msg *AwayCommand) String() string {
|
775
|
769
|
return fmt.Sprintf("AWAY(%s)", msg.text)
|
776
|
770
|
}
|
777
|
771
|
|
778
|
|
-func NewAwayCommand(args []string) (editableCommand, error) {
|
|
772
|
+func NewAwayCommand(args []string) (Command, error) {
|
779
|
773
|
cmd := &AwayCommand{}
|
780
|
774
|
|
781
|
775
|
if len(args) > 0 {
|
|
@@ -795,7 +789,7 @@ func (msg *IsOnCommand) String() string {
|
795
|
789
|
return fmt.Sprintf("ISON(nicks=%s)", msg.nicks)
|
796
|
790
|
}
|
797
|
791
|
|
798
|
|
-func NewIsOnCommand(args []string) (editableCommand, error) {
|
|
792
|
+func NewIsOnCommand(args []string) (Command, error) {
|
799
|
793
|
if len(args) == 0 {
|
800
|
794
|
return nil, NotEnoughArgsError
|
801
|
795
|
}
|
|
@@ -810,7 +804,7 @@ type MOTDCommand struct {
|
810
|
804
|
target string
|
811
|
805
|
}
|
812
|
806
|
|
813
|
|
-func NewMOTDCommand(args []string) (editableCommand, error) {
|
|
807
|
+func NewMOTDCommand(args []string) (Command, error) {
|
814
|
808
|
cmd := &MOTDCommand{}
|
815
|
809
|
if len(args) > 0 {
|
816
|
810
|
cmd.target = args[0]
|
|
@@ -828,7 +822,7 @@ func (cmd *NoticeCommand) String() string {
|
828
|
822
|
return fmt.Sprintf("NOTICE(target=%s, message=%s)", cmd.target, cmd.message)
|
829
|
823
|
}
|
830
|
824
|
|
831
|
|
-func NewNoticeCommand(args []string) (editableCommand, error) {
|
|
825
|
+func NewNoticeCommand(args []string) (Command, error) {
|
832
|
826
|
if len(args) < 2 {
|
833
|
827
|
return nil, NotEnoughArgsError
|
834
|
828
|
}
|
|
@@ -851,7 +845,7 @@ func (msg *KickCommand) Comment() string {
|
851
|
845
|
return msg.comment
|
852
|
846
|
}
|
853
|
847
|
|
854
|
|
-func NewKickCommand(args []string) (editableCommand, error) {
|
|
848
|
+func NewKickCommand(args []string) (Command, error) {
|
855
|
849
|
if len(args) < 2 {
|
856
|
850
|
return nil, NotEnoughArgsError
|
857
|
851
|
}
|
|
@@ -882,7 +876,7 @@ type ListCommand struct {
|
882
|
876
|
target string
|
883
|
877
|
}
|
884
|
878
|
|
885
|
|
-func NewListCommand(args []string) (editableCommand, error) {
|
|
879
|
+func NewListCommand(args []string) (Command, error) {
|
886
|
880
|
cmd := &ListCommand{}
|
887
|
881
|
if len(args) > 0 {
|
888
|
882
|
cmd.channels = strings.Split(args[0], ",")
|
|
@@ -899,7 +893,7 @@ type NamesCommand struct {
|
899
|
893
|
target string
|
900
|
894
|
}
|
901
|
895
|
|
902
|
|
-func NewNamesCommand(args []string) (editableCommand, error) {
|
|
896
|
+func NewNamesCommand(args []string) (Command, error) {
|
903
|
897
|
cmd := &NamesCommand{}
|
904
|
898
|
if len(args) > 0 {
|
905
|
899
|
cmd.channels = strings.Split(args[0], ",")
|
|
@@ -915,7 +909,7 @@ type DebugCommand struct {
|
915
|
909
|
subCommand string
|
916
|
910
|
}
|
917
|
911
|
|
918
|
|
-func NewDebugCommand(args []string) (editableCommand, error) {
|
|
912
|
+func NewDebugCommand(args []string) (Command, error) {
|
919
|
913
|
if len(args) == 0 {
|
920
|
914
|
return nil, NotEnoughArgsError
|
921
|
915
|
}
|
|
@@ -930,7 +924,7 @@ type VersionCommand struct {
|
930
|
924
|
target string
|
931
|
925
|
}
|
932
|
926
|
|
933
|
|
-func NewVersionCommand(args []string) (editableCommand, error) {
|
|
927
|
+func NewVersionCommand(args []string) (Command, error) {
|
934
|
928
|
cmd := &VersionCommand{}
|
935
|
929
|
if len(args) > 0 {
|
936
|
930
|
cmd.target = args[0]
|
|
@@ -944,7 +938,7 @@ type InviteCommand struct {
|
944
|
938
|
channel string
|
945
|
939
|
}
|
946
|
940
|
|
947
|
|
-func NewInviteCommand(args []string) (editableCommand, error) {
|
|
941
|
+func NewInviteCommand(args []string) (Command, error) {
|
948
|
942
|
if len(args) < 2 {
|
949
|
943
|
return nil, NotEnoughArgsError
|
950
|
944
|
}
|
|
@@ -960,7 +954,7 @@ type TimeCommand struct {
|
960
|
954
|
target string
|
961
|
955
|
}
|
962
|
956
|
|
963
|
|
-func NewTimeCommand(args []string) (editableCommand, error) {
|
|
957
|
+func NewTimeCommand(args []string) (Command, error) {
|
964
|
958
|
cmd := &TimeCommand{}
|
965
|
959
|
if len(args) > 0 {
|
966
|
960
|
cmd.target = args[0]
|
|
@@ -974,7 +968,7 @@ type KillCommand struct {
|
974
|
968
|
comment string
|
975
|
969
|
}
|
976
|
970
|
|
977
|
|
-func NewKillCommand(args []string) (editableCommand, error) {
|
|
971
|
+func NewKillCommand(args []string) (Command, error) {
|
978
|
972
|
if len(args) < 2 {
|
979
|
973
|
return nil, NotEnoughArgsError
|
980
|
974
|
}
|
|
@@ -991,7 +985,7 @@ type WhoWasCommand struct {
|
991
|
985
|
target string
|
992
|
986
|
}
|
993
|
987
|
|
994
|
|
-func NewWhoWasCommand(args []string) (editableCommand, error) {
|
|
988
|
+func NewWhoWasCommand(args []string) (Command, error) {
|
995
|
989
|
if len(args) < 1 {
|
996
|
990
|
return nil, NotEnoughArgsError
|
997
|
991
|
}
|