summaryrefslogtreecommitdiff
path: root/lib/Multi/IRC.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-03-13 17:57:42 +0100
committerYorhel <git@yorhel.nl>2010-03-13 17:57:42 +0100
commit1321e3e3ba79008989c80f23dcc6abf71e3ea2b8 (patch)
treee5bffa5cbce1c1003a66255d1df441bf0ea71352 /lib/Multi/IRC.pm
parent70f8d89d509a102e8af67d83b8b79b0c6f1b8317 (diff)
Multi::IRC: Changed !vn command to use the new search function
Diffstat (limited to 'lib/Multi/IRC.pm')
-rw-r--r--lib/Multi/IRC.pm31
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index f0a6fe6a..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 {
@@ -344,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', \@_);
}