]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/OnJoin.pl
don't drop part of message when no #channel
[infobot.git] / 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.1
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                 &status("OnJoin: $nick arrived, printing message");
28                 &msg($chan, $message);
29         }
30
31         return;
32 }
33
34 # set and get messages
35 sub Cmdonjoin {
36         $_ = shift;
37         m/(\S*)(\s*(\S*)(\s*(.*)|)|)/;
38         my $ch = $1;
39         my $nick = $3;
40         my $msg = $5;
41
42         # get options 
43         my $strict = &getChanConf('onjoinStrict');
44         my $ops = &getChanConf('onjoinOpsOnly');
45
46         # see if they specified a channel
47         if ($ch !~ m/^\#/ && $ch ne '_default'){
48                 $msg = $nick . ($msg ? " $msg" : '');
49                 $nick = $ch;
50                 $ch = $chan;
51         }
52
53         $nick = lc $nick;
54
55         if ($nick =~ m/^-(.*)/){
56                 $nick = $1;
57                 if ($ops){
58                         if (!$channels{$chan}{o}{$who}){
59                                 &performReply("sorry, you're not an operator");
60                         }
61                 }
62                 elsif ($strict){
63                         # regardless of strict mode, ops can always change
64                         if (!$channels{$chan}{o}{$who} and $nick ne $who){
65                                 &performReply("I can't alter a message for another user (strict mode)");
66                         }
67                 }
68                 else{
69                         &sqlDelete('onjoin', { nick => $nick, channel => $ch });
70                         &performReply('ok');
71                 }
72                 return;
73         }
74
75         # if msg not set, show what the message would be
76         if (!$msg){
77                 $nick = $who if (!$nick);
78                 $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $ch } ) || '';
79                 if ($msg){
80                         &performReply($msg);
81                 }
82                 return;
83         }
84
85         # only allow changes by ops
86         if ($ops){
87                 if (!$channels{$chan}{o}{$who}){
88                         &performReply("sorry, you're not an operator");
89                         return;
90                 }
91         }
92         # only allow people to change their own message (superceded by OpsOnly)
93         elsif ($strict){
94                 # regardless of strict mode, ops can always change
95                 if (!$channels{$chan}{o}{$who} and $nick ne $who){
96                         &performReply("I can't alter a message for another user (strict mode)");
97                         return;
98                 }
99         }
100
101         # remove old one (if exists) and add new message
102         &sqlDelete('onjoin', { nick => $nick, channel => $ch });
103         &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg });
104         &performReply("ok");
105         return;
106 }
107
108 1;