From 3391f9aa1fabdf1bad7c01e221dd28f95b35e4e7 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Sat, 30 May 2015 01:04:30 +0200
Subject: [PATCH] post an url and a command: ommand get executed after url
 processing

---
 lib/commands/parser.pm |  4 +++-
 lib/sessions/irc.pm    | 16 +++++++++++-----
 lib/sites/parser.pm    | 10 ++++++++--
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm
index ee09f0f..6662b3c 100644
--- a/lib/commands/parser.pm
+++ b/lib/commands/parser.pm
@@ -134,10 +134,12 @@ sub exec {
 
 sub tag {
     my ($msg, $chan) = @_;
-    my @tags = ($msg =~ /(?:^| )#([a-zA-Z0-9_]+)/g);
+    my @tags = ($msg =~ /(?:^| )(#[a-zA-Z0-9_]+)/g);
 
     my $id = utils::id::get($chan);
     commands::tag::exec($id, "@tags");
+
+    return @tags;
 }
 
 1;
diff --git a/lib/sessions/irc.pm b/lib/sessions/irc.pm
index c55a586..6280339 100644
--- a/lib/sessions/irc.pm
+++ b/lib/sessions/irc.pm
@@ -257,11 +257,17 @@ sub on_speak
 	my ($nick,$mask) = split(/!/,$user);
 	my %content;
 
-    # first we test if it's a command
-    if (!commands::parser::exec(@args)) {
-        # if not, maybe there is an url we can parse
-	    sites::parser::parse(@args);
-    }	
+    # first we check for url
+    my @processed_str = sites::parser::parse(@args);
+
+    # we remove any part processed (url and tags)
+    foreach (@processed_str) {
+        $msg =~ s/\Q$_\E//;
+    }
+
+    # and we check for command
+    @args = ($kernel, $user, lc $chan->[0], $msg);
+    commands::parser::exec(@args);
 }
 
 1;
diff --git a/lib/sites/parser.pm b/lib/sites/parser.pm
index 022b2df..011913a 100644
--- a/lib/sites/parser.pm
+++ b/lib/sites/parser.pm
@@ -52,6 +52,9 @@ sub parse {
         $content{'url'} = 'https://www.dailymotion.com/video/' . $1;
     }
 
+    my $matching_url = $&;
+    my @matching_tags;
+
     # something goes wrong ?
     if ($@) {
         $log->warning ($@);
@@ -104,7 +107,7 @@ sub parse {
 
         $dbh->commit;
 
-        commands::parser::tag($msg, $chan);
+        @matching_tags = commands::parser::tag($msg, $chan);
 
         my @tags;
         # get tags
@@ -133,7 +136,10 @@ sub parse {
 		$irc->yield(privmsg => $chan => utils::print::print(\%content));
     }
 
-    return $id;
+    return (
+        $matching_url,
+        @matching_tags
+    );
 }
 
 1;
-- 
GitLab