+#!/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;
# 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;
# 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;
}
# 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;
}
# 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;
}