diff --git a/common.py b/common.py index 76ea594..16a1e34 100644 --- a/common.py +++ b/common.py @@ -5,7 +5,7 @@ if '__main__' == __name__: print('''this is a library file, which is not meant to be executed''') exit(-1) -import sys, os, time, pickle +import sys, time, pickle from local_config import conf RATE_GLOBAL = 0x01 diff --git a/plugins.py b/plugins.py index 16f27b4..a18b375 100644 --- a/plugins.py +++ b/plugins.py @@ -125,7 +125,7 @@ def data_parse_other(msg_obj): elif 'reply_user' == a: args['reply_user'] = reply_user else: - logger('warn', 'unknown required arg for %s: %s' %(p['name'], a)) + logger('warn', 'unknown required arg for %s: %s' % (p['name'], a)) ret = p['func'](args) @@ -187,7 +187,7 @@ def command_help(args): if cmd == p['name']: logger('plugin', 'sent help for %s' % cmd) return { - 'msg': args['reply_user'] + ': help for %s: %s' %(cmd, p['desc']) + 'msg': args['reply_user'] + ': help for %s: %s' % (cmd, p['desc']) } @@ -281,7 +281,7 @@ def command_dice(args): dice_char = ['◇', '⚀', '⚁', '⚂', '⚃', '⚄', '⚅'] return { - 'msg': 'rolling a dice for %s: %s (%d)' %(args['reply_user'], dice_char[rnd], rnd) + 'msg': 'rolling a dice for %s: %s (%d)' % (args['reply_user'], dice_char[rnd], rnd) } def command_uptime(args): @@ -305,7 +305,7 @@ def command_uptime(args): logger('plugin', 'sent statistics') return { - 'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' %(u, plural_uptime, conf('request_counter'), plural_request)) + 'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' % (u, plural_uptime, conf('request_counter'), plural_request)) } def command_ping(args): @@ -345,7 +345,7 @@ def command_info(args): if 'info' in args['data']: logger('plugin', 'sent long info') return { - 'msg': args['reply_user'] + (''': I'm a bot, my job is to extract tags from posted URLs. In case I'm annoying or for further questions, please talk to my master %s. I'm rate limited and shouldn't post more than %d messages per %d seconds. To make me exit immediately, highlight me with 'hangup' in the message (emergency only, please). For other commands, highlight me with 'command'.''' %(conf('bot_owner'), conf('hist_max_count'), conf('hist_max_time'))) + 'msg': args['reply_user'] + (''': I'm a bot, my job is to extract <title> tags from posted URLs. In case I'm annoying or for further questions, please talk to my master %s. I'm rate limited and shouldn't post more than %d messages per %d seconds. To make me exit immediately, highlight me with 'hangup' in the message (emergency only, please). For other commands, highlight me with 'command'.''' % (conf('bot_owner'), conf('hist_max_count'), conf('hist_max_time'))) } def command_teatimer(args): @@ -409,13 +409,13 @@ def command_decode(args): try: uni_name = unicodedata.name(char) except Exception as e: - logger('plugin', 'decode(%s) failed: %s' %(char, str(e))) + logger('plugin', 'decode(%s) failed: %s' % (char, str(e))) return { - 'msg': args['reply_user'] + ": can't decode %s (%s): %s" %(char, char_esc, str(e)) + 'msg': args['reply_user'] + ": can't decode %s (%s): %s" % (char, char_esc, str(e)) } return { - 'msg': args['reply_user'] + ': %s (%s) is called "%s"' %(char, char_esc, uni_name) + 'msg': args['reply_user'] + ': %s (%s) is called "%s"' % (char, char_esc, uni_name) } else: return { @@ -588,7 +588,7 @@ def data_parse_commands(msg_obj): elif 'argv2' == a: args['argv2'] = argv2 else: - logger('warn', 'unknown required arg for %s: %s' %(p['name'], a)) + logger('warn', 'unknown required arg for %s: %s' % (p['name'], a)) ret = p['func'](args) @@ -625,7 +625,7 @@ if debug_enabled(): def _send_reply(a, msg_obj): logger('send_reply[%s]' % msg_obj, a) - def _conf(a): + def _conf(ignored): return 'bot' def _ratelimit_exceeded(ignored=None): @@ -672,7 +672,7 @@ def register(func_type, auto=False): ret['func'] = f plugins[func_type].append(ret) except Exception as e: - logger('warn', 'auto-registering %s failed: %s' %(f, e)) + logger('warn', 'auto-registering %s failed: %s' % (f, e)) else: for f in funcs[func_type]: diff --git a/urlbot.py b/urlbot.py index 0120420..21b7f7d 100755 --- a/urlbot.py +++ b/urlbot.py @@ -1,14 +1,13 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -import sys, os, stat, re, time, pickle, random +import sys, re, time, pickle, random import urllib.request, urllib.parse, urllib.error, html.parser from common import * try: from local_config import conf, set_conf except ImportError: - import sys sys.stderr.write(''' %s: E: local_config.py isn't tracked because of included secrets and %s site specific configurations. Rename local_config.py.skel and @@ -60,7 +59,7 @@ def extract_title(url): (code, html_text, headers) = fetch_page(url) if 1 == code: - return (3, 'failed: %s for %s' %(html_text, url)) + return (3, 'failed: %s for %s' % (html_text, url)) if html_text: charset = '' @@ -134,7 +133,7 @@ def ratelimit_exceeded(ignored=None): # FIXME: separate counters if hist_flag: hist_flag = False # FIXME: this is very likely broken now - send_reply('(rate limited to %d messages in %d seconds, try again at %s)' %(conf('hist_max_count'), conf('hist_max_time'), time.strftime('%T %Z', time.localtime(hist_ts[0] + conf('hist_max_time'))))) + send_reply('(rate limited to %d messages in %d seconds, try again at %s)' % (conf('hist_max_count'), conf('hist_max_time'), time.strftime('%T %Z', time.localtime(hist_ts[0] + conf('hist_max_time'))))) logger('warn', 'rate limiting exceeded: ' + pickle.dumps(hist_ts)) return True @@ -183,16 +182,16 @@ def extract_url(data, msg_obj): if 0 == status: title = title.strip() - message = 'Title: %s: %s' %(title, url) + message = 'Title: %s: %s' % (title, url) elif 1 == status: if conf('image_preview'): # of course it's fake, but it looks interesting at least char = """,._-+=\|/*`~"'""" - message = 'No text but %s, 1-bit ASCII art preview: [%c] %s' %( + message = 'No text but %s, 1-bit ASCII art preview: [%c] %s' % ( title, random.choice(char), url ) else: - logger('info', 'no message sent for non-text %s (%s)' %(url, title)) + logger('info', 'no message sent for non-text %s (%s)' % (url, title)) continue elif 2 == status: message = 'No title: %s' % url @@ -281,11 +280,10 @@ class bot(ClientXMPP): if 'groupchat' == msg_obj['type']: return - plugins.data_parse_commands(msg_obj) - plugins.data_parse_other(msg_obj) +# plugins.data_parse_commands(msg_obj) +# plugins.data_parse_other(msg_obj) print('msg from %s: %s' % (msg_obj['from'].bare, msg_obj)) -# msg_obj.reply(body='waaaaah').send() if '__main__' == __name__: import plugins