Last active
May 3, 2022 00:57
-
-
Save qgustavor/d75f8cee3be8e0647682 to your computer and use it in GitHub Desktop.
HexChat addon for XDCC download automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import hexchat | |
__module_name__ = "AutoDown" | |
__module_version__ = "0.1" | |
__module_description__ = "Automates XDCC downloads" | |
print("\0034", __module_name__, __module_version__, " is loaded\003") | |
# dcc_queue is organized in this way: | |
# {'bot-1': [1, 2, 3], 'bot-2': [1, 2, 3]} | |
# where the numbers are the pack numbers | |
dcc_queue = {} | |
def autodown(word, word_eol, userdata): | |
if len(word) < 3: | |
hexchat.command('help autodown') | |
else: | |
# add packs to queue | |
if word[1] in dcc_queue and len(dcc_queue[word[1]]) > 0: | |
hexchat.prnt('Packs added to queue') | |
dcc_queue[word[1]] = set(dcc_queue[word[1]] + parse_range(word_eol[2])) | |
else: | |
hexchat.prnt('Downloads started') | |
dcc_queue[word[1]] = parse_range(word_eol[2]) | |
process_queue(word[1]) | |
return hexchat.EAT_ALL | |
def autodown_cancel(word, word_eol, userdata): | |
if len(word) < 2: | |
dcc_queue = {} | |
hexchat.prnt('All downloads cancelled') | |
else: | |
# add packs to queue | |
if word[1] in dcc_queue and len(dcc_queue[word[1]]) > 0: | |
dcc_queue[word[1]] = set() | |
hexchat.prnt("Downloads cancelled for {}".format(word[1])) | |
return hexchat.EAT_ALL | |
def process_queue(bot): | |
if bot in dcc_queue and len(dcc_queue[bot]) > 0: | |
hexchat.command("msg {} xdcc send #{}".format(bot, dcc_queue[bot][0])) | |
def completed_xdcc(word, word_eol, userdata): | |
del dcc_queue[word[1]][0] | |
process_queue(word[1]) | |
def completed_xdcc_recv(word, word_eol, userdata): | |
del dcc_queue[word[2]][0] | |
process_queue(word[2]) | |
def parse_range(astr): | |
result = set() | |
for part in astr.split(','): | |
x = part.split('-') | |
result.update(range(int(x[0]), int(x[-1])+1)) | |
return sorted(result) | |
def unload_cb(userdata): | |
print(__module_name__, 'version', __module_version__, 'unloaded.') | |
hexchat.hook_command("autodown", autodown, help="autodown <bot> <pack 1> ([pack 2]...) Automate XDCC downloads") | |
hexchat.hook_command("autodown_cancel", autodown_cancel, help="autodown_cancel [bot] Cancel automated XDCC downloads") | |
hexchat.hook_print("DCC SEND Complete", completed_xdcc) | |
hexchat.hook_print("DCC SEND Failed", completed_xdcc) | |
hexchat.hook_print("DCC SEND Abort", completed_xdcc) | |
hexchat.hook_print("DCC RECV Complete", completed_xdcc_recv) | |
hexchat.hook_print("DCC RECV Failed", completed_xdcc_recv) | |
hexchat.hook_print("DCC RECV Abort", completed_xdcc) # same arguments as DCC SEND | |
hexchat.hook_unload(unload_cb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment