Skip to content

Instantly share code, notes, and snippets.

@LunNova
Created August 6, 2012 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LunNova/a6ddb538578c2871116d to your computer and use it in GitHub Desktop.
Save LunNova/a6ddb538578c2871116d to your computer and use it in GitHub Desktop.
sub getDataC{
my @ret =();
my @remSubs = @ponySubs;
my $json='';
my @cSubs;
while(@cSubs = splice(@remSubs,0,49)){
my $urll = 'http://www.reddit.com/r/'.join('+',@cSubs).'/comments.json?limit=20';
$json = $ua->get($urll."&r=".int(rand(1000))) or return @ret;
$json = $json->content;
eval{$json = decode_json($json); @ret = (@ret,@{$json->{'data'}{'children'}});} or do{print "JSON parse failed.\n";};
}
return reverse(@ret);
}
my @s = getDataC() or return(print "failed getDataC()\n");
foreach my $s(@s){
my $s = $s->{data};
my ($comment,$subreddit,$author,$id,$lid) = @{$s}{'body','subreddit','author','id','link_id'};
$lid =~ s/t3_//;
chomp $comment;
$author =~ s/nallar/nal‍lar/;
my $msg = "\x0304\x02$subreddit\x03\x02: $comment - \x0312by \x02$author\x02 \x0311 at http://reddit.com/comments/$lid/_/$id";
$msg =~ s/\r\n/\n/g;
$msg =~ s/\n+/\n/g;
$msg = decode_entities($msg);
my @msg = split /(?:\n)/, $msg;
my $isAlert = 0;
my $tMsg = decode_entities($comment);
if($author ne "nal‍lar"){
foreach my $alStr(@remAlerts){
$tMsg =~ s/$alStr//;
}
foreach my $alStr(@alerts){
if($tMsg =~ /$alStr/i){
$isAlert=1;
last;
}
}
}
my $lCount = 0;
if((!exists($cdone{$id}))){
if(!$init){
#print "$msg\n";
foreach my $msgPart(@msg){
sendPriv(CCHANNEL, $msgPart);
if($isAlert){
sendPriv('nallar', $msgPart);
}
if($lCount > 1){
$cdone{$id."_".$lCount}=time();
}
$lCount++;
}
}
}
$cdone{$id}=time();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment