@@ -11,6 +11,7 @@ interface
1111, IdIRC
1212, IRCLogBot.Config
1313, IRCLogBot.Database
14+ , IRCLogBot.Replay
1415;
1516
1617type
@@ -24,6 +25,8 @@ TIRCLogBot = class(TObject)
2425
2526 FDB: TDatabase;
2627
28+ FReplay: TReplayThread;
29+
2730 procedure OnConnected (Sender: TObject);
2831 procedure OnDisconnected (Sender: TObject);
2932 procedure OnNotice (ASender: TIdContext; const ANickname, AHost,
@@ -51,26 +54,25 @@ implementation
5154
5255uses
5356 IRCLogBot.Common
54- , IRCLogBot.Replay
5557;
5658
5759
5860{ TIRCLogBot }
5961
6062procedure TIRCLogBot.OnConnected (Sender: TObject);
6163begin
62- debug(' Connected to server' );
64+ debug(' Connected to server. ' );
6365end ;
6466
6567procedure TIRCLogBot.OnDisconnected (Sender: TObject);
6668begin
67- debug(' Disconnected from server' );
69+ debug(' Disconnected from server. ' );
6870end ;
6971
7072procedure TIRCLogBot.OnNotice (ASender: TIdContext; const ANickname, AHost,
7173 ATarget, ANotice: String);
7274begin
73- debug(' >> NOTICE: <%s:%s> (%s) "%s"' , [
75+ debug(' >> NOTICE: <%s:%s> (%s) "%s". ' , [
7476 ANickname,
7577 AHost,
7678 ATarget,
@@ -81,7 +83,7 @@ procedure TIRCLogBot.OnNotice(ASender: TIdContext; const ANickname, AHost,
8183procedure TIRCLogBot.OnServerQuit (ASender: TIdContext; const ANickname, AHost,
8284 AServer, AReason: String);
8385begin
84- debug(' >> QUIT: <%s:%s> %s "%s"' ,[
86+ debug(' >> QUIT: <%s:%s> %s "%s". ' ,[
8587 ANickname,
8688 AHost,
8789 AServer,
@@ -92,14 +94,14 @@ procedure TIRCLogBot.OnServerQuit(ASender: TIdContext; const ANickname, AHost,
9294procedure TIRCLogBot.OnJoin (ASender: TIdContext; const ANickname, AHost,
9395 AChannel: String);
9496begin
95- debug(' >> JOIN: <%s:%s> %s' , [
97+ debug(' >> JOIN: <%s:%s> %s. ' , [
9698 ANickname,
9799 AHost,
98100 AChannel
99101 ]);
100102 if (ANickname = FConfig.NickName) and (AChannel = FConfig.Channel) then
101103 begin
102- debug(' Successfully joined my channel' );
104+ debug(' Successfully joined my channel. ' );
103105 FJoinedChannel:= True;
104106 FIRC.Say(AChannel, ' I have arrived!!! TADAAAAA!!! Send me a private message with ".help" to see what I can do for you.' );
105107 end ;
@@ -111,15 +113,15 @@ procedure TIRCLogBot.OnPrivateMessage(ASender: TIdContext; const ANickname,
111113 strings: TStringArray;
112114 count: Integer;
113115begin
114- debug(' >> PRIVMSG: <%s:%s>(%s) "%s"' , [
116+ debug(' >> PRIVMSG: <%s:%s>(%s) "%s". ' , [
115117 ANickname,
116118 AHost,
117119 ATarget,
118120 AMessage
119121 ]);
120122 if ATarget = FConfig.Channel then
121123 begin
122- debug(' Inserting: %s, %s, %s, %s' , [
124+ debug(' Inserting: %s, %s, %s, %s. ' , [
123125 ANickname,
124126 AHost,
125127 ATarget,
@@ -175,46 +177,51 @@ procedure TIRCLogBot.Help(const ATarget: String);
175177begin
176178 debug(' Help command.' );
177179 FIRC.Say(ATarget, ' Commands:' );
178- FIRC.Say(ATarget, ' .help - This help information.' );
180+ FIRC.Say(ATarget, ' .help - This help information.' );
179181 FIRC.Say(ATarget, ' .replay [count] - Raplays last <count> lines. Default is last 10 lines.' );
180182end ;
181183
182184procedure TIRCLogBot.Replay (const ATarget: String; ACount: Integer);
183185var
184- replayThread: TReplayThread;
185186 lines: TStringList;
186187begin
187188 debug(' Replay command(%d).' , [ACount]);
188189 lines:= FDB.Get(ACount);
189- debug(' Lines: %d' , [lines.Count]);
190- replayThread:= TReplayThread.Create(FIRC, ATarget, lines);
190+ debug(' Lines: %d. ' , [lines.Count]);
191+ FReplay.Add( ATarget, lines);
191192 lines.Free;
192193end ;
193194
194195procedure TIRCLogBot.Run ;
195196begin
196- debug(' Connecting...' );
197197 try
198+ debug(' Connecting...' );
198199 FIRC.Connect;
199200 except
200201 on e:Exception do
201202 begin
202- debug(' Error connecting: %s ' , [e.Message]);
203+ debug(' Error connecting: "%s". ' , [e.Message]);
203204 end ;
204205 end ;
205- debug(' Joining channel: "%s"...' , [FConfig.Channel]);
206206 try
207+ debug(' Joining channel: "%s"...' , [FConfig.Channel]);
207208 FIRC.Join(FConfig.Channel);
208209 except
209210 on e:Exception do
210211 begin
211- debug(' Error joining: %s ' , [e.Message]);
212+ debug(' Error joining: "%s". ' , [e.Message]);
212213 end ;
213214 end ;
215+ debug(' Starting Replay Thread.' );
216+ FReplay:= TReplayThread.Create(FIRC);
214217end ;
215218
216219procedure TIRCLogBot.Shutdown ;
217220begin
221+ debug(' Terminating Replay Thread.' );
222+ FReplay.Terminate;
223+ debug(' Waiting for Replay Thread to terminate...' );
224+ FReplay.WaitFor;
218225 if FIRC.Connected then
219226 begin
220227 debug(' Disconnecting...' );
@@ -224,7 +231,7 @@ procedure TIRCLogBot.Shutdown;
224231 except
225232 on e:Exception do
226233 begin
227- debug(' Error: %s ' , [e.Message]);
234+ debug(' Error disconnecting: "%s". ' , [e.Message]);
228235 end ;
229236 end ;
230237 end ;
@@ -257,7 +264,7 @@ constructor TIRCLogBot.Create(const AConfig: TBotConfig);
257264 except
258265 on e:Exception do
259266 begin
260- debug(' Error creating db: ' , [e.Message]);
267+ debug(' Error creating db: "%s". ' , [e.Message]);
261268 end ;
262269 end ;
263270end ;
0 commit comments