forked from Villavu/Simba
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathirc.simba
More file actions
54 lines (42 loc) · 1.11 KB
/
irc.simba
File metadata and controls
54 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Very simple irc "bot" to test TInternetSocket
// Joins rizon server, and replys the date and time when !date is said
const
NICK_TO_USE := 'SimbaIRCBot' + ToString(Random(999));
CHANNEL_TO_JOIN := '#SimbaIRCBot';
procedure tx(Sock: TInternetSocket; Str: String);
begin
Sock.WriteString(Str + #13#10);
end;
function rx(Sock: TInternetSocket): Boolean;
var
Line: String;
begin
for Line in Sock.ReadString().Split(#13#10) do
begin
WriteLn(Line);
if (Line.StartsWith('PING')) then
begin
tx(Sock, Line.Replace('PING', 'PONG'));
Result := True;
end;
if ('End of /MOTD command' in Line) then
tx(Sock, 'JOIN ' + CHANNEL_TO_JOIN);
if ('!date' in Line) then
tx(Sock, 'PRIVMSG ' + CHANNEL_TO_JOIN + ' :' + TDateTime.CreateFromSystem().ToString('c'));
end;
end;
var
Sock: TInternetSocket;
begin
Sock := TInternetSocket.Create('irc.rizon.net', 6667, False);
Sock.Connect();
tx(Sock, 'NICK ' + NICK_TO_USE);
tx(Sock, 'USER ' + NICK_TO_USE + ' * * *');
while True do
begin
if Sock.HasData() then
rx(Sock);
Sleep(500);
end;
Sock.Free();
end.