unit UnitIRCBot;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdCmdTCPClient, IdIRC, IdContext,
Vcl.StdCtrls,
IdCustomTransparentProxy, IdConnectThroughHttpProxy;
type
TForm1 =
class(TForm)
IdIRC1: TIdIRC;
Bt_Connect: TButton;
Bt_JoinChannel: TButton;
Memo1: TMemo;
Edit1: TEdit;
Bt_Send: TButton;
IdConnectThroughHttpProxy1: TIdConnectThroughHttpProxy;
procedure FormCreate(Sender: TObject);
procedure Bt_ConnectClick(Sender: TObject);
procedure Bt_JoinChannelClick(Sender: TObject);
procedure Bt_SendClick(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure IdIRC1PrivateMessage(ASender: TIdContext;
const ANickname, AHost,
ATarget, AMessage:
string);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Bt_ConnectClick(Sender: TObject);
begin
try //versuche
IdIRC1.Connect();
//zu verbinden
except //wenn Fehler
on E:
Exception do
showMessage('
Fehler: ' + E.
Message);
//Meldung zeigen
end;
end;
procedure TForm1.Bt_JoinChannelClick(Sender: TObject);
begin
IdIRC1.Join('
#botty-channel');
end;
procedure TForm1.Bt_SendClick(Sender: TObject);
begin
IdIRC1.Say('
#botty-channel',Edit1.Text);
//Nachricht zum Channel schicken
Memo1.Lines.Add(IdIRC1.Nickname+'
: '+Edit1.Text);
//Zum Memo hinzufügen, denn durch eigene Nachrichten wird das OnMessage-Ereignis nicht ausgelöst
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
IdIRC1.Disconnect();
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IdConnectThroughHttpProxy1.Enabled := True;
IdConnectThroughHttpProxy1.Host := '
Hongkong';
IdConnectThroughHttpProxy1.Port := 80;
IdIRC1.Nickname:='
botty';
// Legt den Nick fest
IdIRC1.Host:='
chat.freenode.net';
// Gibt den Server an
IdIRC1.Port:=6667;
//Irc Port
end;
procedure TForm1.IdIRC1PrivateMessage(ASender: TIdContext;
const ANickname,
AHost, ATarget, AMessage:
string);
begin
Memo1.lines.add(ANickname+'
: '+AMessage);
end;
end.