From 875eec19dc4fac3960bd45c817e3d3f2806490c7 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 18 Oct 2015 03:42:33 -0400 Subject: Added xdcc_autoget userscript --- scripts/xdcc_autoget.pl | 511 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 511 insertions(+) create mode 100644 scripts/xdcc_autoget.pl (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl new file mode 100644 index 0000000..960ed2e --- /dev/null +++ b/scripts/xdcc_autoget.pl @@ -0,0 +1,511 @@ +# xdcc autogetter, to automate searching and downloading xdcc packs based on chosen search strings +# requires that you enable dcc_autoget and dcc_autoresume. Also requires File::Dir which can be installed with the command >>> sudo perl -MCPAN -e 'install "File::HomeDir"' +# made because torrents are watched by the feds, but xdcc lacks RSS feeds. +# if you encounter any problems, fix it yourself you lazy bastard (or get me to), then contact me so I can add your fix and bump that version # +# BeerWare License. Use any part you want, but buy me a beer if you ever meet me and liked this hacked together broken PoS +# Somewhat based off of DCC multiget by Kaveh Moini. +# USE: for help : ag_help +# to run : ag_run +# to halt at next : ag_stop +# to set the server: ag_server +# to add a bot : ag_botadd BOT1 BOT2 *** BOTN +# to remove a bot : ag_botrem BOT1 BOT2 *** BOTN +# to add string : ag_add "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" +# to remove strings: ag_rem "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" +# ag_next_delay : delay between full transfers +# ag_dcc_closed_retry_delay : delay after premature transfer +# ag_bot_delay: delay between request and when you "SHOULD" get it +# ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another +# ag_autorun : whether to run on startup +# ag_xdcc_send_prefix : the xdcc message before the pack # +# ag_xdcc_find_prefix : the xdcc message before the search term +# ag_bot_file : where your bot list is stored +# ag_search_file : where your search list is stored + +use strict; + +use Irssi; +use Text::ParseWords; +use autodie; # die if problem reading or writing a file +use File::HomeDir; +use File::Copy; +use Irssi 20090331; +use vars qw($VERSION %IRSSI); + +$VERSION = 1.0; +%IRSSI = ( + name => "autoget", + description => "XDCC Autoget, for automated searching and downloading of xdcc packs", + license => "BeerWare Version 42", + changed => "$VERSION", + authors => "MarshalMeatball", + contact => "mobilegundamseed\@hotmail.com", +); + +my @totags = (); #timeout tags (need to be purged between send requests maybe) + +my $nexdelay = 5; #delay for next pack +my $dcrdelay = 10; #delay if transfer closed prematurely +my $botdelay = 30; #max time to wait for the bot to respond +my $exedelay = 15; #delay (in minutes) between finishing one run and starting another + +my $initflag = 1; #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD +my $msgflag = 1; #flag controls whether bot has responded to search request +my $pact = 0; #3 state flag to avoid recursive ag_reqpack calls + +my $sendprefix = "xdcc send"; #virtually universal xdcc send, cancel, and find prefixes +my $cancelprefix = "xdcc cancel"; +my $findprefix = "!find"; +my $botsfilename = File::HomeDir->my_home . "/.irssi/scripts/bots.txt"; #werks on my machine (tm). +my $searchesfilename = File::HomeDir->my_home . "/.irssi/scripts/searches.txt"; + +my $dccflag = 0; #flag so that dccs aren't mistakenly thought of belonging to AG + +my @terms; #lists of search terms, bots, and pack numbers (for current bot only) +my @bots; +my @packs; + +my $termcounter = 0; #counters for array position +my $botcounter = 0; +my $packcounter = 0; + +my $server; #current server + +sub ag_init #init system +{ + Irssi::print "AG | Autoget initiated"; + Irssi::print "AG | /ag_help for help"; + &ag_initserver; +} + +sub ag_initserver #init server +{ + $server = Irssi::active_server(); #keep trying to get server until it works, then continue after 5 seconds + if ($server !~ m/^Irssi::Irc::Server=HASH/) {Irssi::timeout_add_once(1000, sub {&ag_initserver;} , []);} + else {Irssi::timeout_add_once(5000, sub {&ag_run;} , []);} +} + +sub ag_help +{ + Irssi::print "for this help : ag_help"; + Irssi::print "to run : ag_run"; + Irssi::print "to halt at next : ag_stop"; + Irssi::print "to set the server: ag_server"; + Irssi::print "to add a bot : ag_botadd BOT1 BOT2 *** BOTN"; + Irssi::print "to remove a bot : ag_botrem BOT1 BOT2 *** BOTN"; + Irssi::print "to add string : ag_add \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; + Irssi::print "to remove strings: ag_rem \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; + Irssi::print "ag_next_delay : delay between full transfers"; + Irssi::print "ag_dcc_closed_retry_delay: delay after premature transfer"; + Irssi::print "ag_bot_delay : max time to wait for the bot to respond"; + Irssi::print "ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another"; + Irssi::print "ag_autorun : whether to run on startup"; + Irssi::print "ag_xdcc_send_prefix : the xdcc message before the pack #"; + Irssi::print "ag_xdcc_cancel_prefix : the xdcc message to cancel a transfer"; + Irssi::print "ag_xdcc_find_prefix : the xdcc message before the search term"; + Irssi::print "ag_bot_file : where your bot list is stored"; + Irssi::print "ag_search_file : where your search list is stored}"; +} + +sub ag_server #should only be run when you have a server, or it'll break (probably unfixable without a bunch of ugly dumb checks everywhere) +{ + $server = Irssi::active_server(); +} + +sub ag_getbots #reads in bot list +{ + open(bots, "<", $botsfilename); + @bots = ; + chomp(@bots); + close(bots); +} + +sub ag_getterms #reads in search term list +{ + open(searches, "<", $searchesfilename); + @terms = ; + chomp(@terms); + close(searches); +} + +sub ag_search #searches current bot for current term +{ + $msgflag = 0; + Irssi::signal_add("message irc notice", "ag_getmsg"); + $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter]"); + Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip } , []); #skip search if no results given +} + +sub ag_skip +{ + if ($msgflag == 0) + { + if ($#terms != $termcounter) + { + Irssi::print "AG | No packs found or Bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next search"; + Irssi::signal_remove("message irc notice", "ag_getmsg"); + $termcounter++; + &ag_search; + } + elsif ($#bots != $botcounter) + { + Irssi::print "AG | No packs found or Bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next bot"; + Irssi::signal_remove("message irc notice", "ag_getmsg"); + $termcounter = 0; + $botcounter++; + &ag_search; + } + else + { + Irssi::print "AG | No packs found or Bot " . $bots[$botcounter] . " unresponsive or nonexistent. End of list"; + Irssi::signal_remove("message irc notice", "ag_getmsg"); + $botcounter = 0; + $termcounter = 0; + Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; + Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + } + } +} + +sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this from sending useless shit that breaks things +{ + my $message = @_[1]; + my $botname = @_[2]; + $botname =~ tr/[A-Z]/[a-z]/; + $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; + if ($botname == $bots[$botcounter]) + { + $msgflag = 1; + &parseresponse($message); + } +} + +sub parseresponse #takes a single message and finds all instances of "#[XDCC NUMBER]:" since most bots reply to !find requests like that. If a bot uses another method and this doesn't work, fix it yourself and send me the code =D +{ + my($message) = @_; + my @temp = split(' ', $message); + foreach my $n (@temp){ if ($n =~ m{#(\d+):}) {push(@packs, $1);} } + @packs = ag_uniq(@packs); + if ($pact == 0 and $#packs >= 0 and $packs[$packcounter] ne "") #initiallizes the actual xdcc get system only once per search term/bot (pact should be >0 until the whole process is finished) + { + $pact = 1; + &ag_reqpack(); + } +} + +sub ag_uniq #only returns unique entries +{ + my %seen; + grep !$seen{$_}++, @_; +} + +sub ag_reqpack #sends the xdcc send request, and retries on failure +{ + if ($dccflag == 0){Irssi::signal_add("dcc get receive", "ag_opendcc");} #init DCC recieve init flag + $dccflag = 1; + $server->command("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { if ($pact < 2) { Irssi::print "AG | Connection failed"; Irssi::print "AG | retrying: " . $bots[$botcounter] . " " .$packs[$packcounter]; &ag_reqpack(); } } , [])); +} + +sub ag_opendcc #runs on DCC recieve init +{ + Irssi::signal_remove("dcc get receive", "ag_opendcc"); #stops any suplicate sends (there should only ever be one) + $dccflag = 0; + + my ($gdcc) = @_; #current pack + my $botname = $gdcc->{'nick'}; + $botname =~ tr/[A-Z]/[a-z]/; + $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; + if ($botname eq $bots[$botcounter]) #if it's our bot, let user know, and stop any further AG pack requests until finished + { + Irssi::print "AG | received connection for bot: " . $botname . ", #" . $packs[$packcounter]; + $pact = 2; + } + else #if not, allow this to rerun on next get + { + Irssi::signal_add("dcc get receive", "ag_opendcc"); + $dccflag = 1; + } +} + +sub ag_closedcc #deals with DCC closes +{ + my ($dcc) = @_; #current pack + my $botname = $dcc->{'nick'}; #get the bots name, and checks if it's the one we want + $botname =~ tr/[A-Z]/[a-z]/; + $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; + if ($botname eq $bots[$botcounter]) + { + if ($dccflag == 0) {Irssi::signal_add("dcc get receive", "ag_opendcc");} #if so, reinits DCC get signal for the next pack + $dccflag = 1; + Irssi::print "AG | pack " . $packs[$packcounter] . " size was: " . $dcc->{'size'} . " transferred: " . $dcc->{'transfd'} . " skipped: " . $dcc->{'skipped'}; #nerdy info on pack recieved + foreach my $to (@totags) #clears timeouts to defuckify everything + { + Irssi::timeout_remove($to); + } + @totags = (); + if ($dcc->{'transfd'} == $dcc->{'size'}) #checks if the transfer actually ran to completion + { + Irssi::print "AG | transfer successful"; #if so, does next pack/search/bot (in that order) + if ($dcc->{'skipped'} == $dcc->{'size'}) + { + $server->command("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. + } + if ($packcounter < $#packs) + { + $pact = 1; #allow pack requests now that transfer is finished + $packcounter += 1; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next pack in list"; &ag_reqpack(); }, [])); + Irssi::print "AG | waiting " . $nexdelay . " seconds"; + } + elsif ($termcounter < $#terms) + { + $pact = 0; #allow the system to parse new responses + @packs = (); #delete last terms packlist + $termcounter += 1; + $packcounter = 0; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Packlist finished. Searching next term"; &ag_search(); }, [])); + Irssi::print "AG | waiting " . $nexdelay . " seconds"; + } + elsif ($botcounter < $#bots) + { + $pact = 0; #allow the system to parse new responses + @packs = (); #delete last bots packlist + $botcounter += 1; + $termcounter = 0; + $packcounter = 0; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | All searches complete. Searching next bot"; &ag_search(); }, [])); + Irssi::print "AG | waiting " . $nexdelay . " seconds"; + } + else #if last pack on last search on last bot finished, then resets counters and starts over + { + $pact = 0; + @packs = (); #delete last bots packlist + $botcounter = 0; + $termcounter = 0; + $packcounter = 0; + Irssi::signal_remove("message irc notice", "ag_getmsg"); + Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; + Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + } + } + else #if not, retry transfer + { + Irssi::print "AG | transfer failed"; + Irssi::print "AG | " . $dcrdelay . " seconds until retry"; + push(@totags, Irssi::timeout_add_once($dcrdelay * 1000, sub { Irssi::print "AG | retrying: " .$bots[$botcounter] . " " . $packs[$packcounter]; &ag_reqpack(); }, [])); + } + } +} + +sub ag_parseadd #parses add arguments for storage +{ + my ($file, @args) = @_; + open(file, ">>", $file); + foreach my $arg (@args) + { + print file $arg . "\n"; #print to file + } + close(file); + copy($file, "/tmp/temp") or die "COPY FAILED"; #copy to temp file so that duplicate lines [searches/bots] can be removed + unlink "$file"; + open(temp, "<", "/tmp/temp"); + open(file, ">", $file); + my %hTmp; + while (my $sLine = ) #remove duplicate lines + { + next if $sLine =~ m/^\s*$/; #remove empty lines. Without this, still destroys empty lines except for the first one. + $sLine=~s/^\s+//; #strip leading/trailing whitespace + $sLine=~s/\s+$//; + print file qq{$sLine\n} unless ($hTmp{$sLine}++); + } + unlink "/tmp/temp"; + close(file); +} + +sub ag_parserem #parses remove arguments for deletion from file +{ + my ($file, @args) = @_; + open(temp, ">>", "/tmp/temp"); + foreach my $arg (@args) + { + Irssi::print "AG | removing term: " . $arg; + print temp $arg . "\n"; + } + close(temp); + open(temp2, ">", "/tmp/temp2"); + open(file, "<", $file); + my %hTmp; + while( my $fileLine = file->getline() ) #get each entry already stored + { + open(temp, "<", "/tmp/temp"); + while( my $tempLine = temp->getline() ) + { + if ($fileLine eq $tempLine) #if entry in file and arguments + { + $hTmp{$fileLine}++; #set flag to not copy + } + print temp2 qq{$fileLine} unless $hTmp{$fileLine}; #copy other lines to other temp file + } + close(temp); + } + close(temp2); + copy("/tmp/temp2", $file) or die "COPY FAILED"; #rewrite old file + copy($file, "/tmp/temp") or die "COPY FAILED"; + unlink "$file"; + open(temp, "<", "/tmp/temp"); + open(searches, ">", $file); + my %hTmp; + while (my $sLine = ) #remove duplicate lines + { + next if $sLine =~ m/^\s*$/; #remove empty lines. Without this, still destroys empty lines except for the first one. + $sLine=~s/^\s+//; #strip leading/trailing whitespace + $sLine=~s/\s+$//; + print file qq{$sLine\n} unless ($hTmp{$sLine}++); + } + unlink "/tmp/temp"; + unlink "/tmp/temp2"; + close(file); +} + +sub ag_add #add search terms +{ + &ag_server; + my @args = quotewords('\s+', 0, @_[0]); #split arguments (words in brackets not seperated) + if ($#args < 0) + { + Irssi::print "AG | too few arguments"; + Irssi::print "AG | usage: ag_add "; + return; + } + &ag_parseadd($searchesfilename, @args); +} + +sub ag_rem #remove ssearch terms +{ + &ag_server; + my @args = quotewords('\s+', 0, @_[0]); + if ($#args < 0) + { + Irssi::print "AG | too few arguments"; + Irssi::print "AG | usage: ag_rem "; + return; + } + &ag_parserem($searchesfilename, @args); +} + +sub ag_botadd #add bots +{ + &ag_server; + my @args = quotewords('\s+', 0, @_[0]); + if ($#args < 0) + { + Irssi::print "AG | too few arguments"; + Irssi::print "AG | usage: ag_botsadd "; + return; + } + &ag_parseadd($botsfilename, @args); +} + +sub ag_botrem #remove bots +{ + &ag_server; + my @args = quotewords('\s+', 0, @_[0]); + if ($#args < 0) + { + Irssi::print "AG | too few arguments"; + Irssi::print "AG | usage: ag_rem "; + return; + } + &ag_parserem($botsfilename, @args); +} + +sub ag_run #main loop +{ + Irssi::print "AG | Search and get cycle Initiated"; + &ag_getbots; + foreach my $n (@bots) + { + Irssi::print "AG | Bots: " . $n; + } + &ag_getterms; + foreach my $n (@terms) + { + Irssi::print "AG | Terms: " . $n; + } + &ag_search; +} + +sub ag_stop +{ + Irssi::print "AG | killed"; + Irssi::signal_remove("dcc get receive", "ag_opendcc"); + $botcounter = 0; + $termcounter = 0; + $packcounter = 0; + @bots = (); + @terms = (); + @packs = (); + foreach my $to (@totags) + { + Irssi::timeout_remove($to); + } + @totags = (); +} + +sub ag_settings +{ + ($nexdelay, $dcrdelay, $botdelay, $exedelay, $initflag, $sendprefix, $cancelprefix, $findprefix, $botsfilename, $searchesfilename) = (Irssi::settings_get_int("ag_next_delay"), Irssi::settings_get_int("ag_dcc_closed_retry_delay"), Irssi::settings_get_int("ag_bot_delay"), Irssi::settings_get_int("ag_interrun_delay"), Irssi::settings_get_bool("ag_autorun"), Irssi::settings_get_str("ag_xdcc_send_prefix"), Irssi::settings_get_str("ag_xdcc_cancel_prefix"), Irssi::settings_get_str("ag_xdcc_find_prefix"), Irssi::settings_get_str("ag_bot_file"), Irssi::settings_get_str("ag_search_file")); +} + +sub ag_reset +{ + my $nexdelay = 5; + my $dcrdelay = 10; + my $botdelay = 30; + my $exedelay = 15; + my $initflag = 1; + my $sendprefix = "xdcc send"; + my $findprefix = "!find"; + my $botsfilename = "$FindBin::Bin/.irssi/scripts/bots.txt"; + my $searchesfilename = "$FindBin::Bin/.irssi/scripts/searches.txt"; + Irssi::settings_get_int("ag_next_delay"); + Irssi::settings_get_int("ag_dcc_closed_retry_delay"); + Irssi::settings_get_int("ag_bot_delay"); + Irssi::settings_get_int("ag_interrun_delay"); + Irssi::settings_get_bool("ag_autorun"); + Irssi::settings_get_str("ag_xdcc_send_prefix"); + Irssi::settings_get_str("ag_xdcc_find_prefix"); + Irssi::settings_get_str("ag_bot_file"); + Irssi::settings_get_str("ag_search_file"); + Irssi::print "AG | all settings reset to default values"; +} + +open(bots, ">>", $botsfilename); #makes bots and searches file if they don't exist +close(bots); +open(searches, ">>", $searchesfilename); +close(searches); +if ($initflag) {&ag_init();} + +Irssi::signal_add("dcc closed", "ag_closedcc"); + +Irssi::settings_add_int("ag", "ag_next_delay", $nexdelay); +Irssi::settings_add_int("ag", "ag_dcc_closed_retry_delay", $dcrdelay); +Irssi::settings_add_int("ag", "ag_bot_delay", $botdelay); +Irssi::settings_add_int("ag", "ag_interrun_delay", $exedelay); +Irssi::settings_add_bool("ag", "ag_autorun", $initflag); +Irssi::settings_add_str("ag", "ag_xdcc_send_prefix", $sendprefix); +Irssi::settings_add_str("ag", "ag_xdcc_cancel_prefix", $cancelprefix); +Irssi::settings_add_str("ag", "ag_xdcc_find_prefix", $findprefix); +Irssi::settings_add_str("ag", "ag_bot_file", $botsfilename); +Irssi::settings_add_str("ag", "ag_search_file", $searchesfilename); + +Irssi::command_bind("ag_help", "ag_help"); +Irssi::command_bind("ag_run", "ag_run"); +Irssi::command_bind("ag_stop", "ag_run"); +Irssi::command_bind("ag_server", "ag_server"); +Irssi::command_bind("ag_add", "ag_add"); +Irssi::command_bind("ag_rem", "ag_rem"); +Irssi::command_bind("ag_botadd", "ag_botadd"); +Irssi::command_bind("ag_botrem", "ag_botrem"); + -- cgit v1.2.3 From 87ec2d40df3a9d365469e6b7575528c093d75b39 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 25 Oct 2015 18:46:25 -0400 Subject: updated script to v1.2(now actually works --- scripts/xdcc_autoget.pl | 280 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 216 insertions(+), 64 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 960ed2e..100db8e 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -32,7 +32,7 @@ use File::Copy; use Irssi 20090331; use vars qw($VERSION %IRSSI); -$VERSION = 1.0; +$VERSION = 1.2; %IRSSI = ( name => "autoget", description => "XDCC Autoget, for automated searching and downloading of xdcc packs", @@ -42,32 +42,54 @@ $VERSION = 1.0; contact => "mobilegundamseed\@hotmail.com", ); -my @totags = (); #timeout tags (need to be purged between send requests maybe) - -my $nexdelay = 5; #delay for next pack -my $dcrdelay = 10; #delay if transfer closed prematurely -my $botdelay = 30; #max time to wait for the bot to respond -my $exedelay = 15; #delay (in minutes) between finishing one run and starting another - -my $initflag = 1; #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD -my $msgflag = 1; #flag controls whether bot has responded to search request -my $pact = 0; #3 state flag to avoid recursive ag_reqpack calls +Irssi::settings_add_int($IRSSI{'name'}, "ag_next_delay", 5); +Irssi::settings_add_int($IRSSI{'name'}, "ag_dcc_closed_retry_delay", 10); +Irssi::settings_add_int($IRSSI{'name'}, "ag_bot_delay", 30); +Irssi::settings_add_int($IRSSI{'name'}, "ag_interrun_delay", 15); +Irssi::settings_add_bool($IRSSI{'name'}, "ag_autorun", 1); +Irssi::settings_add_bool($IRSSI{'name'}, "ag_episodic", 0); +Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_send_prefix", "xdcc send"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_cancel_prefix", "xdcc cancel"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_find_prefix", "!find"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_format", ""); +Irssi::settings_add_str($IRSSI{'name'}, "ag_bot_file", File::HomeDir->my_home . "/.irssi/scripts/bots.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_search_file", File::HomeDir->my_home . "/.irssi/scripts/searches.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_cache_file", File::HomeDir->my_home . "/.irssi/scripts/finished.txt"); -my $sendprefix = "xdcc send"; #virtually universal xdcc send, cancel, and find prefixes -my $cancelprefix = "xdcc cancel"; -my $findprefix = "!find"; -my $botsfilename = File::HomeDir->my_home . "/.irssi/scripts/bots.txt"; #werks on my machine (tm). -my $searchesfilename = File::HomeDir->my_home . "/.irssi/scripts/searches.txt"; +my @totags = (); #timeout tags (need to be purged between send requests maybe) +my @msgtags = (); #timeout tags for search results + +my $nexdelay = Irssi::settings_get_int("ag_next_delay"); #delay for next pack +my $dcrdelay = Irssi::settings_get_int("ag_dcc_closed_retry_delay"); #delay if transfer closed prematurely +my $botdelay = Irssi::settings_get_int("ag_bot_delay"); #max time to wait for the bot to respond +my $exedelay = Irssi::settings_get_int("ag_interrun_delay"); #delay (in minutes) between finishing one run and starting another + +my $initflag = Irssi::settings_get_bool("ag_autorun"); #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD +my $runningflag = 0; #flag keeps ag from running more than one instance of itself at a time +my $msgflag = 1; #flag controls whether bot has responded to search request +my $addflag = 0; #flag controls whether bot has sent a pack +my $episodeflag = Irssi::settings_get_bool("ag_episodic"); #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) +my $pact = 0; #3 state flag to avoid recursive ag_reqpack calls + +my $sendprefix = Irssi::settings_get_str("ag_xdcc_send_prefix"); #virtually universal xdcc send, cancel, and find prefixes +my $cancelprefix = Irssi::settings_get_str("ag_xdcc_cancel_prefix"); +my $findprefix = Irssi::settings_get_str("ag_find_prefix"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc +my $format = Irssi::settings_get_str("ag_format"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc +my $botsfilename = Irssi::settings_get_str("ag_bot_file"); +my $searchesfilename = Irssi::settings_get_str("ag_search_file"); +my $finishedfilename = Irssi::settings_get_str("ag_cache_file"); my $dccflag = 0; #flag so that dccs aren't mistakenly thought of belonging to AG my @terms; #lists of search terms, bots, and pack numbers (for current bot only) my @bots; my @packs; +my @finished; #list of packs already downloaded my $termcounter = 0; #counters for array position my $botcounter = 0; my $packcounter = 0; +my $episode = 1; my $server; #current server @@ -95,14 +117,17 @@ sub ag_help Irssi::print "to remove a bot : ag_botrem BOT1 BOT2 *** BOTN"; Irssi::print "to add string : ag_add \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; Irssi::print "to remove strings: ag_rem \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; + Irssi::print "to clear cache : ag_clearcache"; Irssi::print "ag_next_delay : delay between full transfers"; Irssi::print "ag_dcc_closed_retry_delay: delay after premature transfer"; Irssi::print "ag_bot_delay : max time to wait for the bot to respond"; Irssi::print "ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another"; Irssi::print "ag_autorun : whether to run on startup"; + Irssi::print "ag_episodic : search ep 1, if found then search ep 2. Use for series if bot limits search results. Results may vary depending on bot and search term"; Irssi::print "ag_xdcc_send_prefix : the xdcc message before the pack #"; Irssi::print "ag_xdcc_cancel_prefix : the xdcc message to cancel a transfer"; Irssi::print "ag_xdcc_find_prefix : the xdcc message before the search term"; + Irssi::print "ag_format : universal string appended to the end of each search in episodic. Use if more than one format exists"; Irssi::print "ag_bot_file : where your bot list is stored"; Irssi::print "ag_search_file : where your search list is stored}"; } @@ -128,41 +153,85 @@ sub ag_getterms #reads in search term list close(searches); } +sub ag_getfinished #reads in finished packs list +{ + open(finished, "<", $finishedfilename); + @finished = ; + chomp(@finished); + @finished = ag_uniq(@finished); + close(finished); +} + +sub ag_clearcache #resets cache of saved packs +{ + unlink $finishedfilename; + open(finished, ">>", $finishedfilename); + close(finished); +} + sub ag_search #searches current bot for current term { $msgflag = 0; Irssi::signal_add("message irc notice", "ag_getmsg"); - $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter]"); - Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip } , []); #skip search if no results given + if($episodeflag) + { + my $ep = sprintf("%.2d", $episode); + $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format" ); + push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_formatlessepisodicsearch; } , [])); #retry search if no results given, but without the format + + } + else + { + $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter]"); + push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given + } +} + +sub ag_formatlessepisodicsearch #redo above, but without formatting +{ + my $ep = sprintf("%.2d", $episode); + $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); + push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given } sub ag_skip { if ($msgflag == 0) - { - if ($#terms != $termcounter) + { + if ($episodeflag and $addflag) { - Irssi::print "AG | No packs found or Bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next search"; + $addflag = 0; + $episode++; + &ag_search; + } + elsif ($#terms != $termcounter) + { + + Irssi::print "AG | No new and unfinished packs found or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next search"; Irssi::signal_remove("message irc notice", "ag_getmsg"); + $episode = 1; $termcounter++; &ag_search; } elsif ($#bots != $botcounter) { - Irssi::print "AG | No packs found or Bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next bot"; + Irssi::print "AG | No new and unfinished packs found or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next bot"; Irssi::signal_remove("message irc notice", "ag_getmsg"); $termcounter = 0; + $episode = 1; $botcounter++; &ag_search; } else { - Irssi::print "AG | No packs found or Bot " . $bots[$botcounter] . " unresponsive or nonexistent. End of list"; + Irssi::print "AG | No new and unfinished packs found or bot " . $bots[$botcounter] . " unresponsive or nonexistent. End of list"; Irssi::signal_remove("message irc notice", "ag_getmsg"); $botcounter = 0; $termcounter = 0; + $episode = 1; Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + $runningflag = 0; } } } @@ -176,27 +245,67 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this if ($botname == $bots[$botcounter]) { $msgflag = 1; - &parseresponse($message); + &ag_parseresponse($message); + foreach my $to (@msgtags) #reset timeouts for skipping if a message has been recieved + { + Irssi::timeout_remove($to); + } + @msgtags = (); + push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given } } -sub parseresponse #takes a single message and finds all instances of "#[XDCC NUMBER]:" since most bots reply to !find requests like that. If a bot uses another method and this doesn't work, fix it yourself and send me the code =D +sub ag_parseresponse #takes a single message and finds all instances of "#[XDCC NUMBER]:" since most bots reply to !find requests like that. If a bot uses another method and this doesn't work, fix it yourself and send me the code =D { my($message) = @_; my @temp = split(' ', $message); - foreach my $n (@temp){ if ($n =~ m{#(\d+):}) {push(@packs, $1);} } + foreach my $m (@temp) + { + $addflag = 1; + if ($m =~ m{#(\d+):}) + { + &ag_getfinished; + foreach my $n (@finished) #don't redownload finished packs + { + if ($n eq "$bots[$botcounter] $1") + { + $addflag = 0; + } + last if ($n eq "$bots[$botcounter] $1"); + } + if ($addflag >= 1) {push(@packs, $1);} + } + } @packs = ag_uniq(@packs); + if ($pact == 0 and $#packs >= 0 and $packs[$packcounter] ne "") #initiallizes the actual xdcc get system only once per search term/bot (pact should be >0 until the whole process is finished) { + foreach my $to (@msgtags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @msgtags = (); + + $msgflag = 1; $pact = 1; &ag_reqpack(); } + elsif ($#packs <= 0) + { + $msgflag = 0; + foreach my $to (@msgtags) #remove timeouts for skipping and skip if no packs found + { + Irssi::timeout_remove($to); + } + @msgtags = (); + push(@msgtags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip(); }, [])); + } } sub ag_uniq #only returns unique entries { - my %seen; - grep !$seen{$_}++, @_; + my %seen; + grep !$seen{$_}++, @_; } sub ag_reqpack #sends the xdcc send request, and retries on failure @@ -228,6 +337,14 @@ sub ag_opendcc #runs on DCC recieve init } } +sub ag_filecomp #save finished downloads +{ + open(finished, ">>", $finishedfilename); + print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print to file + close(finished); + &ag_getfinished; +} + sub ag_closedcc #deals with DCC closes { my ($dcc) = @_; #current pack @@ -238,13 +355,29 @@ sub ag_closedcc #deals with DCC closes { if ($dccflag == 0) {Irssi::signal_add("dcc get receive", "ag_opendcc");} #if so, reinits DCC get signal for the next pack $dccflag = 1; - Irssi::print "AG | pack " . $packs[$packcounter] . " size was: " . $dcc->{'size'} . " transferred: " . $dcc->{'transfd'} . " skipped: " . $dcc->{'skipped'}; #nerdy info on pack recieved foreach my $to (@totags) #clears timeouts to defuckify everything { Irssi::timeout_remove($to); } @totags = (); - if ($dcc->{'transfd'} == $dcc->{'size'}) #checks if the transfer actually ran to completion + + if ($dcc->{'transfd'} == $dcc->{'size'}){&ag_filecomp} + + if($episodeflag and $dcc->{'transfd'} == $dcc->{'size'}) + { + $episode++; + $pact = 1; #allow pack requests now that transfer is finished + @packs = (); #delete packlist + $packcounter = 0; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next episode"; &ag_search(); }, [])); + Irssi::print "AG | waiting " . $nexdelay . " seconds"; + if ($dcc->{'skipped'} == $dcc->{'size'}) + { + $server->command("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. + } + + } + elsif ($dcc->{'transfd'} == $dcc->{'size'}) #checks if the transfer actually ran to completion { Irssi::print "AG | transfer successful"; #if so, does next pack/search/bot (in that order) if ($dcc->{'skipped'} == $dcc->{'size'}) @@ -287,6 +420,7 @@ sub ag_closedcc #deals with DCC closes Irssi::signal_remove("message irc notice", "ag_getmsg"); Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + $runningflag = 0; } } else #if not, retry transfer @@ -422,23 +556,42 @@ sub ag_botrem #remove bots sub ag_run #main loop { - Irssi::print "AG | Search and get cycle Initiated"; - &ag_getbots; - foreach my $n (@bots) - { - Irssi::print "AG | Bots: " . $n; - } - &ag_getterms; - foreach my $n (@terms) + if($runningflag == 0) { - Irssi::print "AG | Terms: " . $n; + $runningflag = 1; + &ag_getbots; + foreach my $n (@bots) + { + Irssi::print "AG | Bots: " . $n; + } + &ag_getterms; + foreach my $n (@terms) + { + Irssi::print "AG | Terms: " . $n; + } + if($#bots < 0 or $#terms < 0) {Irssi::print "AG | No bots or no search terms added. Halting"; &ag_stop;} + else + { + Irssi::print "AG | Search and get cycle Initiated"; + &ag_search; + } } - &ag_search; + else {Irssi::print "AG | Another Instance is already running";} } sub ag_stop { - Irssi::print "AG | killed"; + foreach my $to (@totags) + { + Irssi::timeout_remove($to); + } + @totags = (); + $server->command("msg $bots[$botcounter] $cancelprefix"); + if($runningflag == 1) + { + $runningflag = 0; + Irssi::print "AG | Killed"; + } Irssi::signal_remove("dcc get receive", "ag_opendcc"); $botcounter = 0; $termcounter = 0; @@ -446,16 +599,6 @@ sub ag_stop @bots = (); @terms = (); @packs = (); - foreach my $to (@totags) - { - Irssi::timeout_remove($to); - } - @totags = (); -} - -sub ag_settings -{ - ($nexdelay, $dcrdelay, $botdelay, $exedelay, $initflag, $sendprefix, $cancelprefix, $findprefix, $botsfilename, $searchesfilename) = (Irssi::settings_get_int("ag_next_delay"), Irssi::settings_get_int("ag_dcc_closed_retry_delay"), Irssi::settings_get_int("ag_bot_delay"), Irssi::settings_get_int("ag_interrun_delay"), Irssi::settings_get_bool("ag_autorun"), Irssi::settings_get_str("ag_xdcc_send_prefix"), Irssi::settings_get_str("ag_xdcc_cancel_prefix"), Irssi::settings_get_str("ag_xdcc_find_prefix"), Irssi::settings_get_str("ag_bot_file"), Irssi::settings_get_str("ag_search_file")); } sub ag_reset @@ -481,31 +624,40 @@ sub ag_reset Irssi::print "AG | all settings reset to default values"; } -open(bots, ">>", $botsfilename); #makes bots and searches file if they don't exist +#sub ag_setsettings +#{ +# Irssi::settings_set_int("ag_next_delay", $nexdelay); +# Irssi::settings_set_int("ag_dcc_closed_retry_delay", $dcrdelay); +# Irssi::settings_set_int("ag_bot_delay", $botdelay); +# Irssi::settings_set_int("ag_interrun_delay", $exedelay); +# Irssi::settings_set_bool("ag_autorun", $initflag); +# Irssi::settings_set_bool("ag_episodic", $episodeflag); +# Irssi::settings_set_str("ag_xdcc_send_prefix", $sendprefix); +# Irssi::settings_set_str("ag_xdcc_cancel_prefix", $cancelprefix); +# Irssi::settings_set_str("ag_xdcc_find_prefix", $findprefix); +# Irssi::settings_set_str("ag_format", $format); +# Irssi::settings_set_str("ag_bot_file", $botsfilename); +# Irssi::settings_set_str("ag_search_file", $searchesfilename); +#} + +open(bots, ">>", $botsfilename); #makes bots, searches, and finished file if they don't exist close(bots); open(searches, ">>", $searchesfilename); close(searches); +open(finished, ">>", $finishedfilename); +close(finished); if ($initflag) {&ag_init();} Irssi::signal_add("dcc closed", "ag_closedcc"); - -Irssi::settings_add_int("ag", "ag_next_delay", $nexdelay); -Irssi::settings_add_int("ag", "ag_dcc_closed_retry_delay", $dcrdelay); -Irssi::settings_add_int("ag", "ag_bot_delay", $botdelay); -Irssi::settings_add_int("ag", "ag_interrun_delay", $exedelay); -Irssi::settings_add_bool("ag", "ag_autorun", $initflag); -Irssi::settings_add_str("ag", "ag_xdcc_send_prefix", $sendprefix); -Irssi::settings_add_str("ag", "ag_xdcc_cancel_prefix", $cancelprefix); -Irssi::settings_add_str("ag", "ag_xdcc_find_prefix", $findprefix); -Irssi::settings_add_str("ag", "ag_bot_file", $botsfilename); -Irssi::settings_add_str("ag", "ag_search_file", $searchesfilename); +#Irssi::signal_add("setup changed", "ag_setsettings"); Irssi::command_bind("ag_help", "ag_help"); Irssi::command_bind("ag_run", "ag_run"); -Irssi::command_bind("ag_stop", "ag_run"); +Irssi::command_bind("ag_stop", "ag_stop"); Irssi::command_bind("ag_server", "ag_server"); Irssi::command_bind("ag_add", "ag_add"); Irssi::command_bind("ag_rem", "ag_rem"); Irssi::command_bind("ag_botadd", "ag_botadd"); Irssi::command_bind("ag_botrem", "ag_botrem"); +Irssi::command_bind("ag_clearcache", "ag_clearcache"); -- cgit v1.2.3 From c742fa69f16b1ff32ee3f31d57d4a97d45268c38 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 25 Oct 2015 18:58:49 -0400 Subject: bugfix to work with travis.ci --- scripts/xdcc_autoget.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 100db8e..b89efe4 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -52,9 +52,9 @@ Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_send_prefix", "xdcc send"); Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_cancel_prefix", "xdcc cancel"); Irssi::settings_add_str($IRSSI{'name'}, "ag_find_prefix", "!find"); Irssi::settings_add_str($IRSSI{'name'}, "ag_format", ""); -Irssi::settings_add_str($IRSSI{'name'}, "ag_bot_file", File::HomeDir->my_home . "/.irssi/scripts/bots.txt"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_search_file", File::HomeDir->my_home . "/.irssi/scripts/searches.txt"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_cache_file", File::HomeDir->my_home . "/.irssi/scripts/finished.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_bot_file", File::HomeDir->my_home . "/.irssi/bots.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_search_file", File::HomeDir->my_home . "/.irssi/searches.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_cache_file", File::HomeDir->my_home . "/.irssi/finished.txt"); my @totags = (); #timeout tags (need to be purged between send requests maybe) my @msgtags = (); #timeout tags for search results @@ -207,7 +207,7 @@ sub ag_skip elsif ($#terms != $termcounter) { - Irssi::print "AG | No new and unfinished packs found or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next search"; + Irssi::print "AG | No new and unfinished packs found while searching ". $terms[$termcounter] . " or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next search"; Irssi::signal_remove("message irc notice", "ag_getmsg"); $episode = 1; $termcounter++; @@ -215,7 +215,7 @@ sub ag_skip } elsif ($#bots != $botcounter) { - Irssi::print "AG | No new and unfinished packs found or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next bot"; + Irssi::print "AG | No new and unfinished packs found while searching ". $terms[$termcounter] . " or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next bot"; Irssi::signal_remove("message irc notice", "ag_getmsg"); $termcounter = 0; $episode = 1; @@ -224,7 +224,7 @@ sub ag_skip } else { - Irssi::print "AG | No new and unfinished packs found or bot " . $bots[$botcounter] . " unresponsive or nonexistent. End of list"; + Irssi::print "AG | No new and unfinished packs found while searching ". $terms[$termcounter] . " or bot " . $bots[$botcounter] . " unresponsive or nonexistent. End of list"; Irssi::signal_remove("message irc notice", "ag_getmsg"); $botcounter = 0; $termcounter = 0; -- cgit v1.2.3 From a8a91e1b9cf1c07b9aabaeb971d6b046a6fa506b Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 25 Oct 2015 19:05:44 -0400 Subject: YATBF --- scripts/xdcc_autoget.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index b89efe4..5f719e8 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -52,9 +52,9 @@ Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_send_prefix", "xdcc send"); Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_cancel_prefix", "xdcc cancel"); Irssi::settings_add_str($IRSSI{'name'}, "ag_find_prefix", "!find"); Irssi::settings_add_str($IRSSI{'name'}, "ag_format", ""); -Irssi::settings_add_str($IRSSI{'name'}, "ag_bot_file", File::HomeDir->my_home . "/.irssi/bots.txt"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_search_file", File::HomeDir->my_home . "/.irssi/searches.txt"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_cache_file", File::HomeDir->my_home . "/.irssi/finished.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_bot_file", File::HomeDir->my_home . "/bots.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_search_file", File::HomeDir->my_home . "/searches.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_cache_file", File::HomeDir->my_home . "/finished.txt"); my @totags = (); #timeout tags (need to be purged between send requests maybe) my @msgtags = (); #timeout tags for search results -- cgit v1.2.3 From 33587969df511f3bed66a8f2298f56189af704cb Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 25 Oct 2015 20:39:43 -0400 Subject: preformance improvements --- scripts/xdcc_autoget.pl | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 5f719e8..91d2054 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -176,8 +176,12 @@ sub ag_search #searches current bot for current term if($episodeflag) { my $ep = sprintf("%.2d", $episode); - $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format" ); - push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_formatlessepisodicsearch; } , [])); #retry search if no results given, but without the format + if ($format ne "") + { + $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format" ); + push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_formatlessepisodicsearch; } , [])); #retry search if no results given, but without the format + } + else {&ag_formatlessepisodicsearch;} } else @@ -242,16 +246,17 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this my $botname = @_[2]; $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; + + foreach my $to (@msgtags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @msgtags = (); + if ($botname == $bots[$botcounter]) { $msgflag = 1; &ag_parseresponse($message); - foreach my $to (@msgtags) #reset timeouts for skipping if a message has been recieved - { - Irssi::timeout_remove($to); - } - @msgtags = (); - push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given } } @@ -280,12 +285,6 @@ sub ag_parseresponse #takes a single message and finds all instances of "#[XDCC if ($pact == 0 and $#packs >= 0 and $packs[$packcounter] ne "") #initiallizes the actual xdcc get system only once per search term/bot (pact should be >0 until the whole process is finished) { - foreach my $to (@msgtags) #remove timeouts for skipping if a pack has been recieved - { - Irssi::timeout_remove($to); - } - @msgtags = (); - $msgflag = 1; $pact = 1; &ag_reqpack(); @@ -293,11 +292,6 @@ sub ag_parseresponse #takes a single message and finds all instances of "#[XDCC elsif ($#packs <= 0) { $msgflag = 0; - foreach my $to (@msgtags) #remove timeouts for skipping and skip if no packs found - { - Irssi::timeout_remove($to); - } - @msgtags = (); push(@msgtags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip(); }, [])); } } -- cgit v1.2.3 From b69d7bf4c4aba78035466c8590361b15a6311a5b Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 30 Oct 2015 16:46:01 -0400 Subject: update --- scripts/xdcc_autoget.pl | 147 +++++++++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 57 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 91d2054..b3030df 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -52,12 +52,10 @@ Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_send_prefix", "xdcc send"); Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_cancel_prefix", "xdcc cancel"); Irssi::settings_add_str($IRSSI{'name'}, "ag_find_prefix", "!find"); Irssi::settings_add_str($IRSSI{'name'}, "ag_format", ""); -Irssi::settings_add_str($IRSSI{'name'}, "ag_bot_file", File::HomeDir->my_home . "/bots.txt"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_search_file", File::HomeDir->my_home . "/searches.txt"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_cache_file", File::HomeDir->my_home . "/finished.txt"); +Irssi::settings_add_str($IRSSI{'name'}, "ag_folder", File::HomeDir->my_home); my @totags = (); #timeout tags (need to be purged between send requests maybe) -my @msgtags = (); #timeout tags for search results +my @skiptags = (); #timeout tags for search results my $nexdelay = Irssi::settings_get_int("ag_next_delay"); #delay for next pack my $dcrdelay = Irssi::settings_get_int("ag_dcc_closed_retry_delay"); #delay if transfer closed prematurely @@ -69,15 +67,17 @@ my $runningflag = 0; #flag keeps ag from running more than one instance of my $msgflag = 1; #flag controls whether bot has responded to search request my $addflag = 0; #flag controls whether bot has sent a pack my $episodeflag = Irssi::settings_get_bool("ag_episodic"); #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) +my $formatflag = 1; my $pact = 0; #3 state flag to avoid recursive ag_reqpack calls my $sendprefix = Irssi::settings_get_str("ag_xdcc_send_prefix"); #virtually universal xdcc send, cancel, and find prefixes my $cancelprefix = Irssi::settings_get_str("ag_xdcc_cancel_prefix"); my $findprefix = Irssi::settings_get_str("ag_find_prefix"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc my $format = Irssi::settings_get_str("ag_format"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc -my $botsfilename = Irssi::settings_get_str("ag_bot_file"); -my $searchesfilename = Irssi::settings_get_str("ag_search_file"); -my $finishedfilename = Irssi::settings_get_str("ag_cache_file"); +my $folder = Irssi::settings_get_str("ag_folder"); +my $botsfilename = $folder . "/bots.txt"; +my $searchesfilename = $folder . "/searches.txt"; +my $cachefilename = $folder . "/cache.txt"; my $dccflag = 0; #flag so that dccs aren't mistakenly thought of belonging to AG @@ -97,6 +97,7 @@ sub ag_init #init system { Irssi::print "AG | Autoget initiated"; Irssi::print "AG | /ag_help for help"; + &ag_initserver; } @@ -128,8 +129,7 @@ sub ag_help Irssi::print "ag_xdcc_cancel_prefix : the xdcc message to cancel a transfer"; Irssi::print "ag_xdcc_find_prefix : the xdcc message before the search term"; Irssi::print "ag_format : universal string appended to the end of each search in episodic. Use if more than one format exists"; - Irssi::print "ag_bot_file : where your bot list is stored"; - Irssi::print "ag_search_file : where your search list is stored}"; + Irssi::print "ag_folder : Location for data files. ~/.irssi/ reccomended"; } sub ag_server #should only be run when you have a server, or it'll break (probably unfixable without a bunch of ugly dumb checks everywhere) @@ -155,84 +155,96 @@ sub ag_getterms #reads in search term list sub ag_getfinished #reads in finished packs list { - open(finished, "<", $finishedfilename); + open(finished, "<", $cachefilename); @finished = ; chomp(@finished); @finished = ag_uniq(@finished); close(finished); } -sub ag_clearcache #resets cache of saved packs +sub ag_clearcache #clears cache of saved packs { - unlink $finishedfilename; - open(finished, ">>", $finishedfilename); + unlink $cachefilename; + open(finished, ">>", $cachefilename); close(finished); } sub ag_search #searches current bot for current term { + foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @skiptags = (); $msgflag = 0; Irssi::signal_add("message irc notice", "ag_getmsg"); if($episodeflag) { + $addflag = 1; my $ep = sprintf("%.2d", $episode); - if ($format ne "") + if ($format ne "" and $formatflag) { $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format" ); - push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_formatlessepisodicsearch; } , [])); #retry search if no results given, but without the format + if ($episode eq 1){push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_formatlessepisodicsearch; } , []));} #retry search if no results given, but without the format + else {push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , []));} } else {&ag_formatlessepisodicsearch;} - } else { $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter]"); - push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given + push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given } } sub ag_formatlessepisodicsearch #redo above, but without formatting { + $formatflag = 0; my $ep = sprintf("%.2d", $episode); $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); - push(@msgtags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given + push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given } sub ag_skip { + foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @skiptags = (); + if ($msgflag == 0) - { - if ($episodeflag and $addflag) + { + if($episodeflag and !$addflag) { - $addflag = 0; + Irssi::signal_remove("message irc notice", "ag_getmsg"); $episode++; &ag_search; } elsif ($#terms != $termcounter) { - - Irssi::print "AG | No new and unfinished packs found while searching ". $terms[$termcounter] . " or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next search"; Irssi::signal_remove("message irc notice", "ag_getmsg"); $episode = 1; + $formatflag = 1; $termcounter++; &ag_search; } elsif ($#bots != $botcounter) { - Irssi::print "AG | No new and unfinished packs found while searching ". $terms[$termcounter] . " or bot " . $bots[$botcounter] . " unresponsive or nonexistent. Skipping to next bot"; Irssi::signal_remove("message irc notice", "ag_getmsg"); - $termcounter = 0; $episode = 1; + $formatflag = 1; + $termcounter = 0; $botcounter++; &ag_search; } else { - Irssi::print "AG | No new and unfinished packs found while searching ". $terms[$termcounter] . " or bot " . $bots[$botcounter] . " unresponsive or nonexistent. End of list"; Irssi::signal_remove("message irc notice", "ag_getmsg"); + $episode = 1; + $formatflag = 1; $botcounter = 0; $termcounter = 0; - $episode = 1; Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); $runningflag = 0; @@ -241,18 +253,18 @@ sub ag_skip } sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this from sending useless shit that breaks things -{ - my $message = @_[1]; - my $botname = @_[2]; - $botname =~ tr/[A-Z]/[a-z]/; - $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - - foreach my $to (@msgtags) #remove timeouts for skipping if a pack has been recieved +{ + foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved { Irssi::timeout_remove($to); } - @msgtags = (); + @skiptags = (); + my $message = @_[1]; + my $botname = @_[2]; + $botname =~ tr/[A-Z]/[a-z]/; + $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; + if ($botname == $bots[$botcounter]) { $msgflag = 1; @@ -266,33 +278,28 @@ sub ag_parseresponse #takes a single message and finds all instances of "#[XDCC my @temp = split(' ', $message); foreach my $m (@temp) { - $addflag = 1; if ($m =~ m{#(\d+):}) { + $addflag = 1; &ag_getfinished; foreach my $n (@finished) #don't redownload finished packs { - if ($n eq "$bots[$botcounter] $1") - { - $addflag = 0; - } + if ($n eq "$bots[$botcounter] $1") {$addflag = 0;} last if ($n eq "$bots[$botcounter] $1"); } - if ($addflag >= 1) {push(@packs, $1);} + if ($addflag) {push(@packs, $1);} } } @packs = ag_uniq(@packs); - - if ($pact == 0 and $#packs >= 0 and $packs[$packcounter] ne "") #initiallizes the actual xdcc get system only once per search term/bot (pact should be >0 until the whole process is finished) + if ($pact == 0 and $#packs >= 0 and $packs[$packcounter] ne "" and $bots[$botcounter]ne "") #initiallizes the actual xdcc get system only once per search term/bot (pact should be >0 until the whole process is finished) { - $msgflag = 1; $pact = 1; &ag_reqpack(); } - elsif ($#packs <= 0) + elsif ($#packs < 0 and $pact == 0) { $msgflag = 0; - push(@msgtags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip(); }, [])); + push(@skiptags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip; } , [])); } } @@ -304,6 +311,11 @@ sub ag_uniq #only returns unique entries sub ag_reqpack #sends the xdcc send request, and retries on failure { + foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @skiptags = (); if ($dccflag == 0){Irssi::signal_add("dcc get receive", "ag_opendcc");} #init DCC recieve init flag $dccflag = 1; $server->command("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); @@ -321,6 +333,12 @@ sub ag_opendcc #runs on DCC recieve init $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; if ($botname eq $bots[$botcounter]) #if it's our bot, let user know, and stop any further AG pack requests until finished { + foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @skiptags = (); + Irssi::print "AG | received connection for bot: " . $botname . ", #" . $packs[$packcounter]; $pact = 2; } @@ -329,12 +347,23 @@ sub ag_opendcc #runs on DCC recieve init Irssi::signal_add("dcc get receive", "ag_opendcc"); $dccflag = 1; } + foreach my $n (@finished) #don't redownload finished packs + { + if ($n eq $gdcc->{'arg'}) + { + $gdcc->{'transfd'} = $gdcc->{'size'}; + &ag_closedcc(@_); + } + last if ($n eq "$bots[$botcounter] $1"); + } } sub ag_filecomp #save finished downloads { - open(finished, ">>", $finishedfilename); - print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print to file + my $filename = @_[0]; + open(finished, ">>", $cachefilename); + print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file + print finished $filename . "\n"; #print name to file close(finished); &ag_getfinished; } @@ -347,6 +376,7 @@ sub ag_closedcc #deals with DCC closes $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; if ($botname eq $bots[$botcounter]) { + Irssi::signal_remove("message irc notice", "ag_getmsg"); if ($dccflag == 0) {Irssi::signal_add("dcc get receive", "ag_opendcc");} #if so, reinits DCC get signal for the next pack $dccflag = 1; foreach my $to (@totags) #clears timeouts to defuckify everything @@ -354,13 +384,18 @@ sub ag_closedcc #deals with DCC closes Irssi::timeout_remove($to); } @totags = (); + foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + { + Irssi::timeout_remove($to); + } + @skiptags = (); - if ($dcc->{'transfd'} == $dcc->{'size'}){&ag_filecomp} + if ($dcc->{'transfd'} == $dcc->{'size'}){&ag_filecomp($dcc->{'arg'})} if($episodeflag and $dcc->{'transfd'} == $dcc->{'size'}) { $episode++; - $pact = 1; #allow pack requests now that transfer is finished + $pact = 0; #allow pack requests now that transfer is finished @packs = (); #delete packlist $packcounter = 0; push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next episode"; &ag_search(); }, [])); @@ -369,9 +404,8 @@ sub ag_closedcc #deals with DCC closes { $server->command("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. } - } - elsif ($dcc->{'transfd'} == $dcc->{'size'}) #checks if the transfer actually ran to completion + elsif (!$episodeflag and $dcc->{'transfd'} == $dcc->{'size'}) #checks if the transfer actually ran to completion { Irssi::print "AG | transfer successful"; #if so, does next pack/search/bot (in that order) if ($dcc->{'skipped'} == $dcc->{'size'}) @@ -604,8 +638,8 @@ sub ag_reset my $initflag = 1; my $sendprefix = "xdcc send"; my $findprefix = "!find"; - my $botsfilename = "$FindBin::Bin/.irssi/scripts/bots.txt"; - my $searchesfilename = "$FindBin::Bin/.irssi/scripts/searches.txt"; + my $folder = File::HomeDir->my_home; + Irssi::settings_get_int("ag_next_delay"); Irssi::settings_get_int("ag_dcc_closed_retry_delay"); Irssi::settings_get_int("ag_bot_delay"); @@ -613,8 +647,7 @@ sub ag_reset Irssi::settings_get_bool("ag_autorun"); Irssi::settings_get_str("ag_xdcc_send_prefix"); Irssi::settings_get_str("ag_xdcc_find_prefix"); - Irssi::settings_get_str("ag_bot_file"); - Irssi::settings_get_str("ag_search_file"); + Irssi::settings_get_str("ag_folder"); Irssi::print "AG | all settings reset to default values"; } @@ -638,7 +671,7 @@ open(bots, ">>", $botsfilename); #makes bots, searches, and finished file if th close(bots); open(searches, ">>", $searchesfilename); close(searches); -open(finished, ">>", $finishedfilename); +open(finished, ">>", $cachefilename); close(finished); if ($initflag) {&ag_init();} -- cgit v1.2.3 From 6f33f985a0d3f9bb68d409942fb3723215cd993e Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 1 Nov 2015 15:21:33 -0500 Subject: rewrite, bugfixes, and other minor adjustments --- scripts/xdcc_autoget.pl | 457 +++++++++++++++++++++++++----------------------- 1 file changed, 239 insertions(+), 218 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index b3030df..a4c852f 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -42,7 +42,7 @@ $VERSION = 1.2; contact => "mobilegundamseed\@hotmail.com", ); -Irssi::settings_add_int($IRSSI{'name'}, "ag_next_delay", 5); +Irssi::settings_add_int($IRSSI{'name'}, "ag_next_delay", 10); Irssi::settings_add_int($IRSSI{'name'}, "ag_dcc_closed_retry_delay", 10); Irssi::settings_add_int($IRSSI{'name'}, "ag_bot_delay", 30); Irssi::settings_add_int($IRSSI{'name'}, "ag_interrun_delay", 15); @@ -55,24 +55,25 @@ Irssi::settings_add_str($IRSSI{'name'}, "ag_format", ""); Irssi::settings_add_str($IRSSI{'name'}, "ag_folder", File::HomeDir->my_home); my @totags = (); #timeout tags (need to be purged between send requests maybe) -my @skiptags = (); #timeout tags for search results my $nexdelay = Irssi::settings_get_int("ag_next_delay"); #delay for next pack my $dcrdelay = Irssi::settings_get_int("ag_dcc_closed_retry_delay"); #delay if transfer closed prematurely my $botdelay = Irssi::settings_get_int("ag_bot_delay"); #max time to wait for the bot to respond my $exedelay = Irssi::settings_get_int("ag_interrun_delay"); #delay (in minutes) between finishing one run and starting another -my $initflag = Irssi::settings_get_bool("ag_autorun"); #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD -my $runningflag = 0; #flag keeps ag from running more than one instance of itself at a time -my $msgflag = 1; #flag controls whether bot has responded to search request -my $addflag = 0; #flag controls whether bot has sent a pack -my $episodeflag = Irssi::settings_get_bool("ag_episodic"); #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) -my $formatflag = 1; -my $pact = 0; #3 state flag to avoid recursive ag_reqpack calls +my $initflag = Irssi::settings_get_bool("ag_autorun"); #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD +my $runningflag = 0; #flag keeps ag from running more than one instance of itself at a time +my $msgflag = 1; #flag controls whether bot has responded to search request +my $termisepisodicflag = 0; #flag controls whether +my $episodicflag = Irssi::settings_get_bool("ag_episodic"); #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) +my $formatflag = 1; #flag controls whether a format is appended to the end of an episodic search string +my $reqpackflag = 0; #flag to avoid multiple download requests +my $downloadflag = 0; #flag to avoid multiple download requests +my $newpackflag = 1; my $sendprefix = Irssi::settings_get_str("ag_xdcc_send_prefix"); #virtually universal xdcc send, cancel, and find prefixes my $cancelprefix = Irssi::settings_get_str("ag_xdcc_cancel_prefix"); -my $findprefix = Irssi::settings_get_str("ag_find_prefix"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc +my $findprefix = Irssi::settings_get_str("ag_find_prefix"); my $format = Irssi::settings_get_str("ag_format"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc my $folder = Irssi::settings_get_str("ag_folder"); my $botsfilename = $folder . "/bots.txt"; @@ -84,10 +85,10 @@ my $dccflag = 0; #flag so that dccs aren't mistakenly thought of belonging to AG my @terms; #lists of search terms, bots, and pack numbers (for current bot only) my @bots; my @packs; -my @finished; #list of packs already downloaded +my @finished; #list of packs already downloaded and their filenames my $termcounter = 0; #counters for array position -my $botcounter = 0; +my $botcounter = 0; my $packcounter = 0; my $episode = 1; @@ -97,8 +98,28 @@ sub ag_init #init system { Irssi::print "AG | Autoget initiated"; Irssi::print "AG | /ag_help for help"; - &ag_initserver; + &ag_getbots; + my $m; + foreach my $n (@bots) + { + $m = $m . $n . ", "; + } + Irssi::print "AG | Bots: " . $m; + $m = ""; + &ag_getterms; + foreach my $n (@terms) + { + $m = $m . $n . ", "; + } + Irssi::print "AG | Terms: " . $m; + if ($episodicflag) + { + Irssi::print "AG | Episodic: Yes"; + Irssi::print "AG | Preffered format: $format"; + } + else {Irssi::print "AG | Episodic: No";} + Irssi::print "AG | Data folder: $folder"; } sub ag_initserver #init server @@ -132,9 +153,10 @@ sub ag_help Irssi::print "ag_folder : Location for data files. ~/.irssi/ reccomended"; } -sub ag_server #should only be run when you have a server, or it'll break (probably unfixable without a bunch of ugly dumb checks everywhere) +sub ag_server #sets the current server { - $server = Irssi::active_server(); + $server = Irssi::active_server(); #keep trying to get server until it works + if ($server !~ m/^Irssi::Irc::Server=HASH/) {Irssi::timeout_add_once(1000, sub {&ag_server;} , []);} } sub ag_getbots #reads in bot list @@ -169,279 +191,266 @@ sub ag_clearcache #clears cache of saved packs close(finished); } -sub ag_search #searches current bot for current term +sub ag_search #searches bots for packs { - foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved - { - Irssi::timeout_remove($to); - } - @skiptags = (); - $msgflag = 0; - Irssi::signal_add("message irc notice", "ag_getmsg"); - if($episodeflag) + $msgflag = 0; #unset message flag so that ag_skip knows no important message has arrived + if($episodicflag) #episodic searches are complicated { - $addflag = 1; my $ep = sprintf("%.2d", $episode); if ($format ne "" and $formatflag) { - $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format" ); - if ($episode eq 1){push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_formatlessepisodicsearch; } , []));} #retry search if no results given, but without the format - else {push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , []));} + &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format"); #first search with format + if ($episode == 1) + { + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { $formatflag = 0; &ag_search; } , [])); #if no formated version found, try again with just the search string + ep# + } + else + { + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); + } + } + else + { + &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); } - else {&ag_formatlessepisodicsearch;} } - else + else #if not episodic, just search and skip { - $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter]"); - push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given + &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter]" ); + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); } } -sub ag_formatlessepisodicsearch #redo above, but without formatting +sub ag_remtimeouts #remove timeouts to avoid multiple instances of everything { - $formatflag = 0; - my $ep = sprintf("%.2d", $episode); - $server->command("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); - push(@skiptags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); #skip search if no results given -} - -sub ag_skip -{ - foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + foreach my $to (@totags) #remove timeouts and clear array { Irssi::timeout_remove($to); } - @skiptags = (); - - if ($msgflag == 0) - { - if($episodeflag and !$addflag) - { - Irssi::signal_remove("message irc notice", "ag_getmsg"); - $episode++; - &ag_search; - } - elsif ($#terms != $termcounter) - { - Irssi::signal_remove("message irc notice", "ag_getmsg"); - $episode = 1; - $formatflag = 1; - $termcounter++; - &ag_search; - } - elsif ($#bots != $botcounter) - { - Irssi::signal_remove("message irc notice", "ag_getmsg"); - $episode = 1; - $formatflag = 1; - $termcounter = 0; - $botcounter++; - &ag_search; - } - else - { - Irssi::signal_remove("message irc notice", "ag_getmsg"); - $episode = 1; - $formatflag = 1; - $botcounter = 0; - $termcounter = 0; - Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; - Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); - $runningflag = 0; - } - } + @totags = (); } sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this from sending useless shit that breaks things { - foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved - { - Irssi::timeout_remove($to); - } - @skiptags = (); - my $message = @_[1]; my $botname = @_[2]; $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname == $bots[$botcounter]) + if ($botname == $bots[$botcounter]) #if it's your bot { - $msgflag = 1; - &ag_parseresponse($message); + &ag_remtimeouts; #stop any skips from happening + &ag_getpacks($message); #and check for any new packs in the message + if ($#packs < 0) { push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip; } , [])); } #set up only one possible skip per search + if($#packs >= 0){ &ag_packrequest; } #if there are any packs, + $msgflag = 1; #let everyone know that the current bot has replied } } -sub ag_parseresponse #takes a single message and finds all instances of "#[XDCC NUMBER]:" since most bots reply to !find requests like that. If a bot uses another method and this doesn't work, fix it yourself and send me the code =D +sub ag_getpacks { my($message) = @_; - my @temp = split(' ', $message); - foreach my $m (@temp) + my @temp = split(' ', $message); #split up the message into 'words' + &ag_getfinished; + + foreach my $m (@temp) #find packs (#[NUMBER]: format) { + $newpackflag = 1; if ($m =~ m{#(\d+):}) { - $addflag = 1; - &ag_getfinished; foreach my $n (@finished) #don't redownload finished packs { - if ($n eq "$bots[$botcounter] $1") {$addflag = 0;} + if ($n eq "$bots[$botcounter] $1") {$newpackflag = 0;} last if ($n eq "$bots[$botcounter] $1"); } - if ($addflag) {push(@packs, $1);} + if($newpackflag){push(@packs, $1);} #push all new pack numbers to list of packs } } - @packs = ag_uniq(@packs); - if ($pact == 0 and $#packs >= 0 and $packs[$packcounter] ne "" and $bots[$botcounter]ne "") #initiallizes the actual xdcc get system only once per search term/bot (pact should be >0 until the whole process is finished) - { - $pact = 1; - &ag_reqpack(); - } - elsif ($#packs < 0 and $pact == 0) - { - $msgflag = 0; - push(@skiptags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip; } , [])); - } + @packs = ag_uniq(@packs); #remove duplicates } -sub ag_uniq #only returns unique entries +sub ag_packrequest #sends the xdcc send request, and retries on failure { - my %seen; - grep !$seen{$_}++, @_; -} - -sub ag_reqpack #sends the xdcc send request, and retries on failure -{ - foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + if (!$reqpackflag) { - Irssi::timeout_remove($to); + $reqpackflag = 1; + Irssi::signal_add("dcc get receive", "ag_opendcc"); #init DCC recieve init flag + &ag_message("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag) { Irssi::print "AG | Connection failed"; Irssi::print "AG | retrying: " . $bots[$botcounter] . " " .$packs[$packcounter]; &ag_packrequest(); } } , [])); } - @skiptags = (); - if ($dccflag == 0){Irssi::signal_add("dcc get receive", "ag_opendcc");} #init DCC recieve init flag - $dccflag = 1; - $server->command("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { if ($pact < 2) { Irssi::print "AG | Connection failed"; Irssi::print "AG | retrying: " . $bots[$botcounter] . " " .$packs[$packcounter]; &ag_reqpack(); } } , [])); } sub ag_opendcc #runs on DCC recieve init { - Irssi::signal_remove("dcc get receive", "ag_opendcc"); #stops any suplicate sends (there should only ever be one) - $dccflag = 0; - my ($gdcc) = @_; #current pack my $botname = $gdcc->{'nick'}; $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; + if ($botname eq $bots[$botcounter]) #if it's our bot, let user know, and stop any further AG pack requests until finished { - foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved - { - Irssi::timeout_remove($to); - } - @skiptags = (); - + Irssi::signal_remove("dcc get receive", "ag_opendcc"); #stops any suplicate sends (there should only ever be one) + $dccflag = 0; + $downloadflag = 1; + &ag_remtimeouts; Irssi::print "AG | received connection for bot: " . $botname . ", #" . $packs[$packcounter]; - $pact = 2; - } - else #if not, allow this to rerun on next get - { - Irssi::signal_add("dcc get receive", "ag_opendcc"); - $dccflag = 1; } foreach my $n (@finished) #don't redownload finished packs { - if ($n eq $gdcc->{'arg'}) + if ($n eq $gdcc->{'arg'}) #if file already downloaded, emulate an already finished dcc transfer (in case file deleted) and cancel { $gdcc->{'transfd'} = $gdcc->{'size'}; - &ag_closedcc(@_); + $gdcc->{'skipped'} = $gdcc->{'size'}; + &ag_closedcc(@_); } last if ($n eq "$bots[$botcounter] $1"); } } -sub ag_filecomp #save finished downloads +sub ag_skip { - my $filename = @_[0]; - open(finished, ">>", $cachefilename); - print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file - print finished $filename . "\n"; #print name to file - close(finished); - &ag_getfinished; + &ag_remtimeouts; #stop any other skips + $reqpackflag = 0; #allow pack requests now that transfer is finished + if($episodicflag) + { + @packs = (); #delete and reset packlist + $packcounter = 0; + + if ($msgflag) #if the bot replied, then that means there were episodes, but we already have them + { + $episode++; + &ag_search; + } + elsif ($termcounter < $#terms) #otherwise just increment terms or bots + { + $episode = 1; + $formatflag = 1; + $termcounter++; + $packcounter = 0; + &ag_search; + } + elsif ($botcounter < $#bots) + { + $episode = 1; + $formatflag = 1; + $botcounter++; + $termcounter = 0; + $packcounter = 0; + &ag_search; + } + else #if last episode on last search on last bot finished, then resets counters and starts over + { + $episode = 1; + $formatflag = 1; + $botcounter = 0; + $termcounter = 0; + $packcounter = 0; + Irssi::signal_remove("message irc notice", "ag_getmsg"); + Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; + Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + $runningflag = 0; + } + } + elsif ($packcounter < $#packs) + { + $packcounter++; + &ag_search; + } + elsif ($termcounter < $#terms) + { + @packs = (); #delete last terms packlist + $termcounter++; + $packcounter = 0; + &ag_search; + } + elsif ($botcounter < $#bots) + { + @packs = (); #delete last bots packlist + $botcounter++; + $termcounter = 0; + $packcounter = 0; + &ag_search; + } + else #if last pack on last search on last bot finished, then resets counters and starts over + { + $episode = 1; + $formatflag = 1; + @packs = (); #delete last bots packlist + $botcounter = 0; + $termcounter = 0; + $packcounter = 0; + Irssi::signal_remove("message irc notice", "ag_getmsg"); + Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; + Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + $runningflag = 0; + } } -sub ag_closedcc #deals with DCC closes +sub ag_closedcc { my ($dcc) = @_; #current pack my $botname = $dcc->{'nick'}; #get the bots name, and checks if it's the one we want $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname eq $bots[$botcounter]) + + if ($botname eq $bots[$botcounter]) #checks if the is the bot { - Irssi::signal_remove("message irc notice", "ag_getmsg"); if ($dccflag == 0) {Irssi::signal_add("dcc get receive", "ag_opendcc");} #if so, reinits DCC get signal for the next pack $dccflag = 1; - foreach my $to (@totags) #clears timeouts to defuckify everything + + &ag_remtimeouts(); + + if ($dcc->{'skipped'} == $dcc->{'size'}) { - Irssi::timeout_remove($to); + &ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. } - @totags = (); - foreach my $to (@skiptags) #remove timeouts for skipping if a pack has been recieved + if ($dcc->{'transfd'} == $dcc->{'size'}) { - Irssi::timeout_remove($to); + Irssi::print "AG | transfer successful"; + &ag_addfinished($dcc->{'arg'}); } - @skiptags = (); - if ($dcc->{'transfd'} == $dcc->{'size'}){&ag_filecomp($dcc->{'arg'})} - - if($episodeflag and $dcc->{'transfd'} == $dcc->{'size'}) + if($episodicflag and $dcc->{'transfd'} == $dcc->{'size'}) { - $episode++; - $pact = 0; #allow pack requests now that transfer is finished @packs = (); #delete packlist $packcounter = 0; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next episode"; &ag_search(); }, [])); + $episode++; Irssi::print "AG | waiting " . $nexdelay . " seconds"; - if ($dcc->{'skipped'} == $dcc->{'size'}) - { - $server->command("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. - } + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next episode"; &ag_search(); }, [])); } - elsif (!$episodeflag and $dcc->{'transfd'} == $dcc->{'size'}) #checks if the transfer actually ran to completion + elsif ($dcc->{'transfd'} == $dcc->{'size'}) { - Irssi::print "AG | transfer successful"; #if so, does next pack/search/bot (in that order) - if ($dcc->{'skipped'} == $dcc->{'size'}) - { - $server->command("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. - } if ($packcounter < $#packs) { - $pact = 1; #allow pack requests now that transfer is finished - $packcounter += 1; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next pack in list"; &ag_reqpack(); }, [])); - Irssi::print "AG | waiting " . $nexdelay . " seconds"; + $reqpackflag = 0; #allow pack requests now that transfer is finished + $packcounter++; + Irssi::print "AG | Getting next pack in list in " . $nexdelay . " seconds "; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_reqpack(); }, [])); } elsif ($termcounter < $#terms) { - $pact = 0; #allow the system to parse new responses + $reqpackflag = 0; @packs = (); #delete last terms packlist - $termcounter += 1; + $termcounter++; $packcounter = 0; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Packlist finished. Searching next term"; &ag_search(); }, [])); - Irssi::print "AG | waiting " . $nexdelay . " seconds"; + Irssi::print "AG | Packlist finished. Searching next term in " . $nexdelay . " seconds"; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search(); }, [])); } elsif ($botcounter < $#bots) { - $pact = 0; #allow the system to parse new responses + $reqpackflag = 0; @packs = (); #delete last bots packlist - $botcounter += 1; + $botcounter++; $termcounter = 0; $packcounter = 0; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | All searches complete. Searching next bot"; &ag_search(); }, [])); - Irssi::print "AG | waiting " . $nexdelay . " seconds"; + Irssi::print "AG | Search term lidt finished. Searching nect bot in " . $nexdelay . " seconds"; + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search(); }, [])); } else #if last pack on last search on last bot finished, then resets counters and starts over { - $pact = 0; - @packs = (); #delete last bots packlist + $reqpackflag = 0; + @packs = (); $botcounter = 0; $termcounter = 0; $packcounter = 0; @@ -455,11 +464,34 @@ sub ag_closedcc #deals with DCC closes { Irssi::print "AG | transfer failed"; Irssi::print "AG | " . $dcrdelay . " seconds until retry"; - push(@totags, Irssi::timeout_add_once($dcrdelay * 1000, sub { Irssi::print "AG | retrying: " .$bots[$botcounter] . " " . $packs[$packcounter]; &ag_reqpack(); }, [])); + push(@totags, Irssi::timeout_add_once($dcrdelay * 1000, sub { Irssi::print "AG | retrying: " .$bots[$botcounter] . " " . $packs[$packcounter]; &ag_packrequest(); }, [])); } } } +sub ag_message +{ + (my $message) = @_[0]; + if ($server != Irssi::active_server()) {&ag_server;} + $server->command("$message"); +} + +sub ag_uniq #only returns unique entries +{ + my %seen; + grep !$seen{$_}++, @_; +} + +sub ag_addfinished #save finished downloads +{ + my $filename = @_[0]; + open(finished, ">>", $cachefilename); + print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file + print finished $filename . "\n"; #print name to file + close(finished); +} + + sub ag_parseadd #parses add arguments for storage { my ($file, @args) = @_; @@ -586,17 +618,10 @@ sub ag_run #main loop { if($runningflag == 0) { + Irssi::signal_add("message irc notice", "ag_getmsg"); $runningflag = 1; &ag_getbots; - foreach my $n (@bots) - { - Irssi::print "AG | Bots: " . $n; - } &ag_getterms; - foreach my $n (@terms) - { - Irssi::print "AG | Terms: " . $n; - } if($#bots < 0 or $#terms < 0) {Irssi::print "AG | No bots or no search terms added. Halting"; &ag_stop;} else { @@ -609,24 +634,37 @@ sub ag_run #main loop sub ag_stop { + Irssi::signal_remove("dcc get receive", "ag_opendcc"); + Irssi::signal_remove("message irc notice", "ag_getmsg"); + foreach my $to (@totags) { Irssi::timeout_remove($to); } @totags = (); - $server->command("msg $bots[$botcounter] $cancelprefix"); + + &ag_message("msg $bots[$botcounter] $cancelprefix"); + if($runningflag == 1) { $runningflag = 0; Irssi::print "AG | Killed"; } - Irssi::signal_remove("dcc get receive", "ag_opendcc"); - $botcounter = 0; - $termcounter = 0; - $packcounter = 0; - @bots = (); + $msgflag = 1; + $termisepisodicflag = 0; + $formatflag = 1; + $reqpackflag = 0; + $downloadflag = 0; + $newpackflag = 1; + $dccflag = 0; @terms = (); + @bots = (); @packs = (); + @finished = (); + $termcounter = 0; + $botcounter = 0; + $packcounter = 0; + $episode = 1; } sub ag_reset @@ -648,25 +686,9 @@ sub ag_reset Irssi::settings_get_str("ag_xdcc_send_prefix"); Irssi::settings_get_str("ag_xdcc_find_prefix"); Irssi::settings_get_str("ag_folder"); - Irssi::print "AG | all settings reset to default values"; + Irssi::print "AG | All settings reset to default values"; } -#sub ag_setsettings -#{ -# Irssi::settings_set_int("ag_next_delay", $nexdelay); -# Irssi::settings_set_int("ag_dcc_closed_retry_delay", $dcrdelay); -# Irssi::settings_set_int("ag_bot_delay", $botdelay); -# Irssi::settings_set_int("ag_interrun_delay", $exedelay); -# Irssi::settings_set_bool("ag_autorun", $initflag); -# Irssi::settings_set_bool("ag_episodic", $episodeflag); -# Irssi::settings_set_str("ag_xdcc_send_prefix", $sendprefix); -# Irssi::settings_set_str("ag_xdcc_cancel_prefix", $cancelprefix); -# Irssi::settings_set_str("ag_xdcc_find_prefix", $findprefix); -# Irssi::settings_set_str("ag_format", $format); -# Irssi::settings_set_str("ag_bot_file", $botsfilename); -# Irssi::settings_set_str("ag_search_file", $searchesfilename); -#} - open(bots, ">>", $botsfilename); #makes bots, searches, and finished file if they don't exist close(bots); open(searches, ">>", $searchesfilename); @@ -676,7 +698,6 @@ close(finished); if ($initflag) {&ag_init();} Irssi::signal_add("dcc closed", "ag_closedcc"); -#Irssi::signal_add("setup changed", "ag_setsettings"); Irssi::command_bind("ag_help", "ag_help"); Irssi::command_bind("ag_run", "ag_run"); -- cgit v1.2.3 From d4c93f52b6de2675b516f16ab43e4a65c4efd17b Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 6 Nov 2015 13:54:09 -0500 Subject: update --- scripts/xdcc_autoget.pl | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index a4c852f..a6d1b32 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -193,7 +193,7 @@ sub ag_clearcache #clears cache of saved packs sub ag_search #searches bots for packs { - $msgflag = 0; #unset message flag so that ag_skip knows no important message has arrived + $msgflag = 0; #unset message flag so that ag_skip knows no important message has arrived if($episodicflag) #episodic searches are complicated { my $ep = sprintf("%.2d", $episode); @@ -220,6 +220,7 @@ sub ag_search #searches bots for packs &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter]" ); push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); } + Irssi::signal_add("message irc notice", "ag_getmsg"); } sub ag_remtimeouts #remove timeouts to avoid multiple instances of everything @@ -238,7 +239,7 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname == $bots[$botcounter]) #if it's your bot + if ($botname == $bots[$botcounter] and !$msgflag) #if it's your bot { &ag_remtimeouts; #stop any skips from happening &ag_getpacks($message); #and check for any new packs in the message @@ -272,6 +273,7 @@ sub ag_getpacks sub ag_packrequest #sends the xdcc send request, and retries on failure { + &ag_remtimeouts; if (!$reqpackflag) { $reqpackflag = 1; @@ -290,26 +292,28 @@ sub ag_opendcc #runs on DCC recieve init if ($botname eq $bots[$botcounter]) #if it's our bot, let user know, and stop any further AG pack requests until finished { + Irssi::signal_remove("message irc notice", "ag_getmsg"); Irssi::signal_remove("dcc get receive", "ag_opendcc"); #stops any suplicate sends (there should only ever be one) + &ag_remtimeouts; $dccflag = 0; $downloadflag = 1; - &ag_remtimeouts; Irssi::print "AG | received connection for bot: " . $botname . ", #" . $packs[$packcounter]; - } - foreach my $n (@finished) #don't redownload finished packs - { - if ($n eq $gdcc->{'arg'}) #if file already downloaded, emulate an already finished dcc transfer (in case file deleted) and cancel + foreach my $n (@finished) #don't redownload finished packs { - $gdcc->{'transfd'} = $gdcc->{'size'}; - $gdcc->{'skipped'} = $gdcc->{'size'}; - &ag_closedcc(@_); + if ($n eq $gdcc->{'arg'}) #if file already downloaded, emulate an already finished dcc transfer (in case file deleted) and cancel + { + $gdcc->{'transfd'} = $gdcc->{'size'}; + $gdcc->{'skipped'} = $gdcc->{'size'}; + &ag_closedcc(@_); + } + last if ($n eq $gdcc->{'arg'}); } - last if ($n eq "$bots[$botcounter] $1"); } } sub ag_skip { +# Irssi::print "AG | SKIP $msgflag $episodicflag $episode $#packs $packcounter $#terms $termcounter $#bots $botcounter"; &ag_remtimeouts; #stop any other skips $reqpackflag = 0; #allow pack requests now that transfer is finished if($episodicflag) @@ -346,7 +350,6 @@ sub ag_skip $botcounter = 0; $termcounter = 0; $packcounter = 0; - Irssi::signal_remove("message irc notice", "ag_getmsg"); Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); $runningflag = 0; @@ -380,7 +383,6 @@ sub ag_skip $botcounter = 0; $termcounter = 0; $packcounter = 0; - Irssi::signal_remove("message irc notice", "ag_getmsg"); Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); $runningflag = 0; @@ -396,6 +398,7 @@ sub ag_closedcc if ($botname eq $bots[$botcounter]) #checks if the is the bot { + $reqpackflag = 0; if ($dccflag == 0) {Irssi::signal_add("dcc get receive", "ag_opendcc");} #if so, reinits DCC get signal for the next pack $dccflag = 1; @@ -423,14 +426,12 @@ sub ag_closedcc { if ($packcounter < $#packs) { - $reqpackflag = 0; #allow pack requests now that transfer is finished $packcounter++; Irssi::print "AG | Getting next pack in list in " . $nexdelay . " seconds "; push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_reqpack(); }, [])); } elsif ($termcounter < $#terms) { - $reqpackflag = 0; @packs = (); #delete last terms packlist $termcounter++; $packcounter = 0; @@ -439,7 +440,6 @@ sub ag_closedcc } elsif ($botcounter < $#bots) { - $reqpackflag = 0; @packs = (); #delete last bots packlist $botcounter++; $termcounter = 0; @@ -449,12 +449,10 @@ sub ag_closedcc } else #if last pack on last search on last bot finished, then resets counters and starts over { - $reqpackflag = 0; @packs = (); $botcounter = 0; $termcounter = 0; $packcounter = 0; - Irssi::signal_remove("message irc notice", "ag_getmsg"); Irssi::print "AG | Waiting " . $exedelay . " minutes until next search"; Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); $runningflag = 0; @@ -618,7 +616,6 @@ sub ag_run #main loop { if($runningflag == 0) { - Irssi::signal_add("message irc notice", "ag_getmsg"); $runningflag = 1; &ag_getbots; &ag_getterms; -- cgit v1.2.3 From ddd0e807290b3291b17c65a414206fa50975e37d Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Tue, 10 Nov 2015 08:17:31 -0500 Subject: update as per ailin-nemui's request --- scripts/xdcc_autoget.pl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index a6d1b32..309f178 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -234,8 +234,8 @@ sub ag_remtimeouts #remove timeouts to avoid multiple instances of everything sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this from sending useless shit that breaks things { - my $message = @_[1]; - my $botname = @_[2]; + my $message = $_[1]; + my $botname = $_[2]; $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; @@ -469,7 +469,7 @@ sub ag_closedcc sub ag_message { - (my $message) = @_[0]; + (my $message) = $_[0]; if ($server != Irssi::active_server()) {&ag_server;} $server->command("$message"); } @@ -477,12 +477,12 @@ sub ag_message sub ag_uniq #only returns unique entries { my %seen; - grep !$seen{$_}++, @_; + grep !$seen{$_}++, _; } sub ag_addfinished #save finished downloads { - my $filename = @_[0]; + my $filename = $_[0]; open(finished, ">>", $cachefilename); print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file print finished $filename . "\n"; #print name to file @@ -547,7 +547,6 @@ sub ag_parserem #parses remove arguments for deletion from file unlink "$file"; open(temp, "<", "/tmp/temp"); open(searches, ">", $file); - my %hTmp; while (my $sLine = ) #remove duplicate lines { next if $sLine =~ m/^\s*$/; #remove empty lines. Without this, still destroys empty lines except for the first one. @@ -563,7 +562,7 @@ sub ag_parserem #parses remove arguments for deletion from file sub ag_add #add search terms { &ag_server; - my @args = quotewords('\s+', 0, @_[0]); #split arguments (words in brackets not seperated) + my @args = quotewords('\s+', 0, $_[0]); #split arguments (words in brackets not seperated) if ($#args < 0) { Irssi::print "AG | too few arguments"; @@ -576,7 +575,7 @@ sub ag_add #add search terms sub ag_rem #remove ssearch terms { &ag_server; - my @args = quotewords('\s+', 0, @_[0]); + my @args = quotewords('\s+', 0, $_[0]); if ($#args < 0) { Irssi::print "AG | too few arguments"; @@ -589,7 +588,7 @@ sub ag_rem #remove ssearch terms sub ag_botadd #add bots { &ag_server; - my @args = quotewords('\s+', 0, @_[0]); + my @args = quotewords('\s+', 0, $_[0]); if ($#args < 0) { Irssi::print "AG | too few arguments"; @@ -602,7 +601,7 @@ sub ag_botadd #add bots sub ag_botrem #remove bots { &ag_server; - my @args = quotewords('\s+', 0, @_[0]); + my @args = quotewords('\s+', 0, $_[0]); if ($#args < 0) { Irssi::print "AG | too few arguments"; -- cgit v1.2.3 From 78d47a7b7205fe177441127eaf494e2b1d4659b6 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Tue, 10 Nov 2015 08:33:24 -0500 Subject: whoops --- scripts/xdcc_autoget.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 309f178..c9f3445 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -477,7 +477,7 @@ sub ag_message sub ag_uniq #only returns unique entries { my %seen; - grep !$seen{$_}++, _; + grep !$seen{$_}++, $_; } sub ag_addfinished #save finished downloads -- cgit v1.2.3 From 661b5e115b51765e4116169344cb37c0374b25bc Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Tue, 10 Nov 2015 23:26:23 -0500 Subject: more TRAVIS CI fixes --- scripts/xdcc_autoget.pl | 93 +++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 45 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index c9f3445..323f6d5 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -100,7 +100,7 @@ sub ag_init #init system Irssi::print "AG | /ag_help for help"; &ag_initserver; &ag_getbots; - my $m; + my $m = ""; foreach my $n (@bots) { $m = $m . $n . ", "; @@ -124,6 +124,7 @@ sub ag_init #init system sub ag_initserver #init server { + $server = ""; $server = Irssi::active_server(); #keep trying to get server until it works, then continue after 5 seconds if ($server !~ m/^Irssi::Irc::Server=HASH/) {Irssi::timeout_add_once(1000, sub {&ag_initserver;} , []);} else {Irssi::timeout_add_once(5000, sub {&ag_run;} , []);} @@ -169,26 +170,26 @@ sub ag_getbots #reads in bot list sub ag_getterms #reads in search term list { - open(searches, "<", $searchesfilename); - @terms = ; + open(SEARCHES, "<", $searchesfilename); + @terms = ; chomp(@terms); - close(searches); + close(SEARCHES); } sub ag_getfinished #reads in finished packs list { - open(finished, "<", $cachefilename); - @finished = ; + open(FINISHED, "<", $cachefilename); + @finished = ; chomp(@finished); @finished = ag_uniq(@finished); - close(finished); + close(FINISHED); } sub ag_clearcache #clears cache of saved packs { unlink $cachefilename; - open(finished, ">>", $cachefilename); - close(finished); + open(FINISHED, ">>", $cachefilename); + close(FINISHED); } sub ag_search #searches bots for packs @@ -477,86 +478,87 @@ sub ag_message sub ag_uniq #only returns unique entries { my %seen; - grep !$seen{$_}++, $_; + grep !$seen{$_}++, @_; } sub ag_addfinished #save finished downloads { my $filename = $_[0]; - open(finished, ">>", $cachefilename); - print finished $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file - print finished $filename . "\n"; #print name to file - close(finished); + open(FINISHED, ">>", $cachefilename); + print FINISHED $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file + print FINISHED $filename . "\n"; #print name to file + close(FINISHED); } sub ag_parseadd #parses add arguments for storage { my ($file, @args) = @_; - open(file, ">>", $file); + open(FILE, ">>", $file); foreach my $arg (@args) { - print file $arg . "\n"; #print to file + print FILE $arg . "\n"; #print to file } - close(file); - copy($file, "/tmp/temp") or die "COPY FAILED"; #copy to temp file so that duplicate lines [searches/bots] can be removed + close(FILE); + copy($file, "/tmp/temp") or croak "COPY FAILED"; #copy to temp file so that duplicate lines [searches/bots] can be removed unlink "$file"; - open(temp, "<", "/tmp/temp"); - open(file, ">", $file); + open(TEMP, "<", "/tmp/temp"); + open(FILE, ">", $file); my %hTmp; - while (my $sLine = ) #remove duplicate lines + while (my $sLine = ) #remove duplicate lines { next if $sLine =~ m/^\s*$/; #remove empty lines. Without this, still destroys empty lines except for the first one. $sLine=~s/^\s+//; #strip leading/trailing whitespace $sLine=~s/\s+$//; - print file qq{$sLine\n} unless ($hTmp{$sLine}++); + print FILE qq{$sLine\n} unless ($hTmp{$sLine}++); } unlink "/tmp/temp"; - close(file); + close(FILE); } sub ag_parserem #parses remove arguments for deletion from file { my ($file, @args) = @_; - open(temp, ">>", "/tmp/temp"); + open(TEMP, ">>", "/tmp/temp"); foreach my $arg (@args) { Irssi::print "AG | removing term: " . $arg; - print temp $arg . "\n"; + print TEMP $arg . "\n"; } - close(temp); - open(temp2, ">", "/tmp/temp2"); - open(file, "<", $file); + close(TEMP); + open(TEMP2, ">", "/tmp/temp2"); + open(FILE, "<", $file); my %hTmp; - while( my $fileLine = file->getline() ) #get each entry already stored + while( my $fileLine = FILE->getline() ) #get each entry already stored { - open(temp, "<", "/tmp/temp"); - while( my $tempLine = temp->getline() ) + open(TEMP, "<", "/tmp/temp"); + while( my $tempLine = TEMP->getline() ) { if ($fileLine eq $tempLine) #if entry in file and arguments { $hTmp{$fileLine}++; #set flag to not copy } - print temp2 qq{$fileLine} unless $hTmp{$fileLine}; #copy other lines to other temp file + print TEMP2 qq{$fileLine} unless $hTmp{$fileLine}; #copy other lines to other temp file } - close(temp); + close(TEMP); } - close(temp2); - copy("/tmp/temp2", $file) or die "COPY FAILED"; #rewrite old file - copy($file, "/tmp/temp") or die "COPY FAILED"; + close(TEMP2); + copy("/tmp/temp2", $file) or croak "COPY FAILED"; #rewrite old file + copy($file, "/tmp/temp") or croak "COPY FAILED"; unlink "$file"; - open(temp, "<", "/tmp/temp"); - open(searches, ">", $file); - while (my $sLine = ) #remove duplicate lines + open(TEMP, "<", "/tmp/temp"); + open(SEARCHES, ">", $file); + %hTmp = (); + while (my $sLine = ) #remove duplicate lines { next if $sLine =~ m/^\s*$/; #remove empty lines. Without this, still destroys empty lines except for the first one. $sLine=~s/^\s+//; #strip leading/trailing whitespace $sLine=~s/\s+$//; - print file qq{$sLine\n} unless ($hTmp{$sLine}++); + print FILE qq{$sLine\n} unless ($hTmp{$sLine}++); } unlink "/tmp/temp"; unlink "/tmp/temp2"; - close(file); + close(FILE); } sub ag_add #add search terms @@ -687,10 +689,10 @@ sub ag_reset open(bots, ">>", $botsfilename); #makes bots, searches, and finished file if they don't exist close(bots); -open(searches, ">>", $searchesfilename); -close(searches); -open(finished, ">>", $cachefilename); -close(finished); +open(SEARCHES, ">>", $searchesfilename); +close(SEARCHES); +open(FINISHED, ">>", $cachefilename); +close(FINISHED); if ($initflag) {&ag_init();} Irssi::signal_add("dcc closed", "ag_closedcc"); @@ -705,3 +707,4 @@ Irssi::command_bind("ag_botadd", "ag_botadd"); Irssi::command_bind("ag_botrem", "ag_botrem"); Irssi::command_bind("ag_clearcache", "ag_clearcache"); + -- cgit v1.2.3 From f97abc0ca55bb826820344614e1951caede45be7 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Tue, 10 Nov 2015 23:37:13 -0500 Subject: more TRAVIS CI fixes --- scripts/xdcc_autoget.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 323f6d5..c097b1e 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -500,7 +500,7 @@ sub ag_parseadd #parses add arguments for storage print FILE $arg . "\n"; #print to file } close(FILE); - copy($file, "/tmp/temp") or croak "COPY FAILED"; #copy to temp file so that duplicate lines [searches/bots] can be removed + copy($file, "/tmp/temp"); #copy to temp file so that duplicate lines [searches/bots] can be removed unlink "$file"; open(TEMP, "<", "/tmp/temp"); open(FILE, ">", $file); @@ -543,8 +543,8 @@ sub ag_parserem #parses remove arguments for deletion from file close(TEMP); } close(TEMP2); - copy("/tmp/temp2", $file) or croak "COPY FAILED"; #rewrite old file - copy($file, "/tmp/temp") or croak "COPY FAILED"; + copy("/tmp/temp2", $file); #rewrite old file + copy($file, "/tmp/temp"); unlink "$file"; open(TEMP, "<", "/tmp/temp"); open(SEARCHES, ">", $file); -- cgit v1.2.3 From 19666a6a5d55b6248d82e84d15d16567a1d02063 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Tue, 10 Nov 2015 23:47:53 -0500 Subject: ever more TRAVIS CI fixes --- scripts/xdcc_autoget.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index c097b1e..1cf52b9 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -23,6 +23,7 @@ # ag_search_file : where your search list is stored use strict; +use warnings; use Irssi; use Text::ParseWords; @@ -124,7 +125,7 @@ sub ag_init #init system sub ag_initserver #init server { - $server = ""; + $server = " "; $server = Irssi::active_server(); #keep trying to get server until it works, then continue after 5 seconds if ($server !~ m/^Irssi::Irc::Server=HASH/) {Irssi::timeout_add_once(1000, sub {&ag_initserver;} , []);} else {Irssi::timeout_add_once(5000, sub {&ag_run;} , []);} -- cgit v1.2.3 From c4bbd71d0af08ee4301648b5459bfec43ffc81fc Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Wed, 11 Nov 2015 15:26:54 -0500 Subject: changes as per suggestions --- scripts/xdcc_autoget.pl | 184 ++++++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 84 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 1cf52b9..0409666 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -4,14 +4,15 @@ # if you encounter any problems, fix it yourself you lazy bastard (or get me to), then contact me so I can add your fix and bump that version # # BeerWare License. Use any part you want, but buy me a beer if you ever meet me and liked this hacked together broken PoS # Somewhat based off of DCC multiget by Kaveh Moini. -# USE: for help : ag_help -# to run : ag_run -# to halt at next : ag_stop -# to set the server: ag_server -# to add a bot : ag_botadd BOT1 BOT2 *** BOTN -# to remove a bot : ag_botrem BOT1 BOT2 *** BOTN -# to add string : ag_add "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" -# to remove strings: ag_rem "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" +# USE: for help : ag_help +# to run : ag_run +# to halt at next : ag_stop +# to reset all settings: ag_reset +# to set the server : ag_server +# to add a bot : ag_botadd BOT1 BOT2 *** BOTN +# to remove a bot : ag_botrem BOT1 BOT2 *** BOTN +# to add string : ag_add "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" +# to remove strings : ag_rem "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" # ag_next_delay : delay between full transfers # ag_dcc_closed_retry_delay : delay after premature transfer # ag_bot_delay: delay between request and when you "SHOULD" get it @@ -57,26 +58,29 @@ Irssi::settings_add_str($IRSSI{'name'}, "ag_folder", File::HomeDir->my_home); my @totags = (); #timeout tags (need to be purged between send requests maybe) -my $nexdelay = Irssi::settings_get_int("ag_next_delay"); #delay for next pack -my $dcrdelay = Irssi::settings_get_int("ag_dcc_closed_retry_delay"); #delay if transfer closed prematurely -my $botdelay = Irssi::settings_get_int("ag_bot_delay"); #max time to wait for the bot to respond -my $exedelay = Irssi::settings_get_int("ag_interrun_delay"); #delay (in minutes) between finishing one run and starting another - -my $initflag = Irssi::settings_get_bool("ag_autorun"); #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD -my $runningflag = 0; #flag keeps ag from running more than one instance of itself at a time -my $msgflag = 1; #flag controls whether bot has responded to search request -my $termisepisodicflag = 0; #flag controls whether -my $episodicflag = Irssi::settings_get_bool("ag_episodic"); #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) -my $formatflag = 1; #flag controls whether a format is appended to the end of an episodic search string -my $reqpackflag = 0; #flag to avoid multiple download requests -my $downloadflag = 0; #flag to avoid multiple download requests +my $nexdelay; #delay for next pack +my $dcrdelay; #delay if transfer closed prematurely +my $botdelay; #max time to wait for the bot to respond +my $exedelay; #delay (in minutes) between finishing one run and starting another + +my $initflag; #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD +my $runningflag = 0; #flag keeps ag from running more than one instance of itself at a time +my $msgflag = 1; #flag controls whether bot has responded to search request +my $termisepisodicflag = 0; #flag controls whether +my $episodicflag; #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) +my $formatflag = 1; #flag controls whether a format is appended to the end of an episodic search string +my $reqpackflag = 0; #flag to avoid multiple download requests +my $downloadflag = 0; #flag to avoid multiple download requests my $newpackflag = 1; -my $sendprefix = Irssi::settings_get_str("ag_xdcc_send_prefix"); #virtually universal xdcc send, cancel, and find prefixes -my $cancelprefix = Irssi::settings_get_str("ag_xdcc_cancel_prefix"); -my $findprefix = Irssi::settings_get_str("ag_find_prefix"); -my $format = Irssi::settings_get_str("ag_format"); #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc -my $folder = Irssi::settings_get_str("ag_folder"); +my $sendprefix; #virtually universal xdcc send, cancel, and find prefixes +my $cancelprefix; +my $findprefix; +my $format; #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc +my $folder; + +&ag_setsettings; + my $botsfilename = $folder . "/bots.txt"; my $searchesfilename = $folder . "/searches.txt"; my $cachefilename = $folder . "/cache.txt"; @@ -125,23 +129,23 @@ sub ag_init #init system sub ag_initserver #init server { - $server = " "; $server = Irssi::active_server(); #keep trying to get server until it works, then continue after 5 seconds - if ($server !~ m/^Irssi::Irc::Server=HASH/) {Irssi::timeout_add_once(1000, sub {&ag_initserver;} , []);} + if (ref $server && $server->isa("Irssi::Irc::Server")) {Irssi::timeout_add_once(1000, sub {&ag_initserver;} , []);} else {Irssi::timeout_add_once(5000, sub {&ag_run;} , []);} } sub ag_help { - Irssi::print "for this help : ag_help"; - Irssi::print "to run : ag_run"; - Irssi::print "to halt at next : ag_stop"; - Irssi::print "to set the server: ag_server"; - Irssi::print "to add a bot : ag_botadd BOT1 BOT2 *** BOTN"; - Irssi::print "to remove a bot : ag_botrem BOT1 BOT2 *** BOTN"; - Irssi::print "to add string : ag_add \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; - Irssi::print "to remove strings: ag_rem \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; - Irssi::print "to clear cache : ag_clearcache"; + Irssi::print "for this help : ag_help"; + Irssi::print "to run : ag_run"; + Irssi::print "to halt at next : ag_stop"; + Irssi::print "to reset all settings: ag_reset"; + Irssi::print "to set the server : ag_server"; + Irssi::print "to add a bot : ag_botadd BOT1 BOT2 *** BOTN"; + Irssi::print "to remove a bot : ag_botrem BOT1 BOT2 *** BOTN"; + Irssi::print "to add string : ag_add \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; + Irssi::print "to remove strings : ag_rem \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; + Irssi::print "to clear cache : ag_clearcache"; Irssi::print "ag_next_delay : delay between full transfers"; Irssi::print "ag_dcc_closed_retry_delay: delay after premature transfer"; Irssi::print "ag_bot_delay : max time to wait for the bot to respond"; @@ -158,15 +162,15 @@ sub ag_help sub ag_server #sets the current server { $server = Irssi::active_server(); #keep trying to get server until it works - if ($server !~ m/^Irssi::Irc::Server=HASH/) {Irssi::timeout_add_once(1000, sub {&ag_server;} , []);} + if (ref $server && $server->isa("Irssi::Irc::Server=HASH")) {Irssi::timeout_add_once(1000, sub {&ag_server;} , []);} } sub ag_getbots #reads in bot list { - open(bots, "<", $botsfilename); - @bots = ; + open(BOTS, "<", $botsfilename); + @bots = ; chomp(@bots); - close(bots); + close(BOTS); } sub ag_getterms #reads in search term list @@ -201,7 +205,7 @@ sub ag_search #searches bots for packs my $ep = sprintf("%.2d", $episode); if ($format ne "" and $formatflag) { - &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format"); #first search with format + ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format"); #first search with format if ($episode == 1) { push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { $formatflag = 0; &ag_search; } , [])); #if no formated version found, try again with just the search string + ep# @@ -213,13 +217,13 @@ sub ag_search #searches bots for packs } else { - &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); + ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); } } else #if not episodic, just search and skip { - &ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter]" ); + ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter]" ); push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); } Irssi::signal_add("message irc notice", "ag_getmsg"); @@ -241,10 +245,10 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this $botname =~ tr/[A-Z]/[a-z]/; $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname == $bots[$botcounter] and !$msgflag) #if it's your bot + if ($botname eq $bots[$botcounter] and !$msgflag) #if it's your bot { &ag_remtimeouts; #stop any skips from happening - &ag_getpacks($message); #and check for any new packs in the message + ag_getpacks($message); #and check for any new packs in the message if ($#packs < 0) { push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip; } , [])); } #set up only one possible skip per search if($#packs >= 0){ &ag_packrequest; } #if there are any packs, $msgflag = 1; #let everyone know that the current bot has replied @@ -280,8 +284,8 @@ sub ag_packrequest #sends the xdcc send request, and retries on failure { $reqpackflag = 1; Irssi::signal_add("dcc get receive", "ag_opendcc"); #init DCC recieve init flag - &ag_message("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag) { Irssi::print "AG | Connection failed"; Irssi::print "AG | retrying: " . $bots[$botcounter] . " " .$packs[$packcounter]; &ag_packrequest(); } } , [])); + ag_message("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); + push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag) { Irssi::print "AG | Connection failed"; Irssi::print "AG | retrying: " . $bots[$botcounter] . " " .$packs[$packcounter]; &ag_packrequest; } } , [])); } } @@ -306,7 +310,7 @@ sub ag_opendcc #runs on DCC recieve init { $gdcc->{'transfd'} = $gdcc->{'size'}; $gdcc->{'skipped'} = $gdcc->{'size'}; - &ag_closedcc(@_); + ag_closedcc(@_); } last if ($n eq $gdcc->{'arg'}); } @@ -404,16 +408,16 @@ sub ag_closedcc if ($dccflag == 0) {Irssi::signal_add("dcc get receive", "ag_opendcc");} #if so, reinits DCC get signal for the next pack $dccflag = 1; - &ag_remtimeouts(); + &ag_remtimeouts; if ($dcc->{'skipped'} == $dcc->{'size'}) { - &ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. + ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. } if ($dcc->{'transfd'} == $dcc->{'size'}) { Irssi::print "AG | transfer successful"; - &ag_addfinished($dcc->{'arg'}); + ag_addfinished($dcc->{'arg'}); } if($episodicflag and $dcc->{'transfd'} == $dcc->{'size'}) @@ -422,7 +426,7 @@ sub ag_closedcc $packcounter = 0; $episode++; Irssi::print "AG | waiting " . $nexdelay . " seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next episode"; &ag_search(); }, [])); + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { Irssi::print "AG | Getting next episode"; &ag_search; }, [])); } elsif ($dcc->{'transfd'} == $dcc->{'size'}) { @@ -430,7 +434,7 @@ sub ag_closedcc { $packcounter++; Irssi::print "AG | Getting next pack in list in " . $nexdelay . " seconds "; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_reqpack(); }, [])); + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_reqpack; }, [])); } elsif ($termcounter < $#terms) { @@ -438,7 +442,7 @@ sub ag_closedcc $termcounter++; $packcounter = 0; Irssi::print "AG | Packlist finished. Searching next term in " . $nexdelay . " seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search(); }, [])); + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search; }, [])); } elsif ($botcounter < $#bots) { @@ -447,7 +451,7 @@ sub ag_closedcc $termcounter = 0; $packcounter = 0; Irssi::print "AG | Search term lidt finished. Searching nect bot in " . $nexdelay . " seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search(); }, [])); + push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search; }, [])); } else #if last pack on last search on last bot finished, then resets counters and starts over { @@ -464,7 +468,7 @@ sub ag_closedcc { Irssi::print "AG | transfer failed"; Irssi::print "AG | " . $dcrdelay . " seconds until retry"; - push(@totags, Irssi::timeout_add_once($dcrdelay * 1000, sub { Irssi::print "AG | retrying: " .$bots[$botcounter] . " " . $packs[$packcounter]; &ag_packrequest(); }, [])); + push(@totags, Irssi::timeout_add_once($dcrdelay * 1000, sub { Irssi::print "AG | retrying: " .$bots[$botcounter] . " " . $packs[$packcounter]; &ag_packrequest; }, [])); } } } @@ -472,7 +476,7 @@ sub ag_closedcc sub ag_message { (my $message) = $_[0]; - if ($server != Irssi::active_server()) {&ag_server;} + if (!(ref $server) || !($server->isa(Irssi::active_server()))) {&ag_server;} $server->command("$message"); } @@ -572,7 +576,7 @@ sub ag_add #add search terms Irssi::print "AG | usage: ag_add "; return; } - &ag_parseadd($searchesfilename, @args); + ag_parseadd($searchesfilename, @args); } sub ag_rem #remove ssearch terms @@ -585,7 +589,7 @@ sub ag_rem #remove ssearch terms Irssi::print "AG | usage: ag_rem "; return; } - &ag_parserem($searchesfilename, @args); + ag_parserem($searchesfilename, @args); } sub ag_botadd #add bots @@ -598,7 +602,7 @@ sub ag_botadd #add bots Irssi::print "AG | usage: ag_botsadd "; return; } - &ag_parseadd($botsfilename, @args); + ag_parseadd($botsfilename, @args); } sub ag_botrem #remove bots @@ -611,7 +615,7 @@ sub ag_botrem #remove bots Irssi::print "AG | usage: ag_rem "; return; } - &ag_parserem($botsfilename, @args); + ag_parserem($botsfilename, @args); } sub ag_run #main loop @@ -642,7 +646,7 @@ sub ag_stop } @totags = (); - &ag_message("msg $bots[$botcounter] $cancelprefix"); + ag_message("msg $bots[$botcounter] $cancelprefix"); if($runningflag == 1) { @@ -668,39 +672,51 @@ sub ag_stop sub ag_reset { - my $nexdelay = 5; - my $dcrdelay = 10; - my $botdelay = 30; - my $exedelay = 15; - my $initflag = 1; - my $sendprefix = "xdcc send"; - my $findprefix = "!find"; - my $folder = File::HomeDir->my_home; - - Irssi::settings_get_int("ag_next_delay"); - Irssi::settings_get_int("ag_dcc_closed_retry_delay"); - Irssi::settings_get_int("ag_bot_delay"); - Irssi::settings_get_int("ag_interrun_delay"); - Irssi::settings_get_bool("ag_autorun"); - Irssi::settings_get_str("ag_xdcc_send_prefix"); - Irssi::settings_get_str("ag_xdcc_find_prefix"); - Irssi::settings_get_str("ag_folder"); - Irssi::print "AG | All settings reset to default values"; + Irssi::settings_set_int("ag_next_delay", 10); + Irssi::settings_set_int("ag_dcc_closed_retry_delay", 10); + Irssi::settings_set_int("ag_bot_delay", 30); + Irssi::settings_set_int("ag_interrun_delay", 15); + Irssi::settings_set_bool("ag_autorun", 1); + Irssi::settings_set_bool("ag_episodic", 0); + Irssi::settings_set_str("ag_xdcc_send_prefix", "xdcc send"); + Irssi::settings_set_str("ag_xdcc_cancel_prefix", "xdcc cancel"); + Irssi::settings_set_str("ag_find_prefix", "!find"); + Irssi::settings_set_str("ag_format", ""); + Irssi::settings_set_str("ag_folder", File::HomeDir->my_home); + &ag_setettings; } -open(bots, ">>", $botsfilename); #makes bots, searches, and finished file if they don't exist -close(bots); +sub ag_setsettings +{ + $nexdelay = Irssi::settings_get_int("ag_next_delay"); + $dcrdelay = Irssi::settings_get_int("ag_dcc_closed_retry_delay"); + $botdelay = Irssi::settings_get_int("ag_bot_delay"); + $exedelay = Irssi::settings_get_int("ag_interrun_delay"); + $initflag = Irssi::settings_get_bool("ag_autorun"); + $episodicflag = Irssi::settings_get_bool("ag_episodic"); + $sendprefix = Irssi::settings_get_str("ag_xdcc_send_prefix"); + $cancelprefix = Irssi::settings_get_str("ag_xdcc_cancel_prefix"); + $findprefix = Irssi::settings_get_str("ag_find_prefix"); + $format = Irssi::settings_get_str("ag_format"); + $folder = Irssi::settings_get_str("ag_folder"); +} + +open(BOTS, ">>", $botsfilename); #makes bots, searches, and finished file if they don't exist +close(BOTS); open(SEARCHES, ">>", $searchesfilename); close(SEARCHES); open(FINISHED, ">>", $cachefilename); close(FINISHED); -if ($initflag) {&ag_init();} + +if ($initflag) {&ag_init;} Irssi::signal_add("dcc closed", "ag_closedcc"); +Irssi::signal_add("setup changed", "ag_setsettings"); Irssi::command_bind("ag_help", "ag_help"); Irssi::command_bind("ag_run", "ag_run"); Irssi::command_bind("ag_stop", "ag_stop"); +Irssi::command_bind("ag_reset", "ag_reset"); Irssi::command_bind("ag_server", "ag_server"); Irssi::command_bind("ag_add", "ag_add"); Irssi::command_bind("ag_rem", "ag_rem"); -- cgit v1.2.3 From 1b4bb8d4c440e928b1f3a2dbc6c69b6889b13c4e Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 13 Nov 2015 14:35:56 -0500 Subject: rework server initialization --- scripts/xdcc_autoget.pl | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 0409666..4f5050e 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -103,7 +103,6 @@ sub ag_init #init system { Irssi::print "AG | Autoget initiated"; Irssi::print "AG | /ag_help for help"; - &ag_initserver; &ag_getbots; my $m = ""; foreach my $n (@bots) @@ -127,11 +126,11 @@ sub ag_init #init system Irssi::print "AG | Data folder: $folder"; } -sub ag_initserver #init server +sub ag_server #init server { - $server = Irssi::active_server(); #keep trying to get server until it works, then continue after 5 seconds - if (ref $server && $server->isa("Irssi::Irc::Server")) {Irssi::timeout_add_once(1000, sub {&ag_initserver;} , []);} - else {Irssi::timeout_add_once(5000, sub {&ag_run;} , []);} + Irssi::signal_remove("server connected", "ag_server"); + $server = $_[0]; + if ($initflag and !$runningflag) {push(@totags, Irssi::timeout_add_once(5000, sub { &ag_run; }, []));} } sub ag_help @@ -159,12 +158,6 @@ sub ag_help Irssi::print "ag_folder : Location for data files. ~/.irssi/ reccomended"; } -sub ag_server #sets the current server -{ - $server = Irssi::active_server(); #keep trying to get server until it works - if (ref $server && $server->isa("Irssi::Irc::Server=HASH")) {Irssi::timeout_add_once(1000, sub {&ag_server;} , []);} -} - sub ag_getbots #reads in bot list { open(BOTS, "<", $botsfilename); @@ -476,7 +469,6 @@ sub ag_closedcc sub ag_message { (my $message) = $_[0]; - if (!(ref $server) || !($server->isa(Irssi::active_server()))) {&ag_server;} $server->command("$message"); } @@ -620,11 +612,10 @@ sub ag_botrem #remove bots sub ag_run #main loop { + if (!$initflag) {ag_server(Irssi::active_server());} if($runningflag == 0) { $runningflag = 1; - &ag_getbots; - &ag_getterms; if($#bots < 0 or $#terms < 0) {Irssi::print "AG | No bots or no search terms added. Halting"; &ag_stop;} else { @@ -708,7 +699,8 @@ close(SEARCHES); open(FINISHED, ">>", $cachefilename); close(FINISHED); -if ($initflag) {&ag_init;} +&ag_init; +Irssi::signal_add("server connected", "ag_server"); Irssi::signal_add("dcc closed", "ag_closedcc"); Irssi::signal_add("setup changed", "ag_setsettings"); @@ -724,4 +716,3 @@ Irssi::command_bind("ag_botadd", "ag_botadd"); Irssi::command_bind("ag_botrem", "ag_botrem"); Irssi::command_bind("ag_clearcache", "ag_clearcache"); - -- cgit v1.2.3 From 1d82f6ec9c2ac3289ac696eafefb1d22c57dd085 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 13 Nov 2015 14:39:50 -0500 Subject: minor fix --- scripts/xdcc_autoget.pl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 4f5050e..b7cef39 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -126,11 +126,16 @@ sub ag_init #init system Irssi::print "AG | Data folder: $folder"; } -sub ag_server #init server +sub ag_initserver #init server { Irssi::signal_remove("server connected", "ag_server"); $server = $_[0]; - if ($initflag and !$runningflag) {push(@totags, Irssi::timeout_add_once(5000, sub { &ag_run; }, []));} + if (!$runningflag) {push(@totags, Irssi::timeout_add_once(5000, sub { &ag_run; }, []));} +} + +sub ag_server #init server +{ + $server = Irssi::active_server(); } sub ag_help @@ -700,7 +705,7 @@ open(FINISHED, ">>", $cachefilename); close(FINISHED); &ag_init; -Irssi::signal_add("server connected", "ag_server"); +if ($initflag) {Irssi::signal_add("server connected", "ag_initserver");} Irssi::signal_add("dcc closed", "ag_closedcc"); Irssi::signal_add("setup changed", "ag_setsettings"); -- cgit v1.2.3