diff --git a/lurklite/core.py b/lurklite/core.py index 1154d7c..3c11368 100644 --- a/lurklite/core.py +++ b/lurklite/core.py @@ -3,12 +3,12 @@ # lurklite core # -import os, miniirc, re, sys, time +import concurrent.futures, os, miniirc, re, sys, time import lurklite.tempcmds as tempcmds static_cmds = None # The version -miniirc.version = f'lurklite v0.4.19 (powered by {miniirc.version})' +miniirc.version = f'lurklite v0.4.20 (powered by {miniirc.version})' # Throw errors class BotError(Exception): @@ -209,6 +209,8 @@ def __init__(self, config, *, debug=False): self.disable_yay = self._conf_bool('core', 'disable_yay') self.disable_ouch = self._conf_bool('core', 'disable_ouch') + thread_pool = concurrent.futures.ThreadPoolExecutor(32) + # Get the IRC servers to connect to _servers = {} kwargs = None @@ -238,7 +240,7 @@ def __init__(self, config, *, debug=False): # Create the IRC object irc = miniirc.IRC(c['ip'], int(c['port']), c['nick'], c['channels'].split(','), auto_connect=False, - debug=debug, **kwargs) + debug=debug, executor=thread_pool, **kwargs) _servers[section] = irc # Add the ignores list @@ -265,7 +267,7 @@ def __init__(self, config, *, debug=False): # Create the Discord object irc = miniirc_discord.Discord(c['token'], 0, - c.get('nick', '???'), debug=debug, **kw) + c.get('nick', '???'), debug=debug, executor=thread_pool, **kw) _servers['Discord'] = irc # Add the ignores list @@ -284,7 +286,5 @@ def __init__(self, config, *, debug=False): f'{exc.__class__.__name__}: {exc}') irc.debug('Finished connecting to servers!') -# miniirc update reminderâ„¢ -assert miniirc.ver >= (1,4,0), 'lurklite requires miniirc >= v1.4.0!' -if miniirc.ver < (1,6,2): - print('You are not running the latest version of miniircâ„¢.') +# Ensure miniirc isn't outdated +assert miniirc.ver >= (1,7,0), 'lurklite requires miniirc >= v1.7.0!' diff --git a/lurklite/tempcmds.py b/lurklite/tempcmds.py index b8cc59e..3ae12a4 100644 --- a/lurklite/tempcmds.py +++ b/lurklite/tempcmds.py @@ -301,7 +301,8 @@ def _command_url(irc, hostmask, channel, code, args): code = code.format(*[web_quote(a) for a in args], args = web_quote(' '.join(args)), nick = web_quote(hostmask[0])) - data = urllib.request.urlopen(code).read().decode('utf-8', 'replace') + with urllib.request.urlopen(code, timeout=5) as res: + data = res.read().decode('utf-8', 'replace') while data[-1:] in '\r\n': data = data[:-1] diff --git a/setup.py b/setup.py index b50be2d..499feb7 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name = 'lurklite', - version = '0.4.19', + version = '0.4.20', packages = ['lurklite'], author = 'luk3yx', description = 'A miniirc-based IRC bot.', @@ -18,7 +18,7 @@ long_description = desc, long_description_content_type = 'text/markdown', - install_requires = ['miniirc>=1.4.0', 'msgpack'], + install_requires = ['miniirc>=1.7.0', 'msgpack'], python_requires = '>=3.6', classifiers = [