Page 1 of 1

Regex IRC/Perl

Posted: Thu Nov 16, 2006 1:02 pm
by a94060
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello all, I would like to make a statement that will be able to differencate between !school and !set school. This is what i have right now,but it does not seem to work properly.


[syntax="perl"]#!/usr/bin/perl
##########perl beginning things#########
if ($school == '') {
$school= 'OPEN';
}
else {

$school = $words[2];
}
use Net::IRC;

# create the IRC object
$irc = new Net::IRC;

$conn = $irc->newconn(
	Server 		=> '****',
	# Note: IRC port is normally 6667, but my firewall won't allow it
	Port		=> '6667',
	Nick		=> 'SchoolBot',
	Ircname	=> 'Tells School Openings!',
	Username	=> 'SchoolBot',
	
);
# What to do when the bot successfully connects.
sub on_connect {

        my $conn = shift;
	
        print "Joining Channels...";
	$conn->join("#school");
	$conn->join("#rk");
       $conn->join("#fhs");
	$conn->join("#fms");
	$conn->join("#sgs");
	$conn->join("#fps");
	$conn->join("#pg");
	$conn->join("#mr");
	$conn->join("#ha");
	$conn->join("#ea");
	$conn->join("#cr");
	$conn->privmsg("NickServ","IDENTIFY 674534328740239");
	 $conn->{connected} = 1;
}


sub on_public {
	if ($event->{umode} == '\w\o') {
	# 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];
	
	if ($text=~/^\!set (.+)/) {

	@words= split(' ',$text);

	$school = $words[2];
##################TIME STUFF#################
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$theTime = "$weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year \@ $hour:$minute:$second EST ";
print $theTime; 
###################################################
$conn->privmsg($event->{to}, "School is now $words[2]. Updated $theTime");
}
# regex the text to see if it begins with !school
elsif ($text =~/!school/) {
		# $event->{to} is the channel where this was said
		$conn->privmsg($event->{to}, "School is $words[2]. Set at $theTime");	


}}}

$conn->add_handler('public', \&on_public);
$conn->add_handler('376', \&on_connect);
$irc->start;


This is using the Net::IRC module,i dont think that will matter but the problem is by the if,elsif side. All i need are the regex and i think ill be good. I need to differenciate between !set school and !school


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]