@@ -33,6 +33,9 @@ TIRCLogBot = class(TObject)
3333 AChannel: String);
3434 procedure OnPrivateMessage (ASender: TIdContext; const ANickname, AHost,
3535 ATarget, AMessage: String);
36+
37+ procedure Help (const ATarget: String);
38+ procedure Replay (const ATarget: String; Count: Integer);
3639 protected
3740 public
3841 constructor Create(AHost: String; APort: Word;
@@ -46,85 +49,145 @@ TIRCLogBot = class(TObject)
4649
4750implementation
4851
52+ uses
53+ IRCLogBot.Common
54+ ;
55+
4956{ TIRCLogBot }
5057
5158procedure TIRCLogBot.OnConnected (Sender: TObject);
5259begin
53- WriteLn (' Connected to server' );
60+ debug (' Connected to server' );
5461end ;
5562
5663procedure TIRCLogBot.OnDisconnected (Sender: TObject);
5764begin
58- WriteLn (' Disconnected from server' );
65+ debug (' Disconnected from server' );
5966end ;
6067
6168procedure TIRCLogBot.OnNotice (ASender: TIdContext; const ANickname, AHost,
6269 ATarget, ANotice: String);
6370begin
64- WriteLn(Format (' >> NOTICE: <%s> "%s"' , [
71+ debug (' >> NOTICE: <%s> "%s"' , [
6572 ANickname,
6673 ANotice
67- ])) ;
74+ ]);
6875end ;
6976
7077procedure TIRCLogBot.OnJoin (ASender: TIdContext; const ANickname, AHost,
7178 AChannel: String);
7279begin
73- WriteLn(Format (' >> JOIN: <%s@%s> %s' , [
80+ debug (' >> JOIN: <%s@%s> %s' , [
7481 ANickname,
7582 AHost,
7683 AChannel
77- ])) ;
84+ ]);
7885 if (ANickname = FNickName) and (AChannel = FChannel) then
7986 begin
80- WriteLn (' Successfully joined my channel' );
87+ debug (' Successfully joined my channel' );
8188 FJoinedChannel:= True;
89+ FIRC.Say(AChannel, ' I have arrived!!! TADAAAAA!!! Send me a private message with ".help" to see what I can do for you.' );
8290 end ;
8391end ;
8492
8593procedure TIRCLogBot.OnPrivateMessage (ASender: TIdContext; const ANickname,
8694 AHost, ATarget, AMessage: String);
95+ var
96+ strings: TStringArray;
97+ count: Integer;
8798begin
88- WriteLn(Format (' >> PRIVMSG: <%s@%s>(%s) "%s"' , [
99+ debug (' >> PRIVMSG: <%s@%s>(%s) "%s"' , [
89100 ANickname,
90101 AHost,
91102 ATarget,
92103 AMessage
93- ])) ;
104+ ]);
94105 if ATarget = FNickName then
95106 begin
96107 if Pos(' .' , AMessage) = 1 then
97108 begin
98109 // Parse commands
99110 if Pos(' .help' , Trim(AMessage)) = 1 then
100111 begin
101- WriteLn(' Help command.' );
102- FIRC.Say(ANickname, ' Commands:' );
103- FIRC.Say(ANickname, ' .help - This help information' );
112+ Help(ANickname);
113+ exit;
114+ end ;
115+ if Pos(' .replay' , Trim(AMessage)) = 1 then
116+ begin
117+ strings:= AMessage.Split([' ' ]);
118+ try
119+ if Length(strings) > 1 then
120+ begin
121+ count:= StrToInt(strings[1 ]);
122+ end
123+ else
124+ begin
125+ count:= 0 ;
126+ end ;
127+ Replay(ANickname, count);
128+ except
129+ FIRC.Say(ANickname, ' That <count> is not a number.' );
130+ end ;
131+ exit;
104132 end ;
105133 end
106134 else
107135 begin
108- WriteLn (' No command.' );
136+ debug (' No command.' );
109137 FIRC.Say(ANickname, ' Not a command. Please use ".help" to see a list of commands.' );
110138 end ;
111139 end ;
112140end ;
113141
142+ procedure TIRCLogBot.Help (const ATarget: String);
143+ begin
144+ debug(' Help command.' );
145+ FIRC.Say(ATarget, ' Commands:' );
146+ FIRC.Say(ATarget, ' .help - This help information.' );
147+ FIRC.Say(ATarget, ' .replay [count] - Raplays last <count> lines. Default is last 10 lines.' );
148+ end ;
149+
150+ procedure TIRCLogBot.Replay (const ATarget: String; Count: Integer);
151+ begin
152+ debug(' Replay command.' );
153+ FIRC.Say(ATarget, Format(' Not fully implemented yet: %d' ,[Count]));
154+ end ;
155+
114156procedure TIRCLogBot.Run ;
115157begin
116- WriteLn(' Connecting...' );
117- FIRC.Connect;
118- WriteLn(' Joining channel: "' , FChannel, ' "...' );
119- FIRC.Join(FChannel);
158+ debug(' Connecting...' );
159+ try
160+ FIRC.Connect;
161+ except
162+ on e:Exception do
163+ begin
164+ debug(' Error connecting: %s' , [e.Message]);
165+ end ;
166+ end ;
167+ debug(' Joining channel: "%s"...' , [FChannel]);
168+ try
169+ FIRC.Join(FChannel);
170+ except
171+ on e:Exception do
172+ begin
173+ debug(' Error joining: %s' , [e.Message]);
174+ end ;
175+ end ;
120176end ;
121177
122178procedure TIRCLogBot.Shutdown ;
123179begin
124180 if FIRC.Connected then
125181 begin
126- WriteLn(' Disconnecting...' );
127- FIRC.Disconnect(' Need to go and have a wee nap.' );
182+ debug(' Disconnecting...' );
183+ try
184+ FIRC.Disconnect(' Need to go and have a wee nap.' );
185+ except
186+ on e:Exception do
187+ begin
188+ debug(' Error: %s' , [e.Message]);
189+ end ;
190+ end ;
128191 end ;
129192end ;
130193
0 commit comments