User Control Panel
Advertisements

HELP US, HELP YOU!

IRC Example

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review
View unanswered posts
Author Message
mat007
Almost An Agent
Almost An Agent


Joined: 12 Jan 2004
Posts: 1375

Reputation: 15.8Reputation: 15.8
votes: 2

PostPosted: Thu Dec 02, 2004 4:55 pm    Post subject: Reply with quote

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 Smile

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 Smile
Back to top
aurora_131
Young One
Young One


Joined: 07 Mar 2004
Posts: 66
Location: Melbourne, victoria.
Reputation: 27.7Reputation: 27.7Reputation: 27.7

PostPosted: Sun Dec 05, 2004 9:24 am    Post subject: Reply with quote

Question: Why do you bother to pass and try to recieve $self in your send sub?
Back to top
mat007
Almost An Agent
Almost An Agent


Joined: 12 Jan 2004
Posts: 1375

Reputation: 15.8Reputation: 15.8
votes: 2

PostPosted: Sun Dec 05, 2004 9:51 am    Post subject: Reply with quote

To be honest....Erm no reason.
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Sun Dec 05, 2004 6:35 pm    Post subject: Reply with quote

$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. Razz
Back to top
Basically
Newbie
Newbie


Joined: 03 Jan 2005
Posts: 21
Location: Almere, The Netherlands
Reputation: 16.7Reputation: 16.7

PostPosted: Mon Jan 03, 2005 3:01 pm    Post subject: Reply with quote

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
Almost An Agent


Joined: 12 Jan 2004
Posts: 1375

Reputation: 15.8Reputation: 15.8
votes: 2

PostPosted: Mon Jan 03, 2005 3:20 pm    Post subject: Reply with quote

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
Newbie


Joined: 03 Jan 2005
Posts: 26
Location: Internet
Reputation: 16.8Reputation: 16.8

PostPosted: Fri Jan 07, 2005 11:45 pm    Post subject: Reply with quote

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...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group