Skip to content

Commit

Permalink
Correct !search function : Multi keywords search on IRC with !search …
Browse files Browse the repository at this point in the history
…is now possible
  • Loading branch information
aaaaadrien committed Oct 8, 2016
1 parent 3c5f5fa commit a0c3fe0
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion bot.pl
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,33 @@ sub said
my @params = grep {!/^\s*$/} split(/\s+/, substr($text, length("!$commande")));
if (defined($params[0]) && $params[0] ne '')
{
#print STDERR $params[0];
#print STDERR $params[1];


my $db_handle = DBI->connect("dbi:mysql:database=$db;host=$dbhost:$dbport;user=$dbuser;password=$dbpasswd");
my $sql = "SELECT * FROM links WHERE title LIKE '%$params[0]%' ORDER BY id";
#my $sql = "SELECT * FROM links WHERE title LIKE '%$params[0]%' ORDER BY id";
my $sql = "SELECT * FROM links WHERE ";
my $nbkeywords = $#params;
my $i=0;

if ( $nbkeywords > 0)
{
for ( $i; $i < $nbkeywords ; $i++ )
{
#print STDERR $i;
$sql = $sql."title LIKE \"%".$params[$i]."%\" AND ";
}
$sql = $sql."title LIKE \"%".$params[$i]."%\" ";
}
else
{
$sql = $sql."title LIKE \"%".$params[$i]."%\" ";
}
$sql = $sql."ORDER BY dateandtime DESC LIMIT 100";

#print STDERR $sql;

my $statement = $db_handle->prepare($sql);
$statement->execute();

Expand Down

0 comments on commit a0c3fe0

Please sign in to comment.