diff --git a/Core/HTMLRequests.pm b/Core/HTTPRequests.pm similarity index 99% rename from Core/HTMLRequests.pm rename to Core/HTTPRequests.pm index 4d0417f571a11d44488699adf93fabe1cc5c2036..4e43542b5e9ba206473e705ab3f9867f53479ad6 100644 --- a/Core/HTMLRequests.pm +++ b/Core/HTTPRequests.pm @@ -1,4 +1,4 @@ -package HTMLRequests; +package HTTPRequests; # ============[ Demande de page web de manière asynchrone ]============ # diff --git a/Core/Hook.pm b/Core/Hook.pm index 64d53b4e2370f87c9c9d18b07f5c4aab3793f5d9..a52e73feed161992fc58465818c8167e98a49654 100644 --- a/Core/Hook.pm +++ b/Core/Hook.pm @@ -8,7 +8,7 @@ use Core::CommandProcess; use Core::Display; use Core::EventHandler; use Core::Fifo; -use Core::HTMLRequests; +use Core::HTTPRequests; use Net::IRC; use Core::Save; use Core::VarLoader; @@ -19,7 +19,7 @@ use Core::VarLoader; # On garde le nom du programme dans un coin our $nom_prog = $0; -# Quelques mises en forme pour la beaute de la console +# Quelques mises en forme pour la beaute de la console our $done = sprintf "[%c[32m Done%c[0m ]\n", 0x1B, 0x1B; our $error = sprintf "[%c[31m Error%c[0m ]\n", 0x1B, 0x1B; our $stars = sprintf "%c[31m****%c[0m", 0x1B, 0x1B; @@ -82,7 +82,7 @@ sub irc_connect 'SSL' => 1 ) or die $nom_prog.": Can't connect to IRC server.\n"; - + return $conn; } # Fin irc_connect @@ -97,41 +97,41 @@ sub on_connect { my ($conn, $event) = @_; $::logger->end_pending(1, $::logger->INFO); - + $conn->{'connected'} = 1; - + if($Config::want_nick_register) { $::logger->info($identification_server); $conn->privmsg('nickserv', 'REGISTER ' . $Config::passwd); $conn->privmsg('nickserv', 'IDENTIFY ' . $Config::passwd); } - + $commandtool->schedule(5, \&join_channels); - + # Pour qu'on puisse avoir le commandtool dans les sous-classes facilement $conn->{"cmdtool"} = $commandtool; - # À la place de variables globales, qui peuvent poser problème pour le + # À la place de variables globales, qui peuvent poser problème pour le # reload (notamment), on peut mettre les variables ici $conn->{"vars"} = []; - + # On recharge les variables qu'on avait sauvegardées en s'éteignant la dernière fois $::logger->info($reload_func); $VarLoader::loader->load($conn); - + $::logger->info($init_saver); $Save::saver->init($conn); - + $::logger->info(sprintf "\t\t%c[4mYou can talk to me now%c[0m\n", 0x1B,0x1B); } # Fin on_connect -# Pour éviter de surcharger nos demandes au serveur, on join les chans un peu +# Pour éviter de surcharger nos demandes au serveur, on join les chans un peu # plus tard dans la connexion sub join_channels { my $conn = shift @_; - + unless(defined(&Join::join_main)) { my $warn = "Join module not found, won't be able to join any channel"; @@ -139,7 +139,7 @@ sub join_channels $::logger->warning($warn); return; } - + $::logger->info($connection_auto_channel); # On join quelques chans (ou un seul...) par défaut if($Config::channel !~ /,/) @@ -164,20 +164,20 @@ sub join_channels sub on_disconnect { my ($conn, $event) = @_; - + $conn->{'connected'} = 0; - + $Save::saver->save($conn); - + if(Disconnect::reconnect()) { # On relance le programme parce qu'on a été # deconnecté mais on veut se reconnecter $::logger->warning($program_reinit); - + my @args = Disconnect::args(); my $args = "perl $nom_prog ".join(" ", @args); - + # On échappe les caractères spéciaux $args =~ s/([\\;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g; my $pass = $Config::passwd; @@ -185,7 +185,7 @@ sub on_disconnect $args = "echo '".$pass."' | ".$args; exec $args; } - + # On se suicide... mouahahaha exit 0; } # Fin on_disconnect @@ -195,17 +195,17 @@ sub on_disconnect sub on_public { my ($conn, $event) = @_; - + $reply_to = $event->{'to'}[0]; my $text = $event->{'args'}[0]; - + my $cs = $Config::command_sign; if(substr($text, 0, length $cs) eq $cs) { # $text commence par $cs => il s'agit probablement d'une commande $::logger->debug("Typed text: '$text'"); # On prend le nom de la commande my $commande = ($text =~ m/^$cs([^ ]*)/)[0]; - + if($commande ne '' && ($Config::suffixe eq "" || substr($commande, - length($Config::suffixe)) eq $Config::suffixe) @@ -213,7 +213,7 @@ sub on_public { my @params = grep {!/^\s*$/} split(/\s+/, substr($text, length($cs) + length($commande))); - + $::logger->debug("Typed command: $commande"); if($Config::suffixe ne "") { @@ -225,23 +225,23 @@ sub on_public } $::logger->debug("Real command: $commande"); $::logger->debug("Parameters: '".join("' '", @params)."'"); - + $commandtool->process_command($commande, \@params, $conn, $event, $reply_to); } } - + } # Fin on_public sub on_private { my ($conn, $event) = @_; - + $event->{'to'}[0] = $event->{'nick'}; if($Config::debug && $event->{'nick'} ne $Config::owner) { $conn->privmsg($Config::owner, "There's ".$event->{'nick'}." who is telling me: ".$event->{'args'}[0]); } - + # On ajoute ${Config::command_sign} s'il n'est pas déjà présent my $text = $event->{'args'}[0]; my $cs = $Config::command_sign; @@ -249,7 +249,7 @@ sub on_private { $event->{'args'}[0] = $cs.$text; } - + # On reçoit une query mais on transmet comme si c'était un évènement public on_public($conn, $event); } # Fin on_private @@ -259,12 +259,12 @@ sub on_notice { my ($conn, $event) = @_; my $text = $event->{'args'}[0]; - + # On l'affiche en query à l'owner $conn->privmsg($Config::owner, "<NOTICE: " . $event->nick() . "> $text"); - + # Si on nous dit que le passwd NickServ n'est pas bon - if($event->nick =~ /NickServ/i + if($event->nick =~ /NickServ/i && $text =~ /Password incorrect/i) { Getpass::retrieve($conn, "Nickserv"); @@ -275,10 +275,10 @@ sub on_notice sub on_nick { my ($conn, $event) = @_; - + my $old_nick = $event->{'nick'}; my $new_nick = $event->{'args'}[0]; - + $::logger->debug("$old_nick -> $new_nick"); } # Fin on_nick @@ -286,7 +286,7 @@ sub on_nick sub on_nosuchnick { my ($conn, $event) = @_; - + if($Config::owner ne $event->{'args'}[1]) { $conn->privmsg($Config::owner, $event->{'args'}[1].": " @@ -298,7 +298,7 @@ sub on_nosuchnick sub on_kick { my ($conn, $event) = @_; - + # On regarde si c'est nous qui avons été kické if($event->{'to'}[0] eq $Config::nick) { @@ -318,7 +318,7 @@ sub on_kick $sentence .= "Reason: '".$event->{'args'}[1]."'"; } $conn->privmsg($Config::owner, $sentence); - + Chans::chan_del($channel); $::logger->info("Not on $channel anymore"); } @@ -326,11 +326,11 @@ sub on_kick { $conn->privmsg($Config::owner, "I received a kick event, but I was" ." apparently not on the chan. A dump of the event is displayed."); - + $event->dump; } } - + Chans::remove_user($event->{'args'}[0], $event->{'to'}[0]); } # Fin on_kick @@ -338,11 +338,11 @@ sub on_kick sub on_mode { my ($conn, $event) = @_; - + my $chan = $event->{'to'}[0]; my @modes = @{$event->{'args'}}; my $modes = join(' ', @modes); - + if($chan =~ /^#/) { $::logger->debug("Changing mode of $chan: '$modes'"); @@ -354,7 +354,7 @@ sub on_mode sub on_invite { my ($conn, $event) = @_; - + $conn->privmsg($Config::owner, $event->{'nick'}." is inviting me on ".$event->{'args'}[0]); } # Fin on_invite @@ -362,7 +362,7 @@ sub on_invite sub on_nicknameinuse { my ($conn, $event) = @_; - + $::logger->error($event->{'args'}[2]." ($Config::nick)"); # &irc_connect; exit 1; # FIXME ce serait cool de pouvoir changer de nick @@ -372,7 +372,7 @@ sub on_nicknameinuse sub on_cversion { my ($conn, $event) = @_; - + $conn->ctcp_reply($event->{"nick"}, 'VERSION ' . "ircPerlBot v $Config::version, http://arise.iiens.net"); } # Fin on_cversion @@ -380,7 +380,7 @@ sub on_cversion sub on_topic { my ($conn, $event) = @_; - + if($event->{'to'}[0] eq "") { Chans::change_topic($event->{'args'}[1], $event->{'args'}[2]); @@ -395,13 +395,13 @@ sub on_topic sub on_namreply { my ($conn, $event) = @_; - + if($event->{'format'} eq "server") { my $chan = $event->{'args'}[2]; my $users = $event->{'args'}[3]; my @users = split /\s+/, $users; - + my @owner = (); my @protected = (); my @op = (); @@ -435,7 +435,7 @@ sub on_namreply } $_; } @users; - + $::logger->debug("$chan:\n"); $::logger->debug("Users: '".join("', '", @users)."'\n"); $::logger->debug("Owner: '".join("', '", @owner)."'\n"); @@ -443,7 +443,7 @@ sub on_namreply $::logger->debug("Op: '".join("', '", @op)."'\n"); $::logger->debug("Halfop: '".join("', '", @halfop)."'\n"); $::logger->debug("Voice: '".join("', '", @voice)."'\n"); - + my $modes = '+'; $modes .= ("q" x ($#owner+1)); $modes .= ("a" x ($#protected+1)); @@ -455,16 +455,16 @@ sub on_namreply $modes .= ' '.join(' ', @op); $modes .= ' '.join(' ', @halfop); $modes .= ' '.join(' ', @voice); - + Chans::change_mode($chan, $modes); - + Chans::add_users($chan, @users); } else { use Data::Dumper; print Data::Dumper->Dump([$event], [qw(namreply_event)]); - + $conn->privmsg($Config::owner, "namreply received, see dump for more info"); } } # Fin on_namreply @@ -473,10 +473,10 @@ sub on_namreply sub on_join { my ($conn, $event) = @_; - + my $chan = $event->{'to'}[0]; my $nick = $event->{'nick'}; - + $::logger->debug("Adding $nick to $chan"); Chans::add_one_user($chan, $nick); } # Fin on_join @@ -485,10 +485,10 @@ sub on_join sub on_part { my ($conn, $event) = @_; - + my $chan = $event->{'to'}[0]; my $user = $event->{'nick'}; - + if($user eq $Config::nick) { Chans::chan_del($chan); @@ -503,7 +503,7 @@ sub on_part sub on_quit { my ($conn, $event) = @_; - + Chans::remove_quit_user($event->{'nick'}); } # Fin on_quit @@ -520,7 +520,7 @@ sub on_quit sub on_cannotsendtochan { my ($conn, $event) = @_; - + $@ = undef; eval { $conn->privmsg($Config::owner, "Cannotsendtochan event triggered."); @@ -537,7 +537,7 @@ sub on_cannotsendtochan sub on_toomanychannels { my ($conn, $event) = @_; - + # print "on_toomanychannels\n"; # print Data::Dumper->Dump([$event], [qw(event_toomanychannels)]); } # Fin on_toomanychannels @@ -546,7 +546,7 @@ sub on_toomanychannels sub on_inviteonlychan { my ($conn, $event) = @_; - + # print "on_inviteonlychan\n"; # print Data::Dumper->Dump([$event], [qw(event_inviteonlychan)]); } # Fin on_inviteonlychan @@ -555,7 +555,7 @@ sub on_inviteonlychan sub on_channelisfull { my ($conn, $event) = @_; - + # print "on_channelisfull\n"; # print Data::Dumper->Dump([$event], [qw(event_channelisfull)]); } # Fin on_channelisfull @@ -564,7 +564,7 @@ sub on_channelisfull sub on_bannedfromchannel { my ($conn, $event) = @_; - + # print "on_bannedfromchannel\n"; # print Data::Dumper->Dump([$event], [qw(event_bannedfromchannel)]); } # Fin on_bannedfromchannel @@ -573,7 +573,7 @@ sub on_bannedfromchannel sub on_whoreply { my ($conn, $event) = @_; - + # print "on_whoreply\n"; # print Data::Dumper->Dump([$event], [qw(event_whoreply)]); } # Fin on_whoreply @@ -582,7 +582,7 @@ sub on_whoreply sub on_endofwho { my ($conn, $event) = @_; - + # print "on_endofwho\n"; # print Data::Dumper->Dump([$event], [qw(event_endofwho)]); } # Fin on_endofwho @@ -591,7 +591,7 @@ sub on_endofwho sub on_whoisuser { my ($conn, $event) = @_; - + # print "on_whoisuser\n"; # print Data::Dumper->Dump([$event], [qw(event_whoisuser)]); } # Fin on_whoisuser diff --git a/Modules/Horoscope.pm b/Modules/Horoscope.pm index 5093e3ea32ade81e57181d1770461991ca3ee3cf..cba55c1eee42c55050381528b6280c5f3491a9af 100644 --- a/Modules/Horoscope.pm +++ b/Modules/Horoscope.pm @@ -32,36 +32,36 @@ my %signes = ( # ### # horoscope_main # Donne l'horoscope -# +# # Usage : # !horoscope <sign> # ### sub horoscope_main { my ($conn, $event, $reply_to, $ref_params) = @_; - + return 0 unless(defined($ref_params->[0])); - + my $sign = lc $ref_params->[0]; return 0 if(!defined($signes{$sign})); - + my $sign_num = $signes{$sign}; - - my $htmlreq = new HTMLRequests($conn); - + + my $httpreq = new HTTPRequests($conn); + my $method = "GET"; my $raw_result = 0; my $callback = \&send_result; - + my %params = ( "event" => $event, "reply_to" => $reply_to, "sign num" => $sign_num, "sign" => $sign, ); - - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); - + + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); + return 1; } # Fin hororscope_main @@ -70,7 +70,7 @@ sub send_result { my ($conn, $status, $buffer, $params) = @_; $::logger->debug("Horoscope result received\n"); - + if($status != -1) { $::logger->debug("Status ok\n"); @@ -81,32 +81,32 @@ sub send_result next if(!($tag_id = $tag->get_attr("class")) || $tag_id ne "content-signes"); last; } - + for(my $i = 0; $i <= $signes{$params->{'sign'}}; $i++) { # Pour le tag d'ouverture (<div>) et celui de fermeture (</div>) $parser->get_tag('div'); } - + # Début de l'horoscope $parser->get_tag("p"); - + my $horos = $parser->get_text(); $horos =~ s/\n//g; $horos =~ s/^\s*(.*?)\s*$/$1/; - + # Suite de l'horoscope à cette url... $tag = $parser->get_tag("a"); my $next = $url . $tag->get_attr("href"); - - + + my $sign = ucfirst $params->{"sign"}; - + $conn->privmsg($params->{"reply_to"}, "\x034[\x033$sign\x034]\x03 $horos ($next)"); - + return 1; } - + $::logger->debug("Status not ok\n'''"); $::logger->debug($buffer); $::logger->debug("'''\n"); @@ -121,7 +121,7 @@ sub send_result sub hororscope_help { my ($conn, $event, $reply_to, $ref_params) = @_; - + $conn->privmsg($reply_to, "`".$Config::command_sign."hororscope <sign>` => will display the <sign>'s horoscope"); } # Fin hororscope_help diff --git a/Modules/HostIsDown.pm b/Modules/HostIsDown.pm index 27ad17d30cc1c03e8601199d1d3bda564f4e1577..7eb56d2d3df7c87948df55752ae193a8c2edba54 100644 --- a/Modules/HostIsDown.pm +++ b/Modules/HostIsDown.pm @@ -6,37 +6,37 @@ use HTML::TokeParser::Simple; # ### # hostisdown_main -# Traduit -# +# Traduit +# # Usage : # !hostisdown <host> # ### sub hostisdown_main { my ($conn, $event, $reply_to, $ref_params) = @_; - + return 0 unless(defined($ref_params->[0])); - - my $htmlreq = new HTMLRequests($conn); + + my $httpreq = new HTTPRequests($conn); my $to_check = $ref_params->[0]; if($to_check =~ m#^(?:ht|s?f)tps?://(.*)$#) { $to_check = $1; } - + my $url = "http://www.downforeveryoneorjustme.com/$to_check"; my $method = "GET"; my $raw_result = 0; my $callback = \&send_result; - + my %params = ( "event" => $event, "reply_to" => $reply_to, "host" => $ref_params->[0], ); - - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); - + + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); + return 1; } # Fin hostisdown_main @@ -45,7 +45,7 @@ sub send_result { my ($conn, $status, $buffer, $params) = @_; $::logger->debug("HostIsDown result received\n"); - + if($status != -1) { $::logger->debug("Status ok\n"); @@ -54,16 +54,16 @@ sub send_result while($tag = $parser->get_tag("div")) { next if(!($tag_id = $tag->get_attr("id")) || $tag_id ne "container"); - + my $answer = $parser->get_text(); $answer =~ s/^\s*(.*?)\s*$/$1/; - + my $host = $params->{"host"}; $host = $host =~ m#^(?:ht|s?f)tps?://#i ? $host : "http://".$host; - + $::logger->debug("Host: '$host'"); $::logger->debug("Answer: '$answer'"); - + if($answer =~ /It's just you/i) { $conn->privmsg($params->{"reply_to"}, "$answer $host is up."); @@ -77,11 +77,11 @@ sub send_result { $conn->privmsg($params->{"reply_to"}, $answer); } - + return 1; } } - + $::logger->debug("Status not ok\n'''"); $::logger->debug($buffer); $::logger->debug("'''\n"); @@ -96,7 +96,7 @@ sub send_result sub hostisdown_help { my ($conn, $event, $reply_to, $ref_params) = @_; - + $conn->privmsg($reply_to, "`".$Config::command_sign."hostisdown <host>` => will check if <host> is down just for you or not"); } # Fin hostisdown_help diff --git a/Modules/Meteo.pm b/Modules/Meteo.pm index 14c036ddd83a8f6522546a25ad9d695804cc84e1..6790cdfa548966342f84c1a0cf26573b54b15d2e 100644 --- a/Modules/Meteo.pm +++ b/Modules/Meteo.pm @@ -34,7 +34,7 @@ sub meteo_main # TODO Faire directement les 4 ou 5 requêtes vers des villes aux 4 ou 5 coins de la France return 0 unless(defined($ref_params->[0])); - my $htmlreq = new HTMLRequests($conn); + my $httpreq = new HTTPRequests($conn); my $url = "http://www.lameteogratuite.com/meteo/previsions-meteo-gratuite-".$ref_params->[0]."-france.html"; my $method = "GET"; @@ -48,7 +48,7 @@ sub meteo_main "ville" => $ref_params->[0], ); - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); return 1; } diff --git a/Modules/Rss.pm b/Modules/Rss.pm index b5d9b56139e07faf3c657cbccedba82beed47093..39b5d82e254bb008cd236fe69f638c82492a2b47 100644 --- a/Modules/Rss.pm +++ b/Modules/Rss.pm @@ -773,7 +773,7 @@ sub check_stream my ($conn, $schedule, $id) = @_; # On créé la requête - my $htmlreq = new HTMLRequests($conn); + my $httpreq = new HTTPRequests($conn); my $url = $schedule->{"url"}; my $method = "GET"; @@ -787,7 +787,7 @@ sub check_stream # Et on lance la requête $::logger->info("Running RSS check for url '$url'"); - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); return 1; } # Fin check_stream @@ -879,7 +879,7 @@ sub get_stream my ($conn, $schedule, $id) = @_; # On créé la requête - my $htmlreq = new HTMLRequests($conn); + my $httpreq = new HTTPRequests($conn); my $url = $schedule->{"url"}; my $method = "GET"; @@ -892,7 +892,7 @@ sub get_stream ); # Et on lance la requête - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); return 1; } # Fin get_stream diff --git a/Modules/SMS.pm b/Modules/SMS.pm index bf9ba9bd2c073737de4b67e7f55277cdb993fcc6..3a88e3b2bab8a7a55cc87e7820bf87407d0a5a97 100644 --- a/Modules/SMS.pm +++ b/Modules/SMS.pm @@ -146,7 +146,7 @@ sub try_send my $pass = $self->{'_registered'}->{$to}->{'pass'}; my $escm = uri_escape(Common::strip_colors($msg)); - my $htmlreq = new HTMLRequests($self->{'_conn'}); + my $httpreq = new HTTPRequests($self->{'_conn'}); my $url = "https://smsapi.free-mobile.fr/sendmsg?user=$user&pass=$pass&msg=$escm"; my $method = "GET"; @@ -160,7 +160,7 @@ sub try_send 'url' => $url ); - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); } diff --git a/Modules/Television.pm b/Modules/Television.pm index 15da4f208f2999a4d447ca2627de0d22957895b3..9e806827916595ecfcc3e805b41e1af6513af5bf 100644 --- a/Modules/Television.pm +++ b/Modules/Television.pm @@ -51,33 +51,33 @@ my @chaines = qw( # ### # tv_main -# Traduit -# +# Traduit +# # Usage : # !tv <channel> # ### sub tv_main { my ($conn, $event, $reply_to, $ref_params) = @_; - + my $channel = undef; $channel = &get_channel($ref_params->[0]) if(defined($ref_params->[0])); - - my $htmlreq = new HTMLRequests($conn); - + + my $httpreq = new HTTPRequests($conn); + my $method = "GET"; my $raw_result = 0; my $callback = \&send_result; - - + + my %params = ( "event" => $event, "reply_to" => $reply_to, "channel" => $channel, ); - - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); - + + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); + return 1; } # Fin tv_main @@ -96,7 +96,7 @@ sub hdump { push(@array, ' ') while $len++ < 16; $format="0x%08x (%05d)" . " %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s %s\n"; - } + } $data =~ tr/\0-\37\177-\377/./; printf $format,$offset,$offset,@array,$data; $offset += 16; @@ -109,13 +109,13 @@ sub send_result { my ($conn, $status, $buffer, $params) = @_; $::logger->debug("Television result received\n"); - + if($status != -1) { $::logger->debug("Status ok\n"); - + my $answer = ""; - + # On se place au début de la liste my $parser = HTML::TokeParser::Simple->new("string" => $buffer); my ($tag, $tag_id); @@ -124,8 +124,8 @@ sub send_result next if(!($tag_id = $tag->get_attr('id')) || $tag_id ne 'prime-broadcasts'); last; } - - + + if(defined($params->{"channel"})) { for(my $i = 0; $i <= $table_chaines{$params->{'channel'}}; $i++) @@ -133,7 +133,7 @@ sub send_result # Pour le tag d'ouverture (<li>) et celui de fermeture (</li>) $parser->get_tag('li'); } - + # # On va chercher le nom du programme en cours de diffusion # @@ -142,18 +142,18 @@ sub send_result next if(!($tag_id = $tag->get_attr('class')) || $tag_id ne 'texte_titre'); last; } - + my $prog = $parser->get_text(); $prog =~ s/^\s*(.*?)\s*$/$1/; - + if(! $prog) { $parser->get_tag('a'); $prog = $parser->get_text(); } - + $prog =~ s/^\s*(.*?)\s*$/$1/; - + # Puis les horaires et le temps depuis lequel il a commencé while($tag = $parser->get_tag('span')) { @@ -161,31 +161,31 @@ sub send_result last; } $parser->get_tag('strong'); - + # ... premier horaire my $begin_hour = $parser->get_text(); $begin_hour =~ s/^\s*(.*?)\s*$/$1/; - + $parser->get_tag('em'); - + # ... temps écoulé my $depuis = $parser->get_text(); $depuis =~ s/^\s*(.*?)\s*$/$1/; - + while($tag = $parser->get_tag('strong')) { last if $tag->is_start_tag; } - + # ... deuxième horaire my $end_hour = $parser->get_text(); $end_hour =~ s/^\s*(.*?)\s*$/$1/; - - + + $answer = "\x034[\x033".$params->{"channel"}."\x034]\x03 $begin_hour-$end_hour $prog (\x0305depuis $depuis\x03)"; - - - + + + # # On va chercher le nom du prochain programme # @@ -196,16 +196,16 @@ sub send_result } $prog = $parser->get_text(); $prog =~ s/^\s*(.*?)\s*$/$1/; - + if(! $prog) { $parser->get_tag('a'); $prog = $parser->get_text(); } - + $prog =~ s/^\s*(.*?)\s*$/$1/; - - + + # Puis les horaires while($tag = $parser->get_tag('span')) { @@ -213,21 +213,21 @@ sub send_result last; } $parser->get_tag('strong'); - + # ... premier horaire $begin_hour = $parser->get_text(); $begin_hour =~ s/^\s*(.*?)\s*$/$1/; - + while($tag = $parser->get_tag('strong')) { last if $tag->is_start_tag; } - + # ... deuxième horaire $end_hour = $parser->get_text(); $end_hour =~ s/^\s*(.*?)\s*$/$1/; - - + + $answer .= " \x0307|\x03 $begin_hour-$end_hour $prog"; } else @@ -236,39 +236,39 @@ sub send_result for my $i (0 .. $#chaines) { $parser->get_tag('li'); - - + + while($tag = $parser->get_tag('span')) { next if(!($tag_id = $tag->get_attr('class')) || $tag_id ne 'texte_titre'); last; } - + my $prog = $parser->get_text(); $prog =~ s/^\s*(.*?)\s*$/$1/; - + if(! $prog) { $parser->get_tag('a'); $prog = $parser->get_text(); } - + $prog =~ s/^\s*(.*?)\s*$/$1/; - + $prog = "\x034[\x0303".$chaines[$i]."\x034]\x03 $prog"; push @progs, $prog; } - + $answer = join(" \x0307|\x03 ", @progs); } - - + + $::displayer->sendto($params->{"reply_to"}, $answer); $::logger->debug("Buffer sent ('$answer')\n"); - + return; } - + $::logger->debug("Status NOT ok\n'''"); $::logger->debug($buffer); $::logger->debug("'''\n"); @@ -283,14 +283,14 @@ sub send_result sub get_channel { my $param = shift; - + return $param if(defined($table_chaines{$param})); - + foreach my $key (keys %table_chaines) { return $key if($param =~ /^$key$/i); } - + return undef; } # Fin get_channel @@ -302,7 +302,7 @@ sub get_channel sub tv_help { my ($conn, $event, $reply_to, $ref_params) = @_; - + $conn->privmsg($reply_to, "`".$Config::command_sign.$ref_params->[0]." <channel>` => display informations on what you can watch on <channel>. Available channels are ".join(", ", keys %table_chaines)."."); } # Fin tv_help diff --git a/Modules/Translation.pm b/Modules/Translation.pm index 52b3d5526f46023070a5dd7275ed4d4ac5745e14..caf554e75b277282f1ea1833374609f22cf7297e 100644 --- a/Modules/Translation.pm +++ b/Modules/Translation.pm @@ -101,7 +101,7 @@ sub trad_main return 0 unless(defined($init_lang) && defined($end_lang)); - my $htmlreq = new HTMLRequests($conn); + my $httpreq = new HTTPRequests($conn); # Échappement des caractères spéciaux $to_translate = uri_escape($to_translate); @@ -121,7 +121,7 @@ sub trad_main "end" => $end_lang ); - $htmlreq->wget($url, $method, \%req_params, $raw_result, $callback, \%params); + $httpreq->wget($url, $method, \%req_params, $raw_result, $callback, \%params); return 1; } # Fin trad_main diff --git a/Modules/UrbanDictionary.pm b/Modules/UrbanDictionary.pm index 0104e9aa590f3501235df8d03edf073efae1bae8..a684ec883fa2f78b7e2e1dee127a64356324e443 100644 --- a/Modules/UrbanDictionary.pm +++ b/Modules/UrbanDictionary.pm @@ -10,24 +10,24 @@ use URI::Escape; # ### # ud_main # Retrouve la définition de mots sur UrbanDicitonary -# +# # Usage : # !ud <text> # ### sub ud_main { my ($conn, $event, $reply_to, $ref_params) = @_; - + return 0 unless(defined($ref_params->[0])); - - my $htmlreq = new HTMLRequests($conn); + + my $httpreq = new HTTPRequests($conn); my $search = uri_escape(join(' ', @{$ref_params})); - + my $url = "http://www.urbandictionary.com/define.php?term=".$search; my $method = "GET"; my $raw_result = 0; my $callback = \&send_result; - + my %params = ( "event" => $event, "reply_to" => $reply_to, @@ -35,11 +35,11 @@ sub ud_main "url" => $url, "search" => $search, ); - - $htmlreq->wget($url, $method, undef, $raw_result, $callback, \%params); - - - + + $httpreq->wget($url, $method, undef, $raw_result, $callback, \%params); + + + return 1; } @@ -53,10 +53,10 @@ sub send_result if($status != -1) { $::logger->debug("Status ok\n"); - + my $msg = $params->{"url"}; my $not_exist = undef; - + my $parser = HTML::TokeParser::Simple->new("string" => $buffer); my ($tag, $tag_id); while($tag = $parser->get_tag("div")) @@ -69,23 +69,23 @@ sub send_result last; } } - + last if($tag_id eq "paginator"); } - - + + if(defined($not_exist)) { my $not_found = uri_unescape($params->{"search"}); $msg = "\x02".$not_found."\x02 isn't defined yet. Add it here: http://www.urbandictionary.com/add.php?word=".$params->{"search"}; } - + $::displayer->sendto($params->{"reply_to"}, $msg); $::logger->debug("Sent ok"); - + return 1; } - + $::logger->debug("Status not ok\n'''"); $::logger->debug($buffer); $::logger->debug("'''\n"); @@ -101,9 +101,9 @@ sub send_result sub ud_help { my ($conn, $event, $reply_to, $ref_params) = @_; - + $conn->privmsg($reply_to, "`".$Config::command_sign.$ref_params->[0]." <text>` => retrieve definition of <text> on UrbanDictionary"); - + return 1; } # Fin meteo_help