]> git.donarmstrong.com Git - infobot.git/commitdiff
keep track of who/when modified onjoin
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Tue, 10 Jan 2006 17:59:18 +0000 (17:59 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Tue, 10 Jan 2006 17:59:18 +0000 (17:59 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@1263 c11ca15a-4712-0410-83d8-924469b57eb5

setup/onjoin.sql
src/Modules/OnJoin.pl

index 001924e4df886d5f223a98e4fd3935b4c294507c..994cc5480c97af655d005beef7b3e26faa6b1d47 100644 (file)
@@ -1,5 +1,14 @@
 CREATE TABLE onjoin (
        nick VARCHAR(20) NOT NULL,
        channel VARCHAR(16) NOT NULL,
-       message VARCHAR(255) NOT NULL
+       message VARCHAR(255) NOT NULL,
+       modified_by VARCHAR(20) NOT NULL DEFAULT 'nobody',
+       modified_time INT NOT NULL DEFAULT '0',
+       PRIMARY KEY (nick, channel)
 );
+
+-- v.2 -> v.3
+-- ALTER TABLE onjoin ADD COLUMN modified_by VARCHAR(20) NOT NULL DEFAULT 'nobody';
+-- ALTER TABLE onjoin ADD COLUMN modified_time INT NOT NULL DEFAULT '0';
+-- ** the following doesn't work for sqlite **
+-- ALTER TABLE onjoin ADD PRIMARY KEY (nick, channel);
index 60ca2d0a1f2a3b37f0451f48c7366cff7257402e..3de2a552529158abf9e9a55771a0e283c7852338 100644 (file)
@@ -1,9 +1,10 @@
+#!/usr/bin/perl
 #
 # OnJoin.pl: emit a message when a user enters the channel
 #    Author: Corey Edwards <tensai@zmonkey.org>
-#   Version: v0.2.2
+#   Version: v0.3.0
 #   Created: 20051222
-#   Updated: 20060105
+#   Updated: 20060109
 
 use strict;
 
@@ -24,7 +25,7 @@ sub onjoin {
 
        # print the message, if there was one
        if ($message){
-               $message = substVars($message);
+               $message = substVars($message, 1);
                if ($message =~ m/^<action>\s*(.*)/){
                        &status("OnJoin: $nick arrived, performing action");
                        &action($chan, $1);
@@ -83,9 +84,9 @@ sub Cmdonjoin {
        # if msg not set, show what the message would be
        if (!$msg){
                $nick = $who if (!$nick);
-               $msg = &sqlSelect('onjoin', 'message', { nick => $nick, channel => $ch } ) || '';
-               if ($msg){
-                       &performReply($msg);
+               my %row = &sqlSelectRowHash('onjoin', 'message, modified_by, modified_time', { nick => $nick, channel => $ch } );
+               if ($row{'message'}){
+                       &msg($chan, "onjoin for $nick set by $row{modified_by} on " . localtime($row{modified_time}) . ": $row{message}");
                }
                return;
        }
@@ -108,8 +109,13 @@ sub Cmdonjoin {
 
        # remove old one (if exists) and add new message
        &sqlDelete('onjoin', { nick => $nick, channel => $ch });
-       &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg });
-       &performReply("ok");
+       my $insert = &sqlInsert('onjoin', { nick => $nick, channel => $ch, message => $msg, modified_by => $who, modified_time => time() });
+       if ($insert){
+               &performReply("ok");
+       }
+       else{
+               &performReply('whoops. database error');
+       }
        return;
 }