From: pleia2 Date: Mon, 18 Feb 2019 15:16:43 +0000 (+0100) Subject: [emaildb] version 1.1 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=dff18b3bb78552d190e3f627456690ad17237450;p=irssi-scripts.irssi.org.git [emaildb] version 1.1 --- diff --git a/scripts/emaildb1.0.pl b/scripts/emaildb.pl similarity index 77% rename from scripts/emaildb1.0.pl rename to scripts/emaildb.pl index bf661f2..16a76c0 100644 --- a/scripts/emaildb1.0.pl +++ b/scripts/emaildb.pl @@ -32,7 +32,7 @@ # R2D2 # Time # -# AND uncomment the 3 sections indicatated in the script +# AND uncomment the 2 sections indicatated in the script # # I never created an interface to add new nicknames, email, and birthday, # so you will need to manually insert this information into the database @@ -43,20 +43,20 @@ # results of any nicknames with a 't' i nthem) # # Personally, I run this in an ircbot, as the owner of this script cannot use -# the ~search command themselves +# the ~nick command themselves # # # ... That's about it, enjoy! # -use strict; + use Irssi; use DBI; use vars qw($VERSION %IRSSI); -$VERSION = "1.0"; +$VERSION = "1.1"; %IRSSI = ( - authors => 'PrincessLeia2', + author => 'PrincessLeia2', contact => 'lyz\@princessleia.com ', name => 'emaildb', description => 'a script for accessing an email mysql database through irc', @@ -66,39 +66,36 @@ $VERSION = "1.0"; # uncomment the following commented (and replace '/home/user' with your home directory) lines for user restricted access. -# -# open ( LIST, " ); -# close LIST; -my $d = ('database'); -my $u = ('user'); -my $p = ('password'); + open ( LIST, " ); + close LIST; + +$d = ('database'); +$u = ('user'); +$p = ('password'); sub event_privmsg { my ($server, $data, $nick, $mask, $target) =@_; my ($target, $text) = $data =~ /^(\S*)\s:(.*)/; if ($text =~ /^~search */i ) { - -# Uncomment the following commented lines for user restricted access -# foreach $person (@user) { -# if ($nick =~ /^$person$/i) { - + foreach $person (@user) { + if ($nick =~ /^$person$/i) { my ($nickname) = $text =~ /^~search (.*)/; - my $dbh = DBI->connect("DBI:mysql:$d","$u","$p") + $dbh = DBI->connect("DBI:mysql:$d","$u","$p") or die "Couldn't connect to database: " . DBI->errstr; - my $sth = $dbh->prepare("SELECT * FROM 13th where nickname like \"\%$nickname\%\";") - or die "Cant prepare statement: $dbh->errstr\n"; - my $rv = $sth->execute + $sth = $dbh->prepare("SELECT * FROM 13th where nickname like \"\%$nickname\%\";") + or die "Cant prepare $statement: $dbh->errstr\n"; + $rv = $sth->execute or die "cant execute the query: $sth->errstr\n"; if ($rv >= 1) { my @row; while ( @row = $sth->fetchrow_array( ) ) { - my $n = "$row[0]\n"; - my $e = "$row[1]\n"; - my $b = "$row[2]\n"; + $n = "$row[0]\n"; + $e = "$row[1]\n"; + $b = "$row[2]\n"; $server->command ( "msg $nick Nickname : $n" ); $server->command ( "msg $nick Email : $e" ); $server->command ( "msg $nick Birthday : $b" ); @@ -108,11 +105,8 @@ else { $server->command ( "msg $nick Sorry, No Results Match Your Query\n" ); } -# Uncomment the following commented lines for user restricted access -#} -#} - } } - +} +} Irssi::signal_add('event privmsg', 'event_privmsg');