]> git.donarmstrong.com Git - infobot.git/commitdiff
OnJoin - tensai, fixes by TimRiker
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Sun, 1 Jan 2006 23:02:50 +0000 (23:02 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Sun, 1 Jan 2006 23:02:50 +0000 (23:02 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@1242 c11ca15a-4712-0410-83d8-924469b57eb5

files/sample/blootbot.chan
setup/onjoin.sql [new file with mode: 0644]
src/CommandStubs.pl
src/DynaConfig.pl
src/IRC/IrcHooks.pl
src/Modules/OnJoin.pl [new file with mode: 0644]
src/dbi.pl
src/modules.pl

index 6390b94e47633d831a58ababe937b34c89334095..01af3048acedbf6c01c4cf3527b08840ae7e0dd3 100644 (file)
@@ -1,9 +1,8 @@
-#v1: blootbot -- blootbot -- written Fri Aug 12 22:01:53 2005
+#v1: blootbot -- blootbot -- written Sun Jan  1 22:59:37 2006
 
 #botpark
     +RootWarn
-    _time_added 1108710504
-    autojoin
+    +autojoin
 
 #debian-bots
     +News
@@ -31,6 +30,7 @@ _default
     +HTTPDtype
     +Kernel
     +Math
+    +OnJoin
     +Plug
     +Quote
     +Rss
diff --git a/setup/onjoin.sql b/setup/onjoin.sql
new file mode 100644 (file)
index 0000000..001924e
--- /dev/null
@@ -0,0 +1,5 @@
+CREATE TABLE onjoin (
+       nick VARCHAR(20) NOT NULL,
+       channel VARCHAR(16) NOT NULL,
+       message VARCHAR(255) NOT NULL
+);
index 43df9acc70fc249da67ceaab5ae3c81fde6a8ef6..e2aa6b8250e0baf9cc5dcf65ffc49860544c84b3 100644 (file)
@@ -887,6 +887,7 @@ sub nullski {
 &addCmdHook('quote', ('CODEREF' => 'Quote::Quote', 'Forker' => 1, 'Identifier' => 'Quote', 'Help' => 'quote', 'Cmdstats' => 'Quote') );
 &addCmdHook('reverse', ('CODEREF' => 'reverse::reverse', 'Identifier' => 'reverse', 'Cmdstats' => 'reverse', 'Forker' => 1, 'Module' => 'reverse') );
 &addCmdHook('RootWarn', ('CODEREF' => 'CmdrootWarn', 'Identifier' => 'RootWarn', 'Module' => 'RootWarn') );
+&addCmdHook('OnJoin', ('CODEREF' => 'Cmdonjoin', 'Identifier' => 'OnJoin', 'Module' => 'OnJoin') );
 &addCmdHook('Rss', ('CODEREF' => 'Rss::Rss', 'Identifier' => 'Rss', 'Cmdstats' => 'Rss', 'Forker' => 1, 'Help' => 'rss') );
 &addCmdHook('sched(stats|info)', ('CODEREF' => 'scheduleList', ) );
 &addCmdHook('scramble', ('CODEREF' => 'scramble::scramble', 'Identifier' => 'scramble', 'Cmdstats' => 'scramble', 'Forker' => 1, 'Module' => 'scramble') );
index 4e5153fb29e9d2a7968fa18503f0fe198ec70d56..e1cf464a1a68960ac691cf6b98e0002aa5639923 100644 (file)
@@ -821,6 +821,11 @@ sub rehashConfVars {
            &loadMyModule('RootWarn');
            delete $cache{confvars}{$_};
        }
+
+       if (/^onjoin$/i and $i) {
+           &loadMyModule('OnJoin');
+           delete $cache{confvars}{$_};
+       }
     }
 
     &DEBUG("end of rehashConfVars");
index dac4238f038fc76b0d0a59440ecea45cec7e691d..542ba63643a5b28ade0797f1f1babf113e62c241 100644 (file)
@@ -584,6 +584,9 @@ sub on_join {
                $user =~ /^~?r(oo|ew|00)t$/i
     );
 
+    ### emit a message based on who just joined
+        &onjoin($who,$user,$host,$chan) if (&IsChanConf('OnJoin'));
+
     ### NEWS:
     if (&IsChanConf('News') && &IsChanConf('newsKeepRead')) {
        if (!&loadMyModule('News')) {   # just in case.
diff --git a/src/Modules/OnJoin.pl b/src/Modules/OnJoin.pl
new file mode 100644 (file)
index 0000000..53b5082
--- /dev/null
@@ -0,0 +1,70 @@
+#
+# OnJoin.pl: emit a message when a user enters the channel
+#    Author: tensai
+#   Version: v0.1
+#   Created: 20051222
+#   Updated: 20051230
+
+use strict;
+
+use vars qw(%channels %param);
+use vars qw($dbh $who $chan);
+
+sub onjoin {
+       my ($nick, $user, $host, $chan) = @_;
+       my $n   = lc $nick;
+       my $message = &sqlSelect('onjoin', 'message', { nick => $n, channel => $chan } ) || 0;
+
+       # print the message, if there was one
+       if ($message){
+               &status("OnJoin: $nick arrived");
+               &msg($chan, $message);
+       }
+
+       return;
+}
+
+# set and get messages
+sub Cmdonjoin {
+       my $msg = shift;
+       $msg =~ m/(.*?)( (.*))/;
+       my $nick = $1;
+       $msg = $3;
+
+       # if msg not set, show what the message would be
+       if (!$msg){
+               $nick = $who if (!$nick);
+               $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $chan } ) || '';
+               if ($msg){
+                       &performReply($msg);
+               }
+               return;
+       }
+
+       # get params
+       my $strict = &getChanConf('onjoinStrict');
+       my $ops = &getChanConf('onjoinOpsOnly');
+
+       # only allow changes by ops
+       if ($ops){
+               if (!$channels{$chan}{o}{$who}){
+                       &performReply("sorry, you're not an operator");
+                       return;
+               }
+       }
+       # only allow people to change their own message (superceded by OpsOnly)
+       elsif ($strict){
+               # regardless of strict mode, ops can always change
+               if (!$channels{$chan}{o}{$who} and $nick ne $who){
+                       &performReply("I can't alter a message for another user (strict mode)");
+                       return;
+               }
+       }
+
+       &sqlDelete('onjoin', { nick => $nick, channel => $chan});
+       &sqlInsert('onjoin', { nick => $nick, channel => $chan, message => $msg});
+       &performReply("ok");
+       return;
+}
+
+1;
index 99d115e4d95d81a3f471faeaff568be27e2f4d39..bee8063ac20ce82eed837195fae5d32627e161f4 100644 (file)
@@ -639,7 +639,7 @@ sub checkTables {
        # create database not needed for SQLite
     }
 
-    foreach ( qw(botmail connections factoids rootwarn seen stats) ) {
+    foreach ( qw(botmail connections factoids rootwarn seen stats onjoin) ) {
        if (exists $db{$_}) {
            $cache{has_table}{$_} = 1;
            next;
index af03265bd19b445fe2a6366f1ee913238e7ff0b5..961b90b7a3d8713ab8a6c020c085d8789f8061c2 100644 (file)
@@ -24,7 +24,7 @@ if ($@) {
 my @myModulesLoadNow;
 my @myModulesReloadNot;
 BEGIN {
-    @myModulesLoadNow  = ('Topic', 'Uptime', 'News', 'RootWarn', 'DumpVars2', 'botmail');
+    @myModulesLoadNow  = ('Topic', 'Uptime', 'News', 'RootWarn', 'DumpVars2', 'botmail', 'OnJoin');
     @myModulesReloadNot        = ('IRC/Irc.pl','IRC/Schedulers.pl');
 }