|
| Author |
Message |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
Posted: Mon Jun 12, 2006 6:38 pm Post subject: commands problem , including |
|
|
| Code: |
## alle commands
## -> admin commands
do './com/admin/exit.pl'; # stopt de bot
do './com/admin/broadcast.pl'; # iedereen een bericht ?
## -> games commands
do './com/games/duckhunt.pl'; # duckhunt game
do './com/games/jup.pl'; # jupjup game
do './com/games/coin.pl'; # kop of munt
## -> nuttige commands
do './com/nuttig/links.pl'; # links systeem
do './com/nuttig/google.pl'; # google opzoekings systeem
do './com/nuttig/tijd.pl'; # tijd weergeven
do './com/nuttig/say.pl'; # naaap code
do './com/nuttig/count.pl'; # reken systeem
## -> info commands
do './com/info/acro.pl'; # acroniem zoeken -buggy-
do './com/info/admin.pl'; # wie is de admin
do './com/info/explain.pl'; # definitie geven
do './com/info/naam.pl'; # naam script
do './com/info/help.pl'; # de hulp
## -> fun commands
do './com/fun/crazy.pl'; # crazy letters
do './com/fun/domblond.pl'; # dom blond grappen (eng)
do './com/fun/emoticon.pl'; # alle emoticons
do './com/fun/love.pl'; # love calculator
do './com/fun/pi.pl'; # pi berekenen
do './com/fun/koffie.pl'; # koffie voor ...
## -> security
do './com/security/sec.pl'; # beveiliging |
this doesn't work :s but i din't get a error  |
|
| Back to top |
|
 |
eric256 The Keymaker

Joined: 03 May 2006 Posts: 2292 Location: Colorado
     
|
Posted: Mon Jun 12, 2006 7:20 pm Post subject: |
|
|
Hey,
It is hard or even impossible to help you. You havn't told us what bot you are using, whats in the files, what you expect it to do, or what it actualy does. Those would all be usefull in trying to help you. In fact they would all be required to even try. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com |
|
| Back to top |
|
 |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
Posted: Wed Jun 14, 2006 5:33 pm Post subject: |
|
|
yeah you wright .
-echotbot rev 84 including the command files so if you send a message !xxx he gives somthing not a text from the bot he runs nice but he doesn't return the commands so !xx doesn't work
by example
| Code: | | do './com/admin/exit.pl'; |
!exit should exit the perl command = the bot.
it doesn't work , if i set the content of exit.pl in the file it does work ...  |
|
| Back to top |
|
 |
mattaustin Sentinel

Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA
  votes: 1
|
Posted: Wed Jun 14, 2006 7:51 pm Post subject: |
|
|
echotbot rev 84 still doesn't help. The echo bot that comes with the module doesnt have a "commands" file.. so I assume you are using some sort of template??? _________________ [ matt ] |
|
| Back to top |
|
 |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
|
| Back to top |
|
 |
mattaustin Sentinel

Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA
  votes: 1
|
Posted: Wed Jun 14, 2006 8:55 pm Post subject: |
|
|
I just went there and downlaoded it again.. there are no "do" commands in the echobot...you moust be useing another template..... _________________ [ matt ] |
|
| Back to top |
|
 |
darkmonkey The Merovingian

Joined: 18 Apr 2004 Posts: 2557 Location: London, England
     votes: 7
|
Posted: Wed Jun 14, 2006 9:00 pm Post subject: |
|
|
Matt, you suggested he used do() to include another file, so he is.
svennson, what've you got in the command files? IF statements? _________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ] |
|
| Back to top |
|
 |
mattaustin Sentinel

Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA
  votes: 1
|
Posted: Wed Jun 14, 2006 9:06 pm Post subject: |
|
|
ahh i get it now.... but he is still giving us no info to help at all! _________________ [ matt ] |
|
| Back to top |
|
 |
eric256 The Keymaker

Joined: 03 May 2006 Posts: 2292 Location: Colorado
     
|
Posted: Wed Jun 14, 2006 10:09 pm Post subject: |
|
|
It seems there is some confusion!
The file you linked to is the download for the MSN protocol connector. It is not a bot, but i think it does include a SAMPLE of a bot. That sample doesn't do anything interesting at all...unless you like echoing!
In order to process commands a bot must do one of a number of things. Actualy the programmer (you) writing the bot must do a number of things. The normal/easiest way to handle commands doesn't exist! Everyone does it differently. As a begginner you probably want to find where your bot echos and make it do something else.
Find where and how it echos, and reprogram that to do somehting slightly different. Then figure out how to tell if the users messages starts with a ! and do something even more different. Then hardcode your commands into that same area. Once you have a good grip on all of that you are probably more ready to start looking at programming a bot that includes commands from external files.
If you just want a bot that works, and doesn't require programming of any sort, the you want to look for what we like to call templates. I'm working on a new one and might even get to releasing it some time this century (hard to tell). Otherwise there are many different premade bots and templates out there that you should be able to find and use. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com |
|
| Back to top |
|
 |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
Posted: Thu Jun 15, 2006 10:43 am Post subject: |
|
|
no i actual got a speaking bot he works fine , but the problem was that my file beacus of the commands who i coded and work. are making the bot file (bot.pl) so long i wanne split it in to parts so i want the commands (I mad / found) in a different file. but the do(); commands doesn't include them.
for talking i use program E whit this code
| Code: | #do 'reply.pl';
my $md5 = $username;
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://localhost/bot/talk.php',['input' => $message,'PHPSESSID' => $md5, 'botname' => 'phpBB helper']);
my ($answer) = $response->content =~ m[<B>A: (.*?)<BR>]sg;
$answer =~ s[<BR>][]isg;
print($username."-+-".$name."\n".$message."\nbot\n".$answer."\n\n");
$self->sendMessage($answer); |
and it works fine , for !msnstatus i use
| Code: | if ($message =~/^!msnserver$/){
my $source = get("http://messenger.msn.com/Status.aspx");
$source =~ m{<span id="MessengerText">(.*?)</span>}is;
$self->sendMessage($1);
} |
and it works :p
but when i place a do("msn.pl"); and place the contex
:
| Code: | if ($message =~/^!msnserver$/){
my $source = get("http://messenger.msn.com/Status.aspx");
$source =~ m{<span id="MessengerText">(.*?)</span>}is;
$self->sendMessage($1);
} | in msn.pl in same folder as bot.pl and i start the bot
i ask the bot !msnstatus he doesn't reply the status.
so the problem is he isn't including the file
my total code is of bot.pl
| Code: | use lib "./lib";
use MSN;
use CGI::Carp qw(fatalsToBrowser);
use SOAP::Lite;
use LWP::Simple;
use Data::Dumper;
use File::Basename;
use Digest::MD5 qw(md5);
use LWP::UserAgent;
use HTTP::Request;
my $handle = 'phpbbhelper@hotmail.com';
my $password = '***';
my $admin = 'svennson56@hotmail.com';
# create an MSN object showing all server errors and other errors
my $msn = new MSN( 'Handle' => $handle, 'Password' => $password );
# OR create an MSN object with all error messages turned off
#my $msn = new MSN( 'Handle' => $handle, 'Password' => $password, 'ServerError' => 0, 'Error' => 0 );
# OR create an MSN object with full debugging info
#my $msn = new MSN( 'Handle' => $handle, 'Password' => $password, 'AutoloadError' => 1, 'Debug' => 1, 'ShowTX' => 1, 'ShowRX' => 1 );
# example of setting client info
$msn->setClientInfo( 'Client' => 'MSNC2' );
# example of setting client capabilites (caps)
$msn->setClientCaps( 'Client-Name' => 'MSN Bot/1.0', 'Chat-Logging' => 'Y', 'Client-Template' => 'None' );
# example of setting the default message style and P4 name
$msn->setMessageStyle( 'Color' => 'FFFFFF', 'Name' => 'phpbb helper (co)', 'Font' => 'Verdana');
# set handlers
$msn->setHandler( 'Connected' => \&Connected );
$msn->setHandler( 'Disconnected' => \&Disconnected );
$msn->setHandler( 'Message' => \&Message );
# connect to the server
$msn->connect();
# run the bot
################### WERKING
sub Connected
{
my $self = shift;
print( "Connected\n" );
$msn->setDisplayPicture("./images/avatar/phpBB.png");
print( "setDisplayPicture -- done\n" );
$msn->setName("phpBB helper (co)");
print( "setName to phpBB helper (co) -- done\n" );
$msn->addEmoticon("cool", "./images/smilies/cool.png");
print( "addemoticons -- done\n" );
$msn->call( $admin, "I am connected!",'Color' => 'FFFFFF', 'Name' => 'phpBB helper (co)', 'Font' => 'Verdana' );
print( "hey admin! -- done\n" );
print( "-----------------------------------------------\n" );
$connecteddate = $date;
open (DATA, ">./Files/connected.txt");
print DATA $connecteddate;
close(DATA);
}
sub Status
{
my( $self, $username, $status ) = @_;
}
sub Message
{
my( $self, $username, $name, $message, %style ) = @_;
## -> nuttige commands
do './com/nuttig/links.pl'; # links systeem
do './com/nuttig/google.pl'; # google opzoekings systeem
do './com/nuttig/tijd.pl'; # tijd weergeven
do './com/nuttig/say.pl'; # naaap code
do './com/nuttig/count.pl'; # reken systeem
## anders reageert de bot
if ($message =~/^!msnserver$/){
my $source = get("http://messenger.msn.com/Status.aspx");
$source =~ m{<span id="MessengerText">(.*?)</span>}is;
$self->sendMessage($1);
}
#do 'reply.pl'; # beveiliging
my $md5 = $username;
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://localhost/bot/talk.php',['input' => $message,'PHPSESSID' => $md5, 'botname' => 'phpBB helper']);
my ($answer) = $response->content =~ m[<B>A: (.*?)<BR>]sg;
$answer =~ s[<BR>][]isg;
print($username."-+-".$name."\n".$message."\nbot\n".$answer."\n\n");
$self->sendMessage($answer);
}
my $run = 1;
while( $run )
{
$msn->do_one_loop();
} |
sorry my reply's are so dum im dutch
maybe see this topic to |
|
| Back to top |
|
 |
eric256 The Keymaker

Joined: 03 May 2006 Posts: 2292 Location: Colorado
     
|
Posted: Thu Jun 15, 2006 2:22 pm Post subject: |
|
|
That helped alot. Okay your problem isn't that the include isn't working, it is that it isn't working the way you expect!
make this do_test.pl
| Code: |
use strict;
use warnings;
our $x = 100;
my $y = 100;
print "\$x = $x\n";
print "\$y = $y\n";
require "do_test2.pl";
print "\$x = $x\n";
print "\$y = $y\n";
|
make this do_test2.pl
| Code: |
$x += 100;
$y += 100;
|
Run that code. You should see that X is updated and Y is not. If you look at do_test.pl you'll see that they are declared differently. Y is declared with "my" which means it will only be accessible in that scope. Files create a scope, brackets create scope, etc. X is declared with "our" which means the variable will be available outside its current scope.
There are multiple ways to make your code work. The obvious one is to scope your variables with our so they are accessible. I generaly wouldn't recommend that or us it though. Scoping is a ncie way to make sure that you don't accidentaly use a variable far off in remote code and not mean to. For commands I generaly make the files i'm includeing modules, and then each of them have a sub inside them (the same sub for each.) Then you loop over the modules and call that sub.
| Code: |
package Commands::Test;
sub process {
my ($x) = @_;
$x += 100;
}
|
| Code: |
use Commands::Test;
my $x = 100;
$x = Commands::Test::process($x);
|
Thats just a sample to give you the idea. Obviously there are lots of ways to expand it, automate it, and improve it. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com |
|
| Back to top |
|
 |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
Posted: Thu Jun 15, 2006 6:47 pm Post subject: |
|
|
| the method din't work on my bot , i am now studien on youre second method should the first code in msn.pm ? |
|
| Back to top |
|
 |
Cer Upgraded Agent

Joined: 03 Feb 2004 Posts: 3776 Location: Michigan
  votes: 4
|
Posted: Thu Jun 15, 2006 8:23 pm Post subject: |
|
|
You shouldn't put any code into the MSN.pm. You should make a new module.
To be consistent with Eric's example:
In your bot's folder, make a "Commands" folder and inside, create a file named "Test.pm" (this is a Perl module, note it has a PM instead of PL extension). Inside, put the code he has:
| Code: | package Commands::Test;
sub process {
my ($x) = @_;
$x += 100;
return $x; # return the new $x
} |
The "package Commands::Test" tells your script the name of the module (path names and package names don't always have to match up, but that's a different subject altogether).
And then create a test.pl in your bot's folder (this is for experimenting with using modules for commands, we're not editing your bot yet at this point) and put in:
| Code: | use Commands::Test;
my $x = 100;
$x = Commands::Test::process ($x);
print "x is $x\n"; |
So once you get these two test files completed and test.pl says "x is 200", then hopefully you'll have a basic understanding of the method of using modules as commands. Then you can try to adapt this to your bot's code. _________________ Current Site (2008) http://www.cuvou.com/ |
|
| Back to top |
|
 |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
Posted: Fri Jun 16, 2006 10:53 am Post subject: |
|
|
I am getting an error on this
| Code: | C:\Program Files\xampp\perl>perl.exe test.pl
Commands/Test.pm did not return a true value at test.pl line 1.
BEGIN failed--compilation aborted at test.pl line 1. |
|
|
| Back to top |
|
 |
svennson Newbie

Joined: 05 Jun 2006 Posts: 29
 
|
Posted: Fri Jun 16, 2006 11:09 am Post subject: |
|
|
changed the pm file to
| Code: | package Abra;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter AutoLoader);
@EXPORT = qw(
);
$VERSION = '0.01';
package Commands::Abra;
sub process {
my ($x) = @_;
$x += 100;
return $x; # return the new $x
}
|
it works but the perl stops after that  |
|
| Back to top |
|
 |
|