From: dms Date: Sun, 1 Apr 2001 15:25:18 +0000 (+0000) Subject: forgot to add this file, heh. X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ceb1fb7ec0a1715b2c2d77483b9c4f78b50b6d89;p=infobot.git forgot to add this file, heh. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@426 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/src/Modules/News.pl b/src/Modules/News.pl new file mode 100644 index 0000000..c21799a --- /dev/null +++ b/src/Modules/News.pl @@ -0,0 +1,672 @@ +# +# News.pl: Advanced news management +# Author: dms +# Version: v0.2 (20010326) +# Created: 20010326 +# Notes: Testing done by greycat, kudos! +# +### structure: +# news{ channel }{ string } { items } +# newsuser{ channel }{ user } = time() +### where items is: +# Time - when it was added (used for sorting) +# Author - Who by. +# Expire - Time to expire +# Text - Actual text. +### + +package News; + +sub Parse { + my($what) = @_; + $chan = undef; + + if ($::msgType eq "private") { + # todo: check if the channel exists aswell. + if (defined $what and $what =~ s/^($::mask{chan})\s*//) { + $chan = $1; + } + } else { + $chan = $::chan; + } + + if (!defined $chan) { + my @chans = &::GetNickInChans($::who); + + if (scalar @chans > 1) { + &::msg($::who, "error: I dunno which channel you are referring to since you're on more than one."); + return; + } + + if (scalar @chans == 0) { + &::msg($::who, "error: I couldn't find you on any chan. This must be a bug!"); + return; + } + + $chan = $chans[0]; + &::DEBUG("Guessed $::who being on chan $chan"); + } + + if (!defined $what or $what =~ /^\s*$/) { + &list(); + return; + } + + if ($what =~ /^add(\s+(.*))?$/i) { + &add($2); + } elsif ($what =~ /^del(\s+(.*))?$/i) { + &del($2); + } elsif ($what =~ /^mod(\s+(.*))?$/i) { + &mod($2); + } elsif ($what =~ /^set(\s+(.*))?$/i) { + &set($2); + } elsif ($what =~ /^(\d)$/i) { + &::DEBUG("read shortcut called."); + &read($1); + } elsif ($what =~ /^read(\s+(.*))?$/i) { + &read($2); + } elsif ($what =~ /^list$/i) { + &::DEBUG("list longcut called."); + &list(); + } elsif ($what =~ /^(expire|text|desc)(\s+(.*))?$/i) { + # shortcut/link. + # nice hack. + my($arg1,$arg2) = split(/\s+/, $3, 2); + &set("$arg1 Text $arg2"); + } elsif ($what =~ /^help(\s+(.*))?$/i) { + &::help("news$1"); + } else { + &::DEBUG("could not parse '$what'."); + &::msg($::who, "unknown command: $what"); + } +} + +sub readNews { + my $file = "$::bot_base_dir/blootbot-news.txt"; + if (! -f $file) { + return; + } + + if (fileno NEWS) { + &::DEBUG("readNews: fileno exists, should never happen."); + return; + } + + my($item,$chan); + my($ci,$cu) = (0,0); + + open(NEWS, $file); + while () { + chop; + + # todo: allow commands. + + if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) { + if (!defined $item) { + &::DEBUG("!defined item, never happen!"); + next; + } + $::news{$chan}{$item}{$1} = $2; + next; + } + + # U