From 8ba1bc26524a4edcf57be360446e7b5909b4eba8 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Thu, 14 May 2015 14:24:40 +0200
Subject: [PATCH] Fixes #19: no more "lc $chan->[0]" and other shit everywhere

---
 lib/commands/get.pm       |  9 ++++-----
 lib/commands/parser.pm    | 24 ++++++++++++------------
 lib/sessions/irc.pm       |  7 +++----
 lib/sessions/irc/later.pm |  2 +-
 lib/sites/parser.pm       |  2 +-
 5 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/lib/commands/get.pm b/lib/commands/get.pm
index 7733817..f1dba9e 100644
--- a/lib/commands/get.pm
+++ b/lib/commands/get.pm
@@ -15,10 +15,9 @@ our $log;
 
 sub exec {
 	my ($chan, $msg, $chan_src) = @_;
-    $chan->[0] = lc $chan->[0];
 
     my $query = commands::get::query->new(
-        chan => $chan->[0],
+        chan => $chan,
         query  => ($msg) ? $msg : ''
     );
 
@@ -86,8 +85,8 @@ sub exec {
     my $irc_msg = utils::print::print(\%content_h);
 
     # if in query
-    if ($chan->[0] !~ /^#/) {
-        $irc_msg .= ' [' . $chan_src->[0] . ']';
+    if ($chan !~ /^#/) {
+        $irc_msg .= ' [' . $chan_src . ']';
     }
     else {
         $irc_msg .= ' [' . $rows . ' résultat';
@@ -103,7 +102,7 @@ sub exec {
         VALUES (?,?,?)');
     $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
 
-    $sth->execute($content->[0], $chan->[0], "PlayBot")
+    $sth->execute($content->[0], $chan, "PlayBot")
         or $log->error("Couldn't finish transaction: " . $dbh->errstr);
 
     $dbh->commit();
diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm
index 0d3638c..f001e1f 100644
--- a/lib/commands/parser.pm
+++ b/lib/commands/parser.pm
@@ -45,17 +45,17 @@ sub exec {
 	my ($kernel, $user, $chan, $msg) = @_;
 	my ($nick, $mask) = split(/!/,$user);
 
-    if ($msg eq '!' and $command{lc $chan->[0]}) {
-        $msg = $command{lc $chan->[0]};
+    if ($msg eq '!' and $command{$chan}) {
+        $msg = $command{$chan};
     }
 
     if ($msg =~ /^ *!fav(?: (\S+))? *$/) {
         my $index = $1;
         try {
-            my $id = utils::id::get($chan->[0], $index);
+            my $id = utils::id::get($chan, $index);
             commands::fav::exec($nick, $id)
         } catch {
-            $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]);
+            $irc->yield(privmsg => $chan => $insultes[rand @insultes]);
         }
 	}
 	elsif ($msg =~ /^ *!later(?: (\S+))?(?: in (\d+)(h|m|s)?)? *$/) {
@@ -63,10 +63,10 @@ sub exec {
         my ($time, $unit) = ($2, $3);
 
         try {
-            my $id = utils::id::get($chan->[0], $index);
+            my $id = utils::id::get($chan, $index);
             commands::later::exec($kernel, $nick, $id, $chan, $time, $unit);
         } catch {
-            $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]);
+            $irc->yield(privmsg => $chan => $insultes[rand @insultes]);
         };
 	}
     elsif ($msg =~ /^( *!tag)(?:( +)(-?\d+))?/) {
@@ -82,10 +82,10 @@ sub exec {
         }
 
         try {
-            $id = utils::id::get($chan->[0], $index);
+            $id = utils::id::get($chan, $index);
             commands::tag::exec($id, $tags);
         } catch {
-            $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]);
+            $irc->yield(privmsg => $chan => $insultes[rand @insultes]);
         };
     }
     elsif ($msg =~ /^( *!get)(?: +.*)?$/) {
@@ -94,7 +94,7 @@ sub exec {
         my $id = commands::get::exec(@args);
 
         if ($id) {
-            $lastID->{$chan->[0]} = $id;
+            $lastID->{$chan} = $id;
         }
     }
     elsif ($msg =~ /^ *!help/) {
@@ -111,13 +111,13 @@ sub exec {
         $irc->yield(privmsg => $nick => 'Niveau vie privée, potentiellement toute commande (excepté !help) entraine un enregistrement dans la base de données avec au minimum la date et l\'heure et le nick de la personne ayant exécuté la commande.');
     }
     elsif ($msg =~/^ *!(fav|lat|tag)/) {
-        $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]);
+        $irc->yield(privmsg => $chan => $insultes[rand @insultes]);
     }
     else {
         return 0;
     }
 
-    $command{lc $chan->[0]} = $msg;
+    $command{$chan} = $msg;
     return 1;
 }
 
@@ -125,7 +125,7 @@ sub tag {
     my ($msg, $chan) = @_;
     my @tags = ($msg =~ /#([a-zA-Z0-9_-]+)/g);
 
-    my $id = utils::id::get($chan->[0]);
+    my $id = utils::id::get($chan);
     commands::tag::exec($id, "@tags");
 }
 
diff --git a/lib/sessions/irc.pm b/lib/sessions/irc.pm
index 92c227c..c55a586 100644
--- a/lib/sessions/irc.pm
+++ b/lib/sessions/irc.pm
@@ -170,10 +170,9 @@ sub on_query
 	my ($kernel, $user, $msg) = @_[KERNEL, ARG0, ARG2];
 	my ($nick) = split (/!/,$user);
 
-    my @fake_chan = ($nick);
-    my @args = ($kernel, $user, \@fake_chan, $msg);
+    my $fake_chan = $nick;
+    my @args = ($kernel, $user, $fake_chan, $msg);
 
-    my $fake_chan = \@fake_chan;
     return if (commands::parser::exec(@args));
 
 	if ($msg =~ m/^!/ && $nick eq $admin) {
@@ -253,7 +252,7 @@ sub on_invite
 sub on_speak
 {
 	my ($kernel, $user, $chan, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
-    my @args = ($kernel, $user, $chan, $msg);
+    my @args = ($kernel, $user, lc $chan->[0], $msg);
 
 	my ($nick,$mask) = split(/!/,$user);
 	my %content;
diff --git a/lib/sessions/irc/later.pm b/lib/sessions/irc/later.pm
index 577f748..4eb2800 100644
--- a/lib/sessions/irc/later.pm
+++ b/lib/sessions/irc/later.pm
@@ -7,7 +7,7 @@ sub consume
 {
 	my ($nick, $id, $chan_src) = @_;
 
-    my @args = ([$nick], $id, $chan_src);
+    my @args = ($nick, $id, $chan_src);
     commands::get::exec(@args);
 }
 
diff --git a/lib/sites/parser.pm b/lib/sites/parser.pm
index ff95bf8..022b2df 100644
--- a/lib/sites/parser.pm
+++ b/lib/sites/parser.pm
@@ -99,7 +99,7 @@ sub parse {
             VALUES (?,?,?)');
 		$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
 
-        $sth->execute($id, $chan->[0], $nick)
+        $sth->execute($id, $chan, $nick)
             or $log->error("Couldn't finish transaction: " . $dbh->errstr);
 
         $dbh->commit;
-- 
GitLab