]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/OnJoin.pl
OnJoin - tensai, fixes by TimRiker
[infobot.git] / src / Modules / OnJoin.pl
1 #
2 # OnJoin.pl: emit a message when a user enters the channel
3 #    Author: tensai
4 #   Version: v0.1
5 #   Created: 20051222
6 #   Updated: 20051230
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         my $n   = lc $nick;
16         my $message = &sqlSelect('onjoin', 'message', { nick => $n, channel => $chan } ) || 0;
17
18         # print the message, if there was one
19         if ($message){
20                 &status("OnJoin: $nick arrived");
21                 &msg($chan, $message);
22         }
23
24         return;
25 }
26
27 # set and get messages
28 sub Cmdonjoin {
29         my $msg = shift;
30         $msg =~ m/(.*?)( (.*))/;
31         my $nick = $1;
32         $msg = $3;
33
34         # if msg not set, show what the message would be
35         if (!$msg){
36                 $nick = $who if (!$nick);
37                 $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $chan } ) || '';
38                 if ($msg){
39                         &performReply($msg);
40                 }
41                 return;
42         }
43
44         # get params
45         my $strict = &getChanConf('onjoinStrict');
46         my $ops = &getChanConf('onjoinOpsOnly');
47
48         # only allow changes by ops
49         if ($ops){
50                 if (!$channels{$chan}{o}{$who}){
51                         &performReply("sorry, you're not an operator");
52                         return;
53                 }
54         }
55         # only allow people to change their own message (superceded by OpsOnly)
56         elsif ($strict){
57                 # regardless of strict mode, ops can always change
58                 if (!$channels{$chan}{o}{$who} and $nick ne $who){
59                         &performReply("I can't alter a message for another user (strict mode)");
60                         return;
61                 }
62         }
63
64         &sqlDelete('onjoin', { nick => $nick, channel => $chan});
65         &sqlInsert('onjoin', { nick => $nick, channel => $chan, message => $msg});
66         &performReply("ok");
67         return;
68 }
69
70 1;