Old stuff/Perl/xchat/test.pl
(Deskargatu)
#!/usr/bin/perl -w
use DBI;
my $bdd = DBI->connect("dbi:Pg:dbname=web;","tfe","") or die "error connecting";
#Xchat::register('highlight by tfqe','0.1','','');
#Xchat::hook_server(PRIVMSG,grabber);
#sub grabber($)
#{
$message = shift;
$action =${$message}[1];
$from =${$message}[0];
$channel = ${$message}[2];
$message = join(" ",@{$message}[3..$#$message]);
#
#FROM :tfe_!~tfe@EpiK-BD503C7.w83-193.abo.wanadoo.fr
#
$from = ":tfe_!~tfe\@EpiK-BD503C7.w83-193.abo.wanadoo.fr";
if ($from =~ /:([^\!]+)\!.*/) { $nick = $1; }
$action="PRIVMSG";
$message = " http://www.google.com/linux voila";
$channel ="#test";
$server ="irc.epiknet.org";
if ($message =~
/(
(?:\W|^)
((?:https?)|(?:ftp))
:\/\/
([a-z]+
\.
([a-z]+?
\.
[a-z]{3})
(?::(\d+))?
)
(
\/
[a-z\/\?\(\)0-9\.\-\_\%\=]+
)?
)
/ix
)
{
$url = $1 ? $1 : "";
$protocol = $2 ? $2 : "";
$fhost = $3 ? $3 : "";
$mhost = $4 ? $4 : "";
$port = $5 ? $5 : "";
print "$url \n $protocol\n$fhost\n$mhost\n$port\n$nick\n$channel";
# $1 = url
# $2 = protocol
# $3 = full host
# $4 = main host
# $5 = port
$sth = $bdd->prepare("SELECT * FROM url WHERE url='$url'");
$sth->execute();
print "OK";
$compteur=0;
while($row = $sth->fetchrow_hashref)
{
$compteur= 1;
#print ${$row}{'url'};
}
if ($compteur ==0)
{
$sth = $bdd->prepare("INSERT INTO url
(pseudo,channel,server,base,vhost,url,port)
VALUES
('$nick','$channel','$server','$mhost','$fhost','$url','$port')
") or die $bdd->errstr;
$sth->execute() or die $bdd->errstr;
}
print "FIn\n";
}
#Xchat::print("${$message}[0]\n${$message}[1]\n${$message}[2]");
$_ = $message;
#return $_;
#}