Last active
August 29, 2015 14:02
-
-
Save banditkroot/69f0125d424b5bf31283 to your computer and use it in GitHub Desktop.
Xchat perl script who give Twitch's user information in irc with !whotwitch twitcherusername
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Xchat qw(:all); | |
use JSON qw(decode_json); | |
use Try::Tiny; | |
my $version = "0.21"; | |
my $channel = "#channel"; | |
my ($json, $decode, $user, $name, $type, $bio, $cree, $maj); | |
register('WhoTwitch', $version, '!whotwitch', \&unload); | |
prnt("\cC08WhoTwitch chargé !"); | |
hook_print($_, \&twitchmess) foreach ('Channel Message'); | |
sub twitchmess { | |
whotwitch("Channel Message", $_[0]); | |
return EAT_NONE; | |
} | |
sub whotwitch { | |
my ($type, $message) = @_; | |
my ($nick, $text, $modechar) = @{$message}; | |
my @words = split(/ /, $text); | |
if ($words[0] eq "!whotwitch") { | |
if ( get_info('channel') eq $channel && $words[1]) { | |
$user = $words[1]; | |
try { | |
$json = qx(curl -H 'Accept: application/vnd.twitchtv.v3+json' -X GET https://api.twitch.tv/kraken/users/$user); | |
$decode = decode_json($json); | |
if ($decode->{'name'}) { | |
$name = $decode->{'name'}; | |
$type = $decode->{'type'}; | |
$cree = substr($decode->{'created_at'},8,2) . "/" . substr($decode->{'created_at'},5,2) . "/" . substr($decode->{'created_at'},0,4) . " a " . substr($decode->{'created_at'},11,8); | |
$maj = substr($decode->{'updated_at'},8,2) . "/" . substr($decode->{'updated_at'},5,2) . "/" . substr($decode->{'updated_at'},0,4) . " a " . substr($decode->{'updated_at'},11,8); | |
set_context($channel); | |
if ($decode->{'bio'}) { | |
$bio = "| Bio : " . $decode->{'bio'}. " |"; | |
} | |
else { | |
$bio = "|"; | |
} | |
command("say Utilisateur : $name | Type : $type | Cree le : $cree | Derniere mise a jour : $maj $bio URL : http://twitch.tv/$user/profile/"); | |
} | |
else { | |
command("say Ah pas bon l\'utilisateur..."); | |
} | |
} | |
catch { | |
command("say Petit soucis du côté de Twitch, réessayez plus tard..."); | |
}; | |
} | |
return EAT_ALL; | |
} | |
return EAT_NONE; | |
} | |
#Déchargement de script | |
sub unload { | |
prnt("\cC08WhoTwitch déchargé."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment