|
 |
|
 |
10-07-2004, 06:38 PM
|
#1 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
perl bot (learning)
hey guys, its been awhile  Im trying to learn perl here with a quickness. Im trying to write a bot for IRC that can take counts for a certain server (servers actually)(176 of them) I am having a hard time finding tutorials on IRC bots in perl. Can anyone recommend a good place to read. I need to get this up ASAP. Thanks much.
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-10-2004, 07:58 PM
|
#2 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
none?
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-10-2004, 09:02 PM
|
#3 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
http://search.cpan.org/~jmuhlich/Net-IRC-0.75/IRC.pm
maybe that will help? i haven't used much perl or irc, but that might get you going.
that looks like fun to work with ,, might be a tempting project.
__________________
Mike
|
|
|
10-11-2004, 02:30 PM
|
#4 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
thanks that helped, i couldnt find that anywhere. This is a seemingly easy project, but i cant seem to wrap my head around the way you have to think as a coder 
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-13-2004, 01:36 PM
|
#6 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
i still cant wrap my head around this...
i keep flipping between Net::IRC and POE::Component::IRC modules for perl because i hear the POE is more up to date. Im having trouble figuring out where to start  I have a connection script with Net::IRC, but dont understand how to make the bot listen in a public channel for commands. Any ideas? I have read the docs, but i am still missing something. Thanks all.
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-14-2004, 05:56 AM
|
#7 (permalink)
|
|
Senior Grasshopper
Join Date: Jun 2003
Location: FL
Posts: 317
|
Not sure. I'll see if I can take a look at Net::IRC or the other sometime soon.
-r
|
|
|
10-14-2004, 06:57 AM
|
#8 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
Quote:
Originally posted by idx
(what does it need to count?)
|
__________________
Mike
|
|
|
10-14-2004, 04:19 PM
|
#9 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
ok, lemme break this down for ya...
In the game Diablo II, on the multiplayer battle.net, there is a new (1.10 patch) feature in the game for a special boss that can be released after a certain type of ring is sold a certain amount of times on a server to the merchants. Follow me so far?
There are roughly 176 servers going at any given time on battle.net's western realm, all using the ip range of 63.241.83.16-200. What im trying to do is create a bot, that will join a certain irc server that we have set up and join a specific channel and watch the channel for counts and events. The format "-count server ip number of rings sold" is used (-count 73 4540). The bot must accknowledge the count and add it to the correct server, it then must be able to pm the user who added the count with a conformation of the count added. It must be able to keep track of how many rings are sold and what the count was or is.
We also use the bot to auto update the topic in the channel when a certain amount of rings sold in a certain amount of time, so that it can move the server to the topic, and once in the topic, move it up the list as far as an standby, active or hot. It must be able to take requests from users that ask which servers have been sold on and what the count is using the format "-event server ip" (-event 73) and respond via pm with something to the effect of "Realm Us-West//63.241.83.73//current SOJ sold: 4435//Reported by user "usernick" on Wed-Oct-13-6:15pm//Diablo reported as Last Walked by: "usernick" with 4421 SOJ's sold//SOJ sold since last walk: 119.
It must also have the ability for a few admins for it that can add Ip's directly to the topic by using the format "-addserver IP" (-addserver 73, which will set it to standby in topic) also add a hot ip "-addhot IP" (-addhot 73, which will add it to hot in topic) and one last command of walk "-walk IP" (-walk 73, which will add it to the walked in the topic.) The walk command must be admin only, so that just any user cant join the channel and add a walk for a server that may or may not have walked.
Seems pretty easy, but i cant get in my head how to go about it. Ive looked at other bots, code, examples, tutorials, and RTFM so many times i know the page numbers and whats on them  Any help would be greatly appreciated
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-16-2004, 10:11 AM
|
#10 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
am i deluting myself thinking this is easy? 
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-17-2004, 05:24 AM
|
#11 (permalink)
|
|
Senior Grasshopper
Join Date: Jun 2003
Location: FL
Posts: 317
|
The listening for messages shouldn't be too bad. You just join one channel and parse anything that comes across. It sounds more complicated when you get into all the other functionality.
-r
Last edited by idx; 10-17-2004 at 06:15 AM.
|
|
|
10-17-2004, 06:14 AM
|
#12 (permalink)
|
|
Senior Grasshopper
Join Date: Jun 2003
Location: FL
Posts: 317
|
Maybe this will be a quick start. Look at the Net::IRC example at wholok.com ( http://www.wholok.com/irc/ ) and download the hello bot. Make sure its working ok, maybe testing it out on your own IRC server (i recommend ngIRCd) or one that doesn't mind bots.
Then add a new on_public event to handle the `-event` messages that a channel might receive. Here's an example one for -count events:
Just add this somewhere above the $irc->start(); call.
Code:
sub on_public {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -count
# then print the values
if ($text =~ /^\-count (\d+)\s(\d+)/) {
$conn->privmsg($event->{to}[0], "I received a count of $2 for server ID $1");
}
}
$conn->add_handler('public', \&on_public);
Fire up the bot and watch it go. So then just create additional if() statements to check the text for your commands and process as necessary.
I believe the roker bot on that page has an example of sending a private message to a user.
As for keeping track of stuff; you can keep counts of various things in memory (a hash works best), but you might want to occasionally write these values out to a file incase the bot needs to be restarted.
-r
|
|
|
10-18-2004, 01:06 PM
|
#13 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
thanks alot, that did help somewhat. Ill be back with more questions soon 
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-20-2004, 04:09 PM
|
#14 (permalink)
|
|
Legend in my own mind
Join Date: May 2002
Location: florida
Posts: 618
|
ok more questions. I used your code and wrote another simular to output on "-event"
Code:
sub on_event {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -event
# then print the values
if ($text =~ /^\-event (\d+)/) {
open (TXT, "<C:\\Perl\\clone\\files\\$1.txt");
$text = <TXT>;
close (TXT);
$conn->privmsg($event->{to}[0], "The count for $1 is $text");
}
}
$conn->add_handler('public', \&on_event);
It works good but the problem is now i cant get them to work together at the same time. Im sure im missing something(prolly an if/else statement) but i was wondering why or how to write an if/else statement when the sub's already do what i need.
Code:
#!/usr/bin/perl -w
use Net::IRC;
use Net::IRC::Event;
#use strict;
my $irc = new Net::IRC;
my $conn = $irc->newconn(
Nick => 'CloneBot2',
Server => 'irc.gameaddix.net',
Port => '6667',
Ircname => 'CloneBot2',
Username =>'CloneBot2',
Logfile => 'C:\Perl\clone\clone.log');
# We're going to add this to the conn hash so we know what channel we
# want to operate in.
$conn->{channel} = shift || '##';
sub on_connect {
# shift in our connection object that is passed automatically
my $conn = shift;
# when we connect, join our channel and greet it
$conn->join($conn->{channel});
$conn->privmsg($conn->{channel}, 'CloneBot is Online!');
$conn->{connected} = 1;
}
;
# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);
#setting of public commands
sub on_count {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -count
# then print the values
if ($text =~ /^\-count (\d+)\s(\d+)/) {
$conn->privmsg($event->{to}[0], "I received a count of $2 for server $1");
open (TXT, ">C:\\Perl\\clone\\files\\$1.txt");
print TXT "$2";
close (TXT);
}
}
$conn->add_handler('public', \&on_count);
sub on_event {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -event
# then print the values
if ($text =~ /^\-event (\d+)/) {
open (TXT, "<C:\\Perl\\clone\\files\\$1.txt");
$text = <TXT>;
close (TXT);
$conn->privmsg($event->{to}[0], "The count for $1 is $text");
}
}
$conn->add_handler('public', \&on_event);
use Data::Dumper;
sub default {
# This is helpful to see what an event returns. Data::Dumper will
# recursively reveal the structure of any value
my ($conn, $event) = @_;
print Dumper($event);
}
# experiment with the cping event, printing out to standard output
$conn->add_handler('cping', \&default);
# start IRC
$irc->start();
__________________
Is it me or does the word abbreviation seem a little long?
registered user #193524 with the Linux Counter,
http://counter.li.org
|
|
|
10-21-2004, 04:13 AM
|
#15 (permalink)
|
|
Senior Grasshopper
Join Date: Jun 2003
Location: FL
Posts: 317
|
I believe you can only have one function per event type, so adding multiple handlers for the `public` event wont work.
Just add your if() logic inside one on_public() subroutine and it should be fine.
Also for the -event code, is it supposed to store the number that comes after -event? (edit: nevermind. I see that the -count handler writes the file)
-r
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
python module for a bot app
|
sarah31 |
Platform/API C++ |
0 |
06-05-2002 06:58 PM |
All times are GMT -8. The time now is 08:15 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|