From 3aeed0afeb708bca83dc69b020dfe8a964b37c02 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@gmail.com>
Date: Sat, 16 Aug 2014 22:54:39 +0200
Subject: [PATCH] a !get stores the content in the history like a post

---
 lib/commands/get.pm    | 12 +++++++++++-
 lib/commands/parser.pm |  3 ++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/commands/get.pm b/lib/commands/get.pm
index 38ed533..e332728 100644
--- a/lib/commands/get.pm
+++ b/lib/commands/get.pm
@@ -10,9 +10,10 @@ use Scalar::Util qw(looks_like_number);
 
 our $dbh;
 our $irc;
+our $log;
 
 sub exec {
-	my ($kernel, $user, $chan, $msg) = @_;
+	my ($kernel, $nick, $chan, $msg) = @_;
 
     # if we are in a query or arg -all, we search in all the channels
     my $all = 0;
@@ -141,6 +142,15 @@ sub exec {
     	$irc->yield(privmsg => $chan => '['.$content->[0].'] '.$content->[2].' => '.$content->[3].' '.$tags) ;
     }
 
+    # we save the get like a post
+    my $sth2 = $dbh->prepare_cached('
+        INSERT INTO playbot_chan (content, chan, sender_irc)
+        VALUES (?,?,?)');
+    $log->error("Couldn't prepare querie; aborting") unless (defined $sth2);
+
+    $sth2->execute($content->[0], $chan->[0], $nick)
+        or $log->error("Couldn't finish transaction: " . $dbh->errstr);
+
     return $content->[0];
 }
 
diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm
index 17be634..c8b925c 100644
--- a/lib/commands/parser.pm
+++ b/lib/commands/parser.pm
@@ -25,6 +25,7 @@ sub setConf {
 
     $commands::fav::log = $log;
     $commands::tag::log = $log;
+    $commands::get::log = $log;
     $commands::later::log = $log;
 
     $commands::fav::irc = $ircNew;
@@ -64,7 +65,7 @@ sub exec {
     }
     elsif ($msg =~ /^( *!get)(?: +.*)?$/) {
         $msg = substr $msg, (length $1) + 1;
-        my @args = ($kernel, $user, $chan, $msg);
+        my @args = ($kernel, $nick, $chan, $msg);
         my $id = commands::get::exec(@args);
 
         if ($id) {
-- 
GitLab