From df73cf139299dfba23ebf75b407cce47f30a80ab Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@gmail.com>
Date: Sat, 27 Oct 2012 21:24:33 +0200
Subject: [PATCH] =?UTF-8?q?gestion=20des=20id=20des=20vid=C3=A9os=20d?=
 =?UTF-8?q?=C3=A9j=C3=A0=20envoy=C3=A9es?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 PlayBot.pl | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/PlayBot.pl b/PlayBot.pl
index b446e56..8d8e7b0 100755
--- a/PlayBot.pl
+++ b/PlayBot.pl
@@ -135,8 +135,9 @@ sub on_query
 {
 	my ($user,$msg) = @_[ARG0, ARG2];
 	my ($nick) = split (/!/,$user);
+	print $msg."\n";
 
-	if ($msg =~ m/^!/ && $user eq $admin) {
+	if ($msg =~ m/^!/ && $nick eq $admin) {
 		my $commande = ( $msg =~ m/^!([^ ]*)/ )[0]; 
 		my @params = grep {!/^\s*$/} split(/\s+/, substr($msg, length("!$commande")));
 
@@ -254,11 +255,24 @@ sub on_speak
 			or $log->error("Couldn't finish transaction: " . $dbh->errstr);
 	}
 
+	# sélection de l'id de la vidéo insérée
+	my $id = $dbh->{mysql_insert_id};
+	if (!$id) {
+		my $sth = $dbh->prepare_cached('SELECT id FROM playbot WHERE url = ?');
+		$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
+
+		$sth->execute($content{'url'})
+			or $log->error("Couldn't finish transaction: " . $dbh->errstr);
+
+		$id = $sth->fetch->[0];
+	}
+
+	# message sur irc
 	if (defined $content{'author'}) {
-		$irc->yield(privmsg => $chan => '['.$dbh->{mysql_insertid}.'] '.$content{'title'}.' | '.$content{'author'}) ;
+		$irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}.' | '.$content{'author'}) ;
 	}
 	else {
-		$irc->yield(privmsg => $chan => '['.$dbh->{mysql_insertid}.'] '.$content{'title'}) ;
+		$irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}) ;
 	}
 }
 
-- 
GitLab