Delphi-PRAXiS
Seite 2 von 4     12 34      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Tutorials und Kurse (https://www.delphipraxis.net/36-tutorials-und-kurse/)
-   -   Delphi Irc mit Indy (https://www.delphipraxis.net/113729-irc-mit-indy.html)

FAlter 16. Mai 2008 13:27

Re: Irc mit Indy
 
Hi,

Nickname?

Mein Test-Code:

Delphi-Quellcode:
//IRC = TIdIRC
      IRC.OnPrivateMessage := HandleMsg;
      IRC.OnNotice := HandleMsg;
      IRC.OnWallops := HandleMsg2;
      //IRC.OnRaw := HandleRaw;
      IRC.Nickname := NickEdit.Text;
      IRC.RealName := 'FAlter Bot';
      IRC.Username := 'FAlterBot';
      IRC.Host    := ServerEdit.Text;
      IRC.Port    := StrToIntDef(PortEdit.Text, IRC.Port);
      IRC.Connect;
Muss natürlich noch verbessert werden... Ist ja erstmal nur zum Test.

Mfg
FAlter

[edit]

Aus der IdIRC.Pas: (Indy 10)
Delphi-Quellcode:
procedure TIdIRC.CommandPRIVMSG(ASender: TIdCommand);
var
  LTmp: String;
begin
  if ASender.Params[0][1] = #1 then
  begin
    ParseCTCPQuery(ASender.Params[1], ASender.Params[0]);
  end
  else if Assigned(FOnPrivMessage) then
  begin
    LTmp := copy(ASender.Params[1], 2, length(ASender.Params[1]) - 2); ///!!!!!!!!!!!!!!!
    OnPrivateMessage(ASender.Context, FSenderNick, FSenderHost, ASender.Params[0], LTmp);
  end;
end;
In der markierten Zeile liegt ein Fehler. Das -2 ist falsch und kann sogar komplett weggelassen werden, ansonsten kommt da -1 hin. Das erklärt das Fehlen des letzten Buchstabens.

Die anderen Worte liegen vermutlich in Params[3]..Params[Count-1], schätz ich mal.

[/edit]

[edit]
Mit dieser Änderung gehts erstmal. Ist natürlich nicht gerade optimal, wenns erst auseinandergepflückt und hier wieder zusammengesetzt wird, erstmal reichts jedoch. Der Bot muss "liest" trotzdem schneller als ein Mensch.

Delphi-Quellcode:
procedure TIdIRC.CommandPRIVMSG(ASender: TIdCommand);
var
  LTmp: String;
  I: Integer;
begin
  if ASender.Params[0][1] = #1 then
  begin
    ParseCTCPQuery(ASender.Params[1], ASender.Params[0]);
  end
  else if Assigned(FOnPrivMessage) then
  begin
    LTmp := copy(ASender.Params[1], 2, length(ASender.Params[1]));
    for I := 2 to ASender.Params.Count - 1 do
      LTmp := LTmp + ' ' + ASender.Params[I];
    OnPrivateMessage(ASender.Context, FSenderNick, FSenderHost, ASender.Params[0], LTmp);
  end;
end;

procedure TIdIRC.CommandNOTICE(ASender: TIdCommand);
var
  LTmp: String;
  I: Integer;
begin
  if ASender.Params[0][1] = #1 then
  begin
    ParseCTCPReply(ASender.Params[1], ASender.Params[0]);
  end
  else if Assigned(FOnNotice) then
  begin
    LTmp := copy(ASender.Params[1], 2, length(ASender.Params[1]));
    for I := 2 to ASender.Params.Count - 1 do
      LTmp := LTmp + ' ' + ASender.Params[I];
    OnNotice(ASender.Context, FSenderNick, FSenderHost, ASender.Params[0], LTmp);
  end;
end;
[/edit]

Valle 20. Dez 2008 13:54

Re: Irc mit Indy
 
Ich habe das Tutorial mal aus gegebenem Anlass ins Englische übersetzt, damit unser User dangerduck auch was davon versteht. Ich hoffe, MSSSSM hat nichts dagegen. :-)

---

Hello and welcome!

This post is about the Indy IRC component.

You can download it here.

Let's begin:

First, put the Indy IRC component on your form.

Form.Create should now look like the following:
Delphi-Quellcode:
IdIRC1.Nick:='MyNick';  // Defines the nickname

IdIRC1.Host:='irc.server.org';  // Defines the Server

IdIRC1.Port:=6667; //Irc Port
With this you define the settings for the connection.

Now we have to connect:

Put a button on your form and create the onClick-event:
The buttons caption should be 'Connect'

Put in this code:
Delphi-Quellcode:
try // try ...
IdIRC1.Connect(); // ... to connect
except // ... when an error happens ...
showMessage('Fehler beim Verbinden!'); // ... show a message
end;
You should make a buton with the folling code in the onClick-event
Delphi-Quellcode:
IdIRC1.Join('#lima-city');
Now you can already connect and join a channel.
But to display messages later, you should put a the TMemo component on the form.

The you have to add two events: OnReceive and OnMessage.

OnReceive (It only works with this additional event):
Delphi-Quellcode:
Memo1.lines.add(ACommand); // add to memo
OnMessage:
Delphi-Quellcode:
Memo1.lines.add(AUser.Nick+': '+Content); // Add message

Now you can already receive a message, but it lacks writing yet.

Put a TEdit and a TButton component on your form.

The button gets the caption "Send".

The OnClick-event is:

Delphi-Quellcode:
IdIRC1.Say('#CHANNEL',Edit1.Text); // Send message to the channel
Memo1.Lines.Add(IdIRC1.Nick+': '+Edit1.Text); // Ad to memo, because the OnMessage event won't be called when sending own messages
Now you can send and receive messages with that.

Put the following into the forms OnClose event:

Delphi-Quellcode:
IdIRC1.Disconnect(); // to stop


Additional code:
Create a TListBox.
Create the OnNames event and write:
Delphi-Quellcode:
var
 i: integer;
//begin
for i:=0 to AUsers.Count-1 do // execute as many times as users in the channel
ListBox1.Items.Add(AUsers.Items[i].Nick); // Add to ListBox
//end
Now you have a working IRC client!

Tip: Build an IRC-bot, you only have to work with the content in OnMessage!

Die Muhkuh 20. Dez 2008 14:05

Re: Irc mit Indy
 
Hi,

Du solltest noch dazu schreiben, ob es sich um die Indy 9 oder Indy 10 handelt!

Valle 20. Dez 2008 14:08

Re: Irc mit Indy
 
Zitat:

Zitat von Die Muhkuh
Hi,

Du solltest noch dazu schreiben, ob es sich um die Indy 9 oder Indy 10 handelt!

Ich als Übersetzer oder MSSSSM als Autor? Er hat oben geschrieben, dass er Indy 10 benutzt. ;-)

Mit freundlichen Grüßen,

Valle

Die Muhkuh 20. Dez 2008 14:10

Re: Irc mit Indy
 
Er als Autor. Ich meinte, dass er es ins Tutorial schreiben soll und nicht nur in ein paar Beiträgen drunter.

dangerduck 20. Dez 2008 16:07

Re: Irc mit Indy
 
Danke!
:-D

dangerduck 20. Dez 2008 18:17

Re: Irc mit Indy
 
download link doestn work :cry:
could someone upload it on rapidshare or megaupload please :D

DeddyH 20. Dez 2008 18:19

Re: Irc mit Indy
 
Which link do you mean?

Valle 20. Dez 2008 18:27

Re: Irc mit Indy
 
Zitat:

Zitat von DeddyH
Which link do you mean?

This one.

Everywhere I click, sooner or later I always find this page. But I don't know where to go now, there's no "Continue" button, no "Download" button. And every link on this page results in a 404 error page. :?

DeddyH 20. Dez 2008 18:57

Re: Irc mit Indy
 
Maybe you can have a look at this page.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:33 Uhr.
Seite 2 von 4     12 34      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz