summaryrefslogtreecommitdiff
path: root/lib/Multi/IRC.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Multi/IRC.pm')
-rw-r--r--lib/Multi/IRC.pm59
1 files changed, 42 insertions, 17 deletions
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index 0b19ed05..bce8f934 100644
--- a/lib/Multi/IRC.pm
+++ b/lib/Multi/IRC.pm
@@ -16,6 +16,7 @@ use POE qw|
use POE::Component::IRC::Common ':ALL';
use URI::Escape 'uri_escape_utf8';
use Time::HiRes 'time';
+use VNDBUtil 'normalize_query';
use constant {
@@ -53,7 +54,7 @@ sub spawn {
_start shutdown throttle_gc irc_001 irc_public irc_ctcp_action irc_msg
command idlequote reply notify_init notify notify_result
cmd_info cmd_list cmd_uptime cmd_vn cmd_vn_results cmd_p cmd_p_results cmd_quote cmd_quote_result
- cmd_say cmd_me cmd_notifications cmd_eval cmd_die cmd_post cmd_api vndbid formatid
+ cmd_scr cmd_scr_result cmd_say cmd_me cmd_notifications cmd_eval cmd_die cmd_post cmd_api vndbid formatid
|],
],
heap => {
@@ -73,6 +74,7 @@ sub spawn {
vn => 0, # 2: only users matching the mask in @masters
p => 0, # |8: has to be addressed to the bot (e.g. 'Multi: eval' instead of '!eval')
quote => 0,
+ scr => 0,
say => 1|8,
me => 1|8,
notifications => 1,
@@ -343,27 +345,25 @@ sub cmd_uptime {
sub cmd_vn {
- (my $q = $_[ARG]||'') =~ s/%//g;
+ my $q = $_[ARG];
return $_[KERNEL]->yield(reply => $_[DEST], 'You forgot the search query, dummy~~!', $_[USER]) if !$q;
return $_[KERNEL]->yield(reply => $_[DEST], 'Stop abusing me, it\'s not like I enjoy spamming this channel!', $_[USER])
if throttle $_[HEAP], "query-$_[USER]-$_[DEST][0]", 60, 3;
- $_[KERNEL]->post(pg => query => q|
+ my @q = normalize_query($q);
+ return $_[KERNEL]->yield(reply => $_[DEST],
+ "Couldn't do anything with that search query, you might want to add quotes or use longer words.",
+ $_[USER]) if !@q;
+
+ my $w = join ' AND ', map 'v.c_search LIKE ?', @q;
+ $_[KERNEL]->post(pg => query => qq{
SELECT 'v'::text AS type, v.id, vr.title
- FROM vn v
- JOIN vn_rev vr ON vr.id = v.latest
- WHERE v.hidden = FALSE AND (vr.title ILIKE $1
- OR vr.alias ILIKE $1
- OR v.id IN(
- SELECT rv.vid
- FROM releases r
- JOIN releases_rev rr ON rr.id = r.latest
- JOIN releases_vn rv ON rv.rid = rr.id
- WHERE rr.title ILIKE $1
- OR rr.original ILIKE $1
- ))
- ORDER BY vr.title
- LIMIT 6|, [ "%$q%" ], 'cmd_vn_results', \@_);
+ FROM vn v
+ JOIN vn_rev vr ON vr.id = v.latest
+ WHERE NOT v.hidden AND $w
+ ORDER BY vr.title
+ LIMIT 6
+ }, [ map "%$_%", @q ], 'cmd_vn_results', \@_);
}
@@ -413,6 +413,31 @@ sub cmd_quote_result { # 1, res, dest
}
+sub cmd_scr {
+ my $q = $_[ARG]||'';
+ $q = $1 if $q =~ /([0-9]+)\.jpg/;
+ return $_[KERNEL]->yield(reply => $_[DEST],
+ q|Sorry, I failed to comprehend which screenshot you'd like me to lookup for you,|
+ .q| please understand that Yorhel was not willing to supply me with mind reading capabilities.|,
+ $_[USER]) if !$q || $q !~ /^[0-9]+$/;
+ return $_[KERNEL]->yield(reply => $_[DEST], 'Stop abusing me, it\'s not like I enjoy spamming this channel!', $_[USER])
+ if throttle $_[HEAP], "query-$_[USER]-$_[DEST][0]", 60, 3;
+ $_[KERNEL]->post(pg => query => q|
+ SELECT 'v'::text AS type, v.id, vr.title
+ FROM vn v
+ JOIN vn_rev vr ON vr.id = v.latest
+ JOIN vn_rev vr2 ON vr2.vid = v.id
+ JOIN vn_screenshots vs ON vs.vid = vr2.id
+ WHERE vs.scr = ? LIMIT 1|, [ $q ], "cmd_scr_result", \@_);
+}
+
+
+sub cmd_scr_result {
+ return $_[KERNEL]->yield(reply => $_[ARG2][DEST], 'Couldn\'t find VN with that screenshot.', $_[ARG2][USER]) if $_[ARG0] < 1;
+ $_[KERNEL]->yield(formatid => $_[ARG0], $_[ARG1], [$_[ARG2][DEST]]);
+}
+
+
sub cmd_say {
my $chan = $_[ARG] =~ s/^(#[a-zA-Z0-9-_.]+) // ? $1 : $_[DEST];
$irc->yield(privmsg => $chan, $_[ARG]);