|
| Author |
Message |
mat007 Almost An Agent

Joined: 12 Jan 2004 Posts: 1375
   votes: 2
|
Posted: Thu Dec 02, 2004 4:55 pm Post subject: |
|
|
Ok this is my IRC example!
DO NOT TAKE THIS SERIOUSLY!! If you want an IRC bot i suggest Net::IRC ot Sonara Interface to handle it.
Im realesing so you guys can learn from it 
| Code: | | ####################################################<br /># Perl IRC #<br /># #<br /># By Matthew Fenton 2004 #<br /># !THIS IS NOT A BOT ITS AN EXAMPLE! #<br />####################################################<br /># Main Code #<br />####################################################<br /># Need Modules/Vars/Hashes/Etc #<br />####################################################<br /><br />use IO::Socket;<br /><br />$BOT{'Server'} = 'irc.slashnet.org';<br />$BOT{'Nick'} = 'BotDep';<br />$BOT{'Port'} = 6667;<br />$BOT{'Channel'} = 'bot-depot';<br />$BOT{'Name'} = 'Mat006';<br />$debug = 0; # Set to 1 to debug :)<br /><br />$SOCKET = IO::Socket::INET->new(PeerAddr => $BOT{'Server'}, PeerPort => $BOT{'Port'}, Proto => 'tcp') or warn("Error: I failed to connect because: $!");<br /><br /># Kick start it by sending the first bits of data.<br />&SendSS($self, "NICK $BOT{'Nick'}");<br /><br />while($data = <$SOCKET>)<br /> {<br /> print($data) if($debug eq 1);<br /> if($data =~ /checking ident/i)<br /> {<br /> &SendSS($self, "USER $BOT{'Name'} \"extrabot.net\" \"$BOT{'Server'}\" :$BOT{'Name'}");<br /> #&SendSS($self, "NICKSERV :identify nick_password\n"); # Used to AUTH.<br /> sleep(2);<br /> &SendSS($self, "JOIN \#$BOT{'Channel'}");<br /> sleep(1);<br /> &SendSS($self, "PRIVMSG \#" . $BOT{'Channel'} . " :Example! CODE");<br /> }<br /> if($data =~ /Ping/i)<br /> {<br /> &SendSS($self, "PONG :$BOT{'Server'}");<br /> }<br /> if($data =~ /PRIVMSG \#(.*) :(.*)/i)<br /> {<br /> $msg = $2;<br /> print "\nRecieved Message: " . $msg;<br /> if($msg =~ /^!menu/)<br /> {<br /> &SendSS($self, "PRIVMSG \#" . $BOT{'Channel'} . " :Menu:");<br /> &SendSS($self, "PRIVMSG \#" . $BOT{'Channel'} . " :\t\*\*\* !menu - Shows this menu.");<br /> }<br /> }<br />}<br />####################################################<br /># SendData #<br /># Called By: &SendSS("Data HERE"); #<br />####################################################<br />sub SendSS<br /> {<br /> my $self = shift;<br /> my $command = shift;<br /> $SOCKET->send($command . "\n");<br /> print "Sent " . "-> " . $command . "\n";<br />} |
Its okay to connect etc i may re make thisso its more efficent but till then learn from it.
Its not a bot btw  |
|
| Back to top |
|
 |
aurora_131 Young One

Joined: 07 Mar 2004 Posts: 66 Location: Melbourne, victoria.
   
|
Posted: Sun Dec 05, 2004 9:24 am Post subject: |
|
|
| Question: Why do you bother to pass and try to recieve $self in your send sub? |
|
| Back to top |
|
 |
mat007 Almost An Agent

Joined: 12 Jan 2004 Posts: 1375
   votes: 2
|
Posted: Sun Dec 05, 2004 9:51 am Post subject: |
|
|
| To be honest....Erm no reason. |
|
| Back to top |
|
 |
Mojave Almost An Agent

Joined: 01 Nov 2003 Posts: 1434
 
|
Posted: Sun Dec 05, 2004 6:35 pm Post subject: |
|
|
$self is not even defined as far as I can see - its use usually signals that the code is object-oriented, but this clearly isn't - it's like you stuck it in there to look good.  |
|
| Back to top |
|
 |
Basically Newbie

Joined: 03 Jan 2005 Posts: 21 Location: Almere, The Netherlands
  
|
Posted: Mon Jan 03, 2005 3:01 pm Post subject: |
|
|
| Code: | | print($data) if($debug eq 1); |
I think you should use == instead of eq.
| Code: | | print($data) if($debug == 1); |
|
|
| Back to top |
|
 |
mat007 Almost An Agent

Joined: 12 Jan 2004 Posts: 1375
   votes: 2
|
Posted: Mon Jan 03, 2005 3:20 pm Post subject: |
|
|
| Yea i know ill prolly realese my recode of it soon that ones messy and a bit bugy ive just gota add level checking and version response. |
|
| Back to top |
|
 |
LittleTwirp Newbie

Joined: 03 Jan 2005 Posts: 26 Location: Internet
  
|
Posted: Fri Jan 07, 2005 11:45 pm Post subject: |
|
|
QUOTE(Mat007 @ Dec 2 2004, 08:55 AM) DO NOT TAKE THIS SERIOUSLY!! If you want an IRC bot i suggest Net::IRC ot Sonara Interface to handle it. | i found a good net::irc tutorial: http://www.wholok.com/irc/ just thought i let you know... |