Page 1 of 1

IRC Bot

Posted: Sun Jun 01, 2008 4:45 pm
by oToom
Well, I am working on an irc bot.
I have this so far.

Code: Select all

OpenConsole()

If InitNetwork() = 0
  PrintN("Error, Can't initialize the network.")
EndIf 

Port = 6667
ConnectionID = OpenNetworkConnection("irc.raw-net.com", Port)

If ConnectionID

  Nick$ = "nwBot"
  Channel$ = "#rawnet"
  Databuffer.s=""
  DataBufferLength.w=1024
  
    SendNetworkString(ConnectionID, "NICK"+Nick$+Chr(13)+Chr(10))
    SendNetworkString(ConnectionID, "USER blah 8 * : blah"+Chr(13)+Chr(10))
    SendNetworkString(ConnectionID, "JOIN"+Channel$+Chr(13)+Chr(10))
    
      While 1 
        If NetworkClientEvent(ConnectionID)=2
          Result = ReceiveNetworkData(ConnectionID, @DataBuffer, DataBufferLength)
          PrintN(Databuffer)
        EndIf
      Wend


EndIf



End
COuld someone help me just do a simple command, Ping / Pong. Because this times out everytime it connects.
Thank you.

Also, just on a side note. In the console it says its connected, then times out.
Yet the bot is not actually joined the channel.

Thanks to anyone that can help me.

Need-Help:
Ping / Pong.

Posted: Sun Jun 01, 2008 5:01 pm
by Tranquil
Maybe this helps you:

http://www.purebasic.fr/english/viewtop ... hlight=irc

I use this procedures with success. If a PiNG-Request arrive you, you just have to send a PONG.

In my code it looks like this:

Code: Select all

    If Left(Commands(),4)="PING"
      SendNetworkString(NetID,ReplaceString(Commands(),"PING","PONG")+#NewLine)
    EndIf

Posted: Sun Jun 01, 2008 5:38 pm
by Rook Zimbabwe
Still trying to disrupt MSN huh! :lol:

Posted: Sun Jun 01, 2008 7:36 pm
by oToom
Wtf, how has this got anything to do with msn?

This is an irc bot.
Eventually it will have commands such as, !google (query here)
And it will give the first 3 searches, At the moment i have no clue on how to go about doing this but hey.

At the moment i want it just to say stuff like, when someone says hello, it will greet them back.

So i do not know how this has anything to do with msn?
Explain to me. Go for it.

Posted: Sun Jun 01, 2008 8:07 pm
by LuCiFeR[SD]
hehehe, I have to agree with Rook, it does (from a casual observers perspective) look very suspicious :P

one minute it is MSN style malware you want to play with... then IRC... So what is it this time... a botnet?

But if you REALLY want to know how it all works... http://www.irchelp.org/irchelp/rfc/rfc.html

Actually.... you could download eggdrop or winbot, both have source code available for your browsing pleasure... why reinvent the wheel?

Posted: Sun Jun 01, 2008 10:02 pm
by oToom
I know what happens,
I code irc bots sometimes in perl.

But i don't know how to do it in purebasic.

And lol. A botnet? Seriously, if i wanted to, i would do it in C++ or something?


Anyway, no, this has nothing to do with malware. I just want a fricken irc bot working. Yet if you aren't up for helping. I'm off. Cya'z

Posted: Sun Jun 01, 2008 10:25 pm
by maw
Well, you have made 2 critical errors in your code. The first is when you send "NICK"+Nick$+Chr(13)+Chr(10) this will send NICKnwBot, you need a space! "NICK "+Nick$+Chr(13)+Chr(10), same goes for the join command.

The second mistake is the databuffer. You never allocate one! You need to either do a Databuffer.s = space(1024) or use AllocateMemory().

With those 2 fixed I'm sure you're gonna be able to continue a little easier.

Posted: Sun Jun 01, 2008 10:35 pm
by oToom
Ah, well. It joins fine now. And has yet to time out.

I didn't need the allocatememory thing in the end, or not as far as it goes. Not to mention i don't know hardly anything about pureBASIC.

Posted: Sun Jun 01, 2008 11:31 pm
by Rook Zimbabwe
Allocating memory will help if you get many requests at once... you can hold them there and parse them at your leisure.

Posted: Mon Jun 02, 2008 10:27 pm
by oToom
Well, i will try whatever! Lol!