User Control Panel
Advertisements

HELP US, HELP YOU!

Perl/PHP bot

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Tutorials
View unanswered posts
Author Message
LittleTwirp
Newbie
Newbie


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

PostPosted: Fri Mar 04, 2005 2:35 am    Post subject: Reply with quote

I hope this goes here,
It was mostly PHP so I wasn't sure if it showed go in Perl...
(Sorry)
Anyways, back on topic.

So I'm used to PHP and think it's easier (it's my primary programming language Razz )
So what you will need:
A site with PHP,
A Bot.

So I was thinking how could I make it so I can use PHP with my bot.
And I remembered:
Code:
<br />$variable = get "http://bleh.net/bleh.txt";<br />

And thought if I pass variables through it, I can get PHP to do what I want instead of Perl.
So I thought it would be easier for me (personally) to get PHP to do everything. And I could also probaly add some SQL type things with it.
so for on im I changed it to:
Code:
<br />sub on_im {<br />   $client = shift;<br />   $msg = shift;<br />    $rep = get "http://twirp.net/aim/bot.php?man=$client&msg=$msg";<br />$aim->send_im($client,$rep);<br />}<br />1;<br />


It makes it easier for me to think and I don't have to restart the bot everytime I change something Smile
So bot.php looks something like:
Code:
<?php<br />// whats said and the replys<br />$said[1] = ":'(";<br />$reply[1] = "What's wrong?||:'(";<br />$said[2] = "hi|hey|hola|hello";<br />$reply[2] = "hello||hi||hey||sup {name}||hello {name}";<br />$tot = count($said);<br /><br />// if there are no possible replys<br />$n[1] = "I don't understand";<br />$n[2] = "What?!?!?!?";<br />$tn = count($n);<br />$say = stripslashes($msg);<br />function talk_it($man,$say){<br />    global $tot;<br />    global $said;<br />    global $n;<br />    global $t;<br />    global $reply;<br />    global $rt;<br />    global $tn;<br />   for($x=1;$x<$tot;$x++){<br />         if(preg_match("/(.*?)([$said[$x]])(.*?)/i", $say)){<br />             $t = $x;<br />     }<br />   }<br />   $*lazy* = explode("||",$reply[$t]);<br />   $rt = count($*lazy*);<br />   $cr = rand(0,$rt-1);<br />   $message = $*lazy*[$cr];<br />   $message = str_replace("{name}","$man",$message);<br />   if($message==""){<br />     $rd = rand(1,$tn);<br />     $message = $n[$rd];<br />   }<br />   return $message;<br />}<br />$message = talk_it($man,$say);<br />echo "$message";<br />echo "<!--- $man: $say --->";<br />?><br />

So what this does is create an array of things that I want to reply them with.
If I wanted to I could problay log it into a database and problay make it so it can do more.
I can add more and everything.
Or instead of an array, I could have a database storing the replys to things.

I also wanted to make it so my bot could send me messages via e-mail.
Or if the person talking to the bot wanted to send me an e-mail.
So I created this php script:
Code:
<br /><?php<br />   $message = "From: $client \nMessage: $mess";<br />   $to = "me@mysite.com";<br />   $head = "From: \"$client\" <$client>\n";<br />   $subject = "$sub";<br />   $m = mail($to,$subject,$message,$head);<br />   if($m){<br />     echo"Message sent";<br />   }else{<br />     echo"Message couldn't be sent";<br />   }<br />?><br />

To get it so it can send the thing, i added some stuff to onim:
Code:
<br />sub on_im {<br />   $client = shift;<br />   $msg = shift;<br />  if($msg =~ /^\!leave/){<br />     if($msg =~ /^\!leave (.+)/){<br />     $msg =~ s/!leave //ig;<br />     my ($sendto,$newmsg) = split(/->/,$msg);<br />     unless($sendto eq "" || $newmsg eq ""){<br />    $thought = get "http://twirp.net/aim/contact.php?client=$client&mess=$newmsg&sub=$sendto";<br />    sleep(2);<br />    $aim->send_im($client,"Message sent");<br />     }else{<br />    $aim->send_im($client,"Wrong format <br> !msg subject->message");<br />     }<br />    $rep = get "http://twirp.net/aim/bot.php?man=$client&msg=$msg";<br />$aim->send_im($client,$rep);<br />}<br />1;<br />


So now I people can send commands to my bot, and it will go to a PHP script that will do what I want with it.

Thanks for reading :rolleyes:
Hope this was helpful/You unsderstood
Back to top
davidk
Senior Member
Senior Member


Joined: 14 Feb 2004
Posts: 195
Location: United Kingdom, Europe, Earth, Solar system, The Milky Way, The Universe, the 3rd Dimension.
Reputation: 31.1Reputation: 31.1Reputation: 31.1

PostPosted: Sun Mar 06, 2005 9:58 am    Post subject: Reply with quote

:-/ This is complete twap as there aren't any Subroutines in PHP, only functions.
Back to top
Craig
Newbie
Newbie


Joined: 02 Sep 2006
Posts: 13

Reputation: -53.3
votes: 2

PostPosted: Sat Sep 02, 2006 7:14 am    Post subject: Reply with quote

how do you do this in perl ?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Tutorials 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