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
20 &sqlSelect( 'onjoin', 'message', { nick => $nick, channel => $chan } )
23 # look for a default message
26 &sqlSelect( 'onjoin', 'message',
27 { nick => $nick, channel => '_default' } )
31 # print the message, if there was one
33 $message = substVars( $message, 1 );
34 if ( $message =~ m/^<action>\s*(.*)/ ) {
35 &status("OnJoin: $nick arrived, performing action");
39 $message =~ s/^<reply>\s*//;
40 &status("OnJoin: $nick arrived, printing message");
41 &msg( $chan, $message );
48 # set and get messages
51 m/(\S*)(\s*(\S*)(\s*(.*)|)|)/;
57 my $strict = &getChanConf('onjoinStrict');
58 my $ops = &getChanConf('onjoinOpsOnly');
60 # see if they specified a channel
61 if ( $ch !~ m/^\#/ && $ch ne '_default' ) {
62 $msg = $nick . ( $msg ? " $msg" : '' );
69 if ( $nick =~ m/^-(.*)/ ) {
72 if ( !$channels{$chan}{o}{$who} ) {
73 &performReply("sorry, you're not an operator");
78 # regardless of strict mode, ops can always change
79 if ( !$channels{$chan}{o}{$who} and $nick ne $who ) {
81 "I can't alter a message for another user (strict mode)");
85 &sqlDelete( 'onjoin', { nick => $nick, channel => $ch } );
91 # if msg not set, show what the message would be
93 $nick = $who if ( !$nick );
94 my %row = &sqlSelectRowHash(
96 'message, modified_by, modified_time',
97 { nick => $nick, channel => $ch }
99 if ( $row{'message'} ) {
100 &performStrictReply( "onjoin for $nick set by $row{modified_by} on "
101 . localtime( $row{modified_time} )
102 . ": $row{message}" );
107 # only allow changes by ops
109 if ( !$channels{$chan}{o}{$who} ) {
110 &performReply("sorry, you're not an operator");
115 # only allow people to change their own message (superceded by OpsOnly)
118 # regardless of strict mode, ops can always change
119 if ( !$channels{$chan}{o}{$who} and $nick ne $who ) {
121 "I can't alter a message for another user (strict mode)");
126 # remove old one (if exists) and add new message
127 &sqlDelete( 'onjoin', { nick => $nick, channel => $ch } );
128 my $insert = &sqlInsert(
135 modified_time => time()
142 &performReply('whoops. database error');
149 # vim:ts=4:sw=4:expandtab:tw=80