- Ја почнал/а темата
- #1
Aleks
Gaining Experience
- 18 мај 2007
- 5,748
- 288
Пред некој ден се зезав со конектирање на ИРЦ преку телнет (ќе објаснам за тоа на блог) и реков да напраам ИРЦ бот и + нечто да научам. Еве го кодот во паскал.
Код:
program PBOT;
{
PBot, is a IRC bot that understand RAW irc commands
written in PASCAL. The inspiration came to me when I
was fooling and connecting to IRC via TELNET, so in
some way this is like telnet connecting to IRC only
smart IRC connecting. The command for controling is:
!cmd RAW IRC CMD
Example:
!cmd privmsg #channel : Hello Cruel World.
Written by Aleks Lazarov @ Irc.MicroLinux.Org & It.Com.Mk
I`m working on updating the bot everytime I get the
chance to do so ... so w8 a bit for a new version...
THE END of the BS =)
}
{$mode objfpc}{$H+}
uses
sockets, ERRORS, inetaux; // use sockets_patched on Windows
var
sin, // STANDARD IN
sout: text; // STANDARD OUT
socketABC:longint;
addr: TInetSockAddr;
line,SrvIP,Vrati,channel,owner: string;
CODE: Integer;
procedure Main(input :string); //ne e zavrshena !!!
var
dolzina, X, A, B, S, K: Integer;
inp,outs,cmd:String;
tmpchar:char;
tmpstr:ARRAY[1..2000] of string;
begin
for K:=1 to 2000 do
tmpstr[K]:='';
B:=0; S:=1;
cmd:='';
inp:=input;
dolzina := length(inp);
//tmpchar:=inp[1];
repeat
repeat
inc(B);
tmpchar:=inp[B];
if tmpchar=' ' then
break
else
tmpstr[S]:=tmpstr[S]+tmpchar;
until((B>=dolzina) OR (tmpchar=' '));
inc(S);
until(B>=dolzina);
// staying alive on the IRC server
if tmpstr[1]='PING' then
begin
outs:='PONG '+tmpstr[2];
//WriteLn(outs);
CODE:=1;
end;
// preforming commands
if tmpstr[1]=owner then
begin
if tmpstr[2]='PRIVMSG' then
begin
if tmpstr[4]=':!cmd' then
begin
FOR X:=5 to S DO
cmd:=cmd+' '+tmpstr[X];
CODE:=1;
outs:=cmd;
end;
end;
end;
Vrati:=outs;
end;
begin
// CONFIGURIRATION //
SrvIP:='204.11.244.21'; // freenode
//SrvIP:='85.196.81.25'; // infected
channel:='#irctest';
//owner:=':[email protected]';
owner:=':[email protected]/aleks';
// CODE //
Addr.family:=AF_INET;
addr.port := htons(6667);
addr.addr := StrToAddr(SrvIP);
socketABC:= socket(AF_INET, SOCK_STREAM, 0);
if not Connect (socketABC,ADDR,SIN,SOUT) then
begin
Writeln ('Couldn''t connect to server!!!!');
Writeln ('Socket error : ', strerror(SocketError));
halt(1);
end else
Writeln ('Connected to server !!!');
rewrite (sout);
reset(sin);
writeln(sout, 'NICK TelnetGeek');
writeln(sout, 'USER Weee 8 ASD : KILL ME');
writeln(sout, 'JOIN ',channel);
flush(sout);
while not eof(sin) do
begin
readln (Sin,line);
Main(line);
if CODE=1 then
begin
WriteLn(Sout, Vrati);
//WriteLn(Sout,'privmsg #irctest : ',Vrati);
WriteLn(line);
WriteLn(Vrati);
CODE:=0;
end
else
writeln(line);
end;
close(sin);
close(sout);
writeln ('hit enter to exit');
readln;
end.