-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: New unit for thread and datetime formatting
- Loading branch information
Showing
5 changed files
with
131 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
unit IRCLogBot.Replay; | ||
|
||
{$mode ObjFPC}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
, SysUtils | ||
, SyncObjs | ||
, IdIRC | ||
|
||
; | ||
|
||
type | ||
{ TReplayThread } | ||
TReplayThread = class(TThread) | ||
private | ||
FCriticalSection: TCriticalSection; | ||
FIRC: TIdIRC; | ||
FTarget: String; | ||
FLines: TStringList; | ||
protected | ||
procedure Execute; override; | ||
public | ||
constructor Create(AIRC: TIdIRC; const ATarget: String; | ||
const ALines: TStringList); | ||
destructor Destroy; override; | ||
published | ||
end; | ||
|
||
implementation | ||
|
||
uses | ||
IRCLogBot.Common | ||
; | ||
|
||
{ TReplayThread } | ||
|
||
procedure TReplayThread.Execute; | ||
var | ||
line: String; | ||
index: Integer = 0; | ||
begin | ||
if not FIRC.Connected then | ||
begin | ||
debug('Exiting replay thread due not being connected.'); | ||
exit; | ||
end; | ||
try | ||
FIRC.Say(FTarget, '!! --> To avoid triggering flooding, for each 5 lines, I will pause for 5 seconds <-- !!'); | ||
FIRC.Say(FTarget, Format('*** Here are the last %d lines ***', [FLines.Count])); | ||
for line in FLines do | ||
begin | ||
if (Terminated) or (not FIRC.Connected) then | ||
begin | ||
debug('Exiting replay thread due to termination or not being connected.'); | ||
exit; | ||
end; | ||
debug('Sending #%d: "%s"', [index, line]); | ||
Inc(index); | ||
FIRC.Say(FTarget, line); | ||
if (index mod 5) = 0 then | ||
begin | ||
debug('Pausing'); | ||
Sleep(5000); | ||
end; | ||
end; | ||
FIRC.Say(FTarget, Format('*** End of the last %d lines ***', [FLines.Count])); | ||
finally | ||
FLines.Free; | ||
end; | ||
end; | ||
|
||
constructor TReplayThread.Create(AIRC: TIdIRC; const ATarget: String; | ||
const ALines: TStringList); | ||
begin | ||
inherited Create(True); | ||
FCriticalSection:= TCriticalSection.Create; | ||
FIRC:= AIRC; | ||
FTarget:= ATarget; | ||
FLines:= TStringList.Create; | ||
FLines.Text := ALines.Text; | ||
FreeOnTerminate:= True; | ||
Start; | ||
end; | ||
|
||
destructor TReplayThread.Destroy; | ||
begin | ||
FCriticalSection.Free; | ||
inherited Destroy; | ||
end; | ||
|
||
end. | ||
|