]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/OnJoin.pl
take a few more things literally
[infobot.git] / src / Modules / OnJoin.pl
index 68389b5d995be2ac5bd0588adf8b2fed4fb612fb..74ca9d8de9c2b9ee719a1e15549623ac1aa1c189 100644 (file)
@@ -1,9 +1,10 @@
+#!/usr/bin/perl
 #
 # OnJoin.pl: emit a message when a user enters the channel
 #    Author: Corey Edwards <tensai@zmonkey.org>
-#   Version: v0.2
+#   Version: v0.3.1
 #   Created: 20051222
-#   Updated: 20060102
+#   Updated: 20060112
 
 use strict;
 
@@ -24,8 +25,16 @@ sub onjoin {
 
        # print the message, if there was one
        if ($message){
-               &status("OnJoin: $nick arrived, printing message");
-               &msg($chan, $message);
+               $message = substVars($message, 1);
+               if ($message =~ m/^<action>\s*(.*)/){
+                       &status("OnJoin: $nick arrived, performing action");
+                       &action($chan, $1);
+               }
+               else{
+                       $message =~ s/^<reply>\s*//;
+                       &status("OnJoin: $nick arrived, printing message");
+                       &msg($chan, $message);
+               }
        }
 
        return;
@@ -34,18 +43,18 @@ sub onjoin {
 # set and get messages
 sub Cmdonjoin {
        $_ = shift;
-       m/(\S*)( (\S*)( (.*)|)|)/;
+       m/(\S*)(\s*(\S*)(\s*(.*)|)|)/;
        my $ch = $1;
        my $nick = $3;
        my $msg = $5;
 
-       # get options 
+       # get options
        my $strict = &getChanConf('onjoinStrict');
        my $ops = &getChanConf('onjoinOpsOnly');
 
        # see if they specified a channel
        if ($ch !~ m/^\#/ && $ch ne '_default'){
-               $msg = $nick;
+               $msg = $nick . ($msg ? " $msg" : '');
                $nick = $ch;
                $ch = $chan;
        }
@@ -75,9 +84,9 @@ sub Cmdonjoin {
        # if msg not set, show what the message would be
        if (!$msg){
                $nick = $who if (!$nick);
-               $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $ch } ) || '';
-               if ($msg){
-                       &performReply($msg);
+               my %row = &sqlSelectRowHash('onjoin', 'message, modified_by, modified_time', { nick => $nick, channel => $ch } );
+               if ($row{'message'}){
+                       &performStrictReply("onjoin for $nick set by $row{modified_by} on " . localtime($row{modified_time}) . ": $row{message}");
                }
                return;
        }
@@ -100,8 +109,13 @@ sub Cmdonjoin {
 
        # remove old one (if exists) and add new message
        &sqlDelete('onjoin', { nick => $nick, channel => $ch });
-       &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg });
-       &performReply("ok");
+       my $insert = &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg, modified_by => $who, modified_time => time() });
+       if ($insert){
+               &performReply('ok');
+       }
+       else{
+               &performReply('whoops. database error');
+       }
        return;
 }