]> git.donarmstrong.com Git - infobot.git/blob - blootbot/src/Modules/OnJoin.pl
<action>
[infobot.git] / blootbot / src / Modules / OnJoin.pl
1 #
2 # OnJoin.pl: emit a message when a user enters the channel
3 #    Author: Corey Edwards <tensai@zmonkey.org>
4 #   Version: v0.2.2
5 #   Created: 20051222
6 #   Updated: 20060105
7
8 use strict;
9
10 use vars qw(%channels %param);
11 use vars qw($dbh $who $chan);
12
13 sub onjoin {
14         my ($nick, $user, $host, $chan) = @_;
15         $nick = lc $nick;
16
17         # look for a channel specific message
18         my $message = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $chan } ) || 0;
19
20         # look for a default message
21         if (!$message){
22                 $message = &sqlSelect('onjoin', 'message', { nick => $nick, channel => '_default' } ) || 0;
23         }
24
25         # print the message, if there was one
26         if ($message){
27                 $message = substVars($message);
28                 if ($message =~ m/^<action>\s*(.*)/){
29                         &status("OnJoin: $nick arrived, performing action");
30                         &action($chan, $1);
31                 }
32                 else{
33                         $message =~ s/^<reply>\s*//;
34                         &status("OnJoin: $nick arrived, printing message");
35                         &msg($chan, $message);
36                 }
37         }
38
39         return;
40 }
41
42 # set and get messages
43 sub Cmdonjoin {
44         $_ = shift;
45         m/(\S*)(\s*(\S*)(\s*(.*)|)|)/;
46         my $ch = $1;
47         my $nick = $3;
48         my $msg = $5;
49
50         # get options 
51         my $strict = &getChanConf('onjoinStrict');
52         my $ops = &getChanConf('onjoinOpsOnly');
53
54         # see if they specified a channel
55         if ($ch !~ m/^\#/ && $ch ne '_default'){
56                 $msg = $nick . ($msg ? " $msg" : '');
57                 $nick = $ch;
58                 $ch = $chan;
59         }
60
61         $nick = lc $nick;
62
63         if ($nick =~ m/^-(.*)/){
64                 $nick = $1;
65                 if ($ops){
66                         if (!$channels{$chan}{o}{$who}){
67                                 &performReply("sorry, you're not an operator");
68                         }
69                 }
70                 elsif ($strict){
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)");
74                         }
75                 }
76                 else{
77                         &sqlDelete('onjoin', { nick => $nick, channel => $ch });
78                         &performReply('ok');
79                 }
80                 return;
81         }
82
83         # if msg not set, show what the message would be
84         if (!$msg){
85                 $nick = $who if (!$nick);
86                 $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $ch } ) || '';
87                 if ($msg){
88                         &performReply($msg);
89                 }
90                 return;
91         }
92
93         # only allow changes by ops
94         if ($ops){
95                 if (!$channels{$chan}{o}{$who}){
96                         &performReply("sorry, you're not an operator");
97                         return;
98                 }
99         }
100         # only allow people to change their own message (superceded by OpsOnly)
101         elsif ($strict){
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)");
105                         return;
106                 }
107         }
108
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 });
112         &performReply("ok");
113         return;
114 }
115
116 1;