2 # OnJoin.pl: emit a message when a user enters the channel
3 # Author: Corey Edwards <tensai@zmonkey.org>
10 use vars qw(%channels %param);
11 use vars qw($dbh $who $chan);
14 my ($nick, $user, $host, $chan) = @_;
17 # look for a channel specific message
18 my $message = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $chan } ) || 0;
20 # look for a default message
22 $message = &sqlSelect('onjoin', 'message', { nick => $nick, channel => '_default' } ) || 0;
25 # print the message, if there was one
27 $message = substVars($message);
28 if ($message =~ m/^<action>\s*(.*)/){
29 &status("OnJoin: $nick arrived, performing action");
33 $message =~ s/^<reply>\s*//;
34 &status("OnJoin: $nick arrived, printing message");
35 &msg($chan, $message);
42 # set and get messages
45 m/(\S*)(\s*(\S*)(\s*(.*)|)|)/;
51 my $strict = &getChanConf('onjoinStrict');
52 my $ops = &getChanConf('onjoinOpsOnly');
54 # see if they specified a channel
55 if ($ch !~ m/^\#/ && $ch ne '_default'){
56 $msg = $nick . ($msg ? " $msg" : '');
63 if ($nick =~ m/^-(.*)/){
66 if (!$channels{$chan}{o}{$who}){
67 &performReply("sorry, you're not an operator");
71 # regardless of strict mode, ops can always change
72 if (!$channels{$chan}{o}{$who} and $nick ne $who){
73 &performReply("I can't alter a message for another user (strict mode)");
77 &sqlDelete('onjoin', { nick => $nick, channel => $ch });
83 # if msg not set, show what the message would be
85 $nick = $who if (!$nick);
86 $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $ch } ) || '';
93 # only allow changes by ops
95 if (!$channels{$chan}{o}{$who}){
96 &performReply("sorry, you're not an operator");
100 # only allow people to change their own message (superceded by OpsOnly)
102 # regardless of strict mode, ops can always change
103 if (!$channels{$chan}{o}{$who} and $nick ne $who){
104 &performReply("I can't alter a message for another user (strict mode)");
109 # remove old one (if exists) and add new message
110 &sqlDelete('onjoin', { nick => $nick, channel => $ch });
111 &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg });