From 5e81427c6e2c34b912feccd803c73de847a9e93c Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 5 Aug 2009 12:33:29 +0200 Subject: Multi::IRC: Added !quote command to reply with a random quote from the DB --- lib/Multi/IRC.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/Multi/IRC.pm') diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm index 88de3dad..92f887ea 100644 --- a/lib/Multi/IRC.pm +++ b/lib/Multi/IRC.pm @@ -49,7 +49,7 @@ sub spawn { package_states => [ $p => [qw| _start shutdown irc_001 irc_public irc_ctcp_action irc_msg command reply - cmd_info cmd_list cmd_uptime cmd_vn cmd_vn_results cmd_say cmd_me + cmd_info cmd_list cmd_uptime cmd_vn cmd_vn_results cmd_quote cmd_quote_result cmd_say cmd_me cmd_eval cmd_die cmd_post vndbid formatid |], ], @@ -68,7 +68,8 @@ sub spawn { list => 0, # 0: everyone, uptime => 0, # 1: only OPs in the first channel listed in @channels vn => 0, # 2: only users matching the mask in @masters - say => 1|8, # |8: has to be addressed to the bot (e.g. 'Multi: eval' instead of '!eval') + quote => 0, # |8: has to be addressed to the bot (e.g. 'Multi: eval' instead of '!eval') + say => 1|8, me => 1|8, eval => 2|8, die => 2|8, @@ -258,6 +259,16 @@ sub cmd_vn_results { # num, res, \@_ } +sub cmd_quote { + $_[KERNEL]->post(pg => query => q|SELECT quote FROM quotes ORDER BY random() LIMIT 1|, undef, 'cmd_quote_result', $_[DEST]); +} + + +sub cmd_quote_result { # 1, res, dest + $_[KERNEL]->yield(reply => $_[ARG2] => $_[ARG1][0]{quote}) if $_[ARG0] > 0; +} + + sub cmd_say { my $chan = $_[ARG] =~ s/^(#[a-zA-Z0-9-_.]+) // ? $1 : $_[DEST]; $irc->yield(privmsg => $chan, $_[ARG]); -- cgit v1.2.3