From 5f976ac30700b63a2cc55d43a2ae078ab9abfda0 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@gmail.com>
Date: Sun, 11 Aug 2013 14:38:18 +0200
Subject: [PATCH] Commands correction, now everything should work

---
 PlayBot.pl             |  6 +++---
 lib/commands/fav.pm    |  1 +
 lib/commands/parser.pm | 12 +++++++-----
 lib/commands/tag.pm    |  4 ++--
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/PlayBot.pl b/PlayBot.pl
index 13d5b70..4cf05bc 100755
--- a/PlayBot.pl
+++ b/PlayBot.pl
@@ -59,8 +59,6 @@ my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $co
 	})
 	or die("Couldn't connect to database: ".DBI->errstr);
 
-$commands::parser::setConf($irc, $dbh);
-
 # Evenements que le bot va gérer
 POE::Session->create(
 	inline_states => {
@@ -128,7 +126,7 @@ sub cycle
 
     Module::Refresh->refresh;
 
-    $commands::parser::setConf($irc, $dbh);
+    commands::parser::setConf($irc, $dbh, $log);
     $commands::parser::lastID = $lastID;
 }
 
@@ -306,6 +304,8 @@ sub on_speak
 }
 
 
+commands::parser::setConf($irc, $dbh, $log);
+
 # Boucle des events
 $poe_kernel->run();
 exit 0;
diff --git a/lib/commands/fav.pm b/lib/commands/fav.pm
index 278b425..67bbd91 100644
--- a/lib/commands/fav.pm
+++ b/lib/commands/fav.pm
@@ -5,6 +5,7 @@ our @ISA = qw(Exporter);
 our @EXPORT_OK = qw(exec);
 
 our $dbh;
+our $log;
 
 sub exec {
     my ($nick, $id) = @_;
diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm
index 3a2f3bb..11c3ef6 100644
--- a/lib/commands/parser.pm
+++ b/lib/commands/parser.pm
@@ -14,11 +14,14 @@ our $lastID;
 my $irc;
 
 sub setConf {
-    my ($ircNew, $dbh) = @_;
+    my ($ircNew, $dbh, $log) = @_;
 
     $commands::fav::dbh = $dbh;
     $commands::tag::dbh = $dbh;
 
+    $commands::fav::log = $log;
+    $commands::tag::log = $log;
+
     $irc = $ircNew;
 }
 
@@ -29,19 +32,18 @@ sub exec {
     if ($msg =~ /^!fav(?: ([0-9]+))?/) {
         $id = ($1) ? $1 : $lastID;
 
-        $commands::fav::dbh = $dbh;
         commands::fav::exec($nick, $id)
 	}
 	elsif ($msg =~ /^!later(?: ([0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) {
         my $id = ($1) ? $1 : $lastID;
         my ($time, $unit) = ($2, $3);
 
-        commands::later::exec($id, $time, $unit);
+        commands::later::exec($kernel, $nick, $id, $time, $unit);
 	}
     elsif ($msg =~ /^!tag(?: +([0-9]+))?/) {
         my $id = ($1) ? $1 : $lastID;
 
-        commands::tag($id, $msg);
+        commands::tag::exec($id, $msg);
     }
     elsif ($msg =~ /^!help/) {
 		$irc->yield(privmsg => $chan => '!fav [<id>] : enregistre la vidéo dans les favoris');
@@ -59,7 +61,7 @@ sub exec {
 sub tag {
     my ($msg) = @_;
 
-    commands::tag($lastID, $msg);
+    commands::tag::exec($lastID, $msg);
 }
 
 1;
diff --git a/lib/commands/tag.pm b/lib/commands/tag.pm
index c9ce28b..8d06b72 100644
--- a/lib/commands/tag.pm
+++ b/lib/commands/tag.pm
@@ -1,11 +1,11 @@
-package commands::later;
+package commands::tag;
 
 require Exporter;
 our @ISA = qw(Exporter);
 our @EXPORT_OK = qw(exec);
 
-our $kernel;
 our $dbh;
+our $log;
 
 sub exec {
     my ($id, $msg) = @_;
-- 
GitLab