3 # OnJoin.pl: emit a message when a user enters the channel
4 # Author: Corey Edwards <tensai@zmonkey.org>
11 use vars qw(%channels %param);
12 use vars qw($dbh $who $chan);
15 my ($nick, $user, $host, $chan) = @_;
18 # look for a channel specific message
19 my $message = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $chan } ) || 0;
21 # look for a default message
23 $message = &sqlSelect('onjoin', 'message', { nick => $nick, channel => '_default' } ) || 0;
26 # print the message, if there was one
28 $message = substVars($message, 1);
29 if ($message =~ m/^<action>\s*(.*)/){
30 &status("OnJoin: $nick arrived, performing action");
34 $message =~ s/^<reply>\s*//;
35 &status("OnJoin: $nick arrived, printing message");
36 &msg($chan, $message);
43 # set and get messages
46 m/(\S*)(\s*(\S*)(\s*(.*)|)|)/;
52 my $strict = &getChanConf('onjoinStrict');
53 my $ops = &getChanConf('onjoinOpsOnly');
55 # see if they specified a channel
56 if ($ch !~ m/^\#/ && $ch ne '_default'){
57 $msg = $nick . ($msg ? " $msg" : '');
64 if ($nick =~ m/^-(.*)/){
67 if (!$channels{$chan}{o}{$who}){
68 &performReply("sorry, you're not an operator");
72 # regardless of strict mode, ops can always change
73 if (!$channels{$chan}{o}{$who} and $nick ne $who){
74 &performReply("I can't alter a message for another user (strict mode)");
78 &sqlDelete('onjoin', { nick => $nick, channel => $ch });
84 # if msg not set, show what the message would be
86 $nick = $who if (!$nick);
87 my %row = &sqlSelectRowHash('onjoin', 'message, modified_by, modified_time', { nick => $nick, channel => $ch } );
89 &performStrictReply("onjoin for $nick set by $row{modified_by} on " . localtime($row{modified_time}) . ": $row{message}");
94 # only allow changes by ops
96 if (!$channels{$chan}{o}{$who}){
97 &performReply("sorry, you're not an operator");
101 # only allow people to change their own message (superceded by OpsOnly)
103 # regardless of strict mode, ops can always change
104 if (!$channels{$chan}{o}{$who} and $nick ne $who){
105 &performReply("I can't alter a message for another user (strict mode)");
110 # remove old one (if exists) and add new message
111 &sqlDelete('onjoin', { nick => $nick, channel => $ch });
112 my $insert = &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg, modified_by => $who, modified_time => time() });
117 &performReply('whoops. database error');