From d8ebb3b420ba4541df65dd04ce0a03e4cc1ed425 Mon Sep 17 00:00:00 2001 From: timriker Date: Tue, 10 Jan 2006 17:59:18 +0000 Subject: [PATCH] keep track of who/when modified onjoin git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1263 c11ca15a-4712-0410-83d8-924469b57eb5 --- blootbot/setup/onjoin.sql | 11 ++++++++++- blootbot/src/Modules/OnJoin.pl | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/blootbot/setup/onjoin.sql b/blootbot/setup/onjoin.sql index 001924e..994cc54 100644 --- a/blootbot/setup/onjoin.sql +++ b/blootbot/setup/onjoin.sql @@ -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); diff --git a/blootbot/src/Modules/OnJoin.pl b/blootbot/src/Modules/OnJoin.pl index 60ca2d0..3de2a55 100644 --- a/blootbot/src/Modules/OnJoin.pl +++ b/blootbot/src/Modules/OnJoin.pl @@ -1,9 +1,10 @@ +#!/usr/bin/perl # # OnJoin.pl: emit a message when a user enters the channel # Author: Corey Edwards -# 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/^\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; } -- 2.39.2