PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 24, 2019 1:55 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Regex IRC/Perl
PostPosted: Thu Nov 16, 2006 2:02 pm 
Offline
Forum Regular
User avatar

Joined: Fri Feb 10, 2006 5:53 pm
Posts: 543
feyd | Please use
Syntax: [ Download ] [ Hide ]
,
[syntax=php]and
Syntax: [ Download ] [ Hide ]
  1. tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: to learn how to do it too. 
  2.  
  3.  
  4.  
  5.  
  6.  
  7. 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. 
  8.  
  9.  
  10.  
  11.  
  12.  
  13. [syntax="perl"]#!/usr/bin/perl 
  14.  
  15. ##########perl beginning things######### 
  16.  
  17. if ($school == '') { 
  18.  
  19. $school= 'OPEN'; 
  20.  
  21.  
  22. else { 
  23.  
  24.  
  25.  
  26. $school = $words[2]; 
  27.  
  28.  
  29. use Net::IRC; 
  30.  
  31.  
  32.  
  33. # create the IRC object 
  34.  
  35. $irc = new Net::IRC; 
  36.  
  37.  
  38.  
  39. $conn = $irc->newconn( 
  40.  
  41. Server => '****', 
  42.  
  43. # Note: IRC port is normally 6667, but my firewall won't allow it 
  44.  
  45. Port => '6667', 
  46.  
  47. Nick => 'SchoolBot', 
  48.  
  49. Ircname => 'Tells School Openings!', 
  50.  
  51. Username => 'SchoolBot', 
  52.  
  53.  
  54.  
  55. ); 
  56.  
  57. # What to do when the bot successfully connects. 
  58.  
  59. sub on_connect { 
  60.  
  61.  
  62.  
  63. my $conn = shift; 
  64.  
  65.  
  66.  
  67. print "Joining Channels..."; 
  68.  
  69. $conn->join("#school"); 
  70.  
  71. $conn->join("#rk"); 
  72.  
  73. $conn->join("#fhs"); 
  74.  
  75. $conn->join("#fms"); 
  76.  
  77. $conn->join("#sgs"); 
  78.  
  79. $conn->join("#fps"); 
  80.  
  81. $conn->join("#pg"); 
  82.  
  83. $conn->join("#mr"); 
  84.  
  85. $conn->join("#ha"); 
  86.  
  87. $conn->join("#ea"); 
  88.  
  89. $conn->join("#cr"); 
  90.  
  91. $conn->privmsg("NickServ","IDENTIFY 674534328740239"); 
  92.  
  93. $conn->{connected} = 1; 
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. sub on_public { 
  101.  
  102. if ($event->{umode} == '\w\o') { 
  103.  
  104. # on an event, we get connection object and event hash 
  105.  
  106. my ($conn, $event) = @_; 
  107.  
  108.  
  109.  
  110. # this is what was said in the event 
  111.  
  112. my $text = $event->{args}[0]; 
  113.  
  114.  
  115.  
  116. if ($text=~/^\!set (.+)/) { 
  117.  
  118.  
  119.  
  120. @words= split(' ',$text); 
  121.  
  122.  
  123.  
  124. $school = $words[2]; 
  125.  
  126. ##################TIME STUFF################# 
  127.  
  128. @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); 
  129.  
  130. @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); 
  131.  
  132. ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); 
  133.  
  134. $year = 1900 + $yearOffset; 
  135.  
  136. $theTime = "$weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year \@ $hour:$minute:$second EST "; 
  137.  
  138. print $theTime;  
  139.  
  140. ################################################### 
  141.  
  142. $conn->privmsg($event->{to}, "School is now $words[2]. Updated $theTime"); 
  143.  
  144.  
  145. # regex the text to see if it begins with !school 
  146.  
  147. elsif ($text =~/!school/) { 
  148.  
  149. # $event->{to} is the channel where this was said 
  150.  
  151. $conn->privmsg($event->{to}, "School is $words[2]. Set at $theTime");  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. }}} 
  158.  
  159.  
  160.  
  161. $conn->add_handler('public', \&on_public); 
  162.  
  163. $conn->add_handler('376', \&on_connect); 
  164.  
  165. $irc->start; 
  166.  
  167.  
  168.  
  169.  
  170.  
  171. [/syntax] 
  172.  
  173.  
  174.  
  175. 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 
  176.  
  177.  
  178.  
  179.  
  180.  
  181. feyd | Please use 
Syntax: [ Download ] [ Hide ]
,
[syntax=php]and
Syntax: [ Download ] [ Hide ]
  1. tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: to learn how to do it too. 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group