misc
This commit is contained in:
@@ -21,6 +21,7 @@ class IdleBot(ClientXMPP):
|
||||
self.add_event_handler('groupchat_message', self.muc_message)
|
||||
self.add_event_handler('disconnected', self.disconnected)
|
||||
self.add_event_handler('presence_error', self.disconnected)
|
||||
self.add_event_handler('session_end', self.disconnected)
|
||||
self.priority = 0
|
||||
self.status = None
|
||||
self.show = None
|
||||
@@ -30,6 +31,7 @@ class IdleBot(ClientXMPP):
|
||||
self.add_event_handler('muc::%s::got_offline' % room, self.muc_offline)
|
||||
|
||||
def disconnected(self, _):
|
||||
self.logger.warn("Disconnected! dbg: {}".format(str(_)))
|
||||
self.disconnect(wait=True)
|
||||
|
||||
def session_start(self, _):
|
||||
@@ -105,6 +107,8 @@ def start(botclass, active=False):
|
||||
|
||||
bot.connect()
|
||||
bot.register_plugin('xep_0045')
|
||||
bot.register_plugin('xep_0199', {'keepalive': True})
|
||||
bot.register_plugin('xep_0308')
|
||||
bot.process()
|
||||
|
||||
config.runtimeconf_set('start_time', -time.time())
|
||||
|
||||
@@ -6,28 +6,48 @@ from plugin_system import pluginfunction, ptypes
|
||||
from rate_limit import RATE_FUN, RATE_GLOBAL
|
||||
|
||||
|
||||
def give_item(user, item_name, search_word=None):
|
||||
if not search_word:
|
||||
search_word = item_name
|
||||
return {'msg': '{} for {}: {}'.format(item_name, user, giphy(search_word, 'dc6zaTOxFJmzC'))}
|
||||
|
||||
|
||||
def cake_excuse(user):
|
||||
return {
|
||||
'msg': '{}: {}'.format(user, random.choice(cakes))
|
||||
}
|
||||
|
||||
|
||||
@pluginfunction('cake', 'displays a cake ASCII art', ptypes.COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||
def command_cake(argv, **args):
|
||||
if {'please', 'bitte'}.intersection(set(argv)):
|
||||
return {
|
||||
'msg': 'cake for {}: {}'.format(args['reply_user'], giphy('cake', 'dc6zaTOxFJmzC'))
|
||||
}
|
||||
|
||||
return {
|
||||
'msg': args['reply_user'] + ': %s' % random.choice(cakes)
|
||||
}
|
||||
return give_item(args['reply_user'], 'cake')
|
||||
else:
|
||||
return cake_excuse(args['reply_user'])
|
||||
|
||||
|
||||
@pluginfunction('keks', 'keks!', ptypes.COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||
def command_cookie(argv, **args):
|
||||
if {'please', 'bitte'}.intersection(set(argv)):
|
||||
return {
|
||||
'msg': 'keks für {}: {}'.format(args['reply_user'], giphy('cookie', 'dc6zaTOxFJmzC'))
|
||||
}
|
||||
return give_item(args['reply_user'], 'keks', 'cookie')
|
||||
else:
|
||||
return cake_excuse(args['reply_user'])
|
||||
|
||||
return {
|
||||
'msg': args['reply_user'] + ': %s' % random.choice(cakes)
|
||||
}
|
||||
|
||||
@pluginfunction('schnitzel', 'schnitzel!', ptypes.COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||
def command_schnitzel(argv, **args):
|
||||
if {'please', 'bitte'}.intersection(set(argv)):
|
||||
return give_item(args['reply_user'], 'schnitzel')
|
||||
else:
|
||||
return cake_excuse(args['reply_user'])
|
||||
|
||||
|
||||
@pluginfunction('kaffee', 'kaffee!', ptypes.COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||
def command_coffee(argv, **args):
|
||||
if {'please', 'bitte'}.intersection(set(argv)):
|
||||
return give_item(args['reply_user'], 'kaffee', 'coffee')
|
||||
else:
|
||||
return cake_excuse(args['reply_user'])
|
||||
|
||||
|
||||
cakes = [
|
||||
@@ -46,4 +66,3 @@ cakes = [
|
||||
"I'm going to kill you, and all the cake is gone.",
|
||||
"Who's gonna make the cake when I'm gone? You?"
|
||||
]
|
||||
|
||||
|
||||
@@ -881,35 +881,6 @@ def reload_runtimeconfig(argv, **args):
|
||||
return {'msg': 'done'}
|
||||
|
||||
|
||||
@pluginfunction('snitch', "tell on a spammy user", ptypes.COMMAND)
|
||||
def ignore_user(argv, **args):
|
||||
if not argv:
|
||||
return {'msg': 'syntax: "{}: snitch username"'.format(config.conf_get("bot_nickname"))}
|
||||
|
||||
then = time.time() + 15 * 60
|
||||
spammer = argv[0]
|
||||
|
||||
if spammer == config.conf_get("bot_owner"):
|
||||
return {
|
||||
'msg': 'My owner does not spam, he is just very informative.'
|
||||
}
|
||||
|
||||
if spammer not in config.runtime_config_store['spammers']:
|
||||
config.runtime_config_store['spammers'].append(spammer)
|
||||
|
||||
def unblock_user(user):
|
||||
if user not in config.runtime_config_store['spammers']:
|
||||
config.runtime_config_store['spammers'].append(user)
|
||||
|
||||
return {
|
||||
'msg': 'user reported and ignored till {}'.format(time.strftime('%H:%M', time.localtime(then))),
|
||||
'event': {
|
||||
'time': then,
|
||||
'command': (unblock_user, ([spammer],))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pluginfunction('search', 'search the web (using duckduckgo)', ptypes.COMMAND)
|
||||
def search_the_web(argv, **args):
|
||||
url = 'http://api.duckduckgo.com/'
|
||||
|
||||
@@ -58,14 +58,11 @@ def parse_debbug(**args):
|
||||
log.info('detected Debian bug #%s' % b)
|
||||
|
||||
url = 'https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s' % b
|
||||
status, title = extract_title(url)
|
||||
|
||||
if 0 == status:
|
||||
title = extract_title(url)
|
||||
|
||||
if title:
|
||||
out.append('Debian Bug: %s: %s' % (title, url))
|
||||
elif 3 == status:
|
||||
out.append('error for #%s: %s' % (b, title))
|
||||
else:
|
||||
log.info('unknown status %d' % status)
|
||||
|
||||
return {
|
||||
'msg': out
|
||||
@@ -130,34 +127,6 @@ def parse_slash_me(**args):
|
||||
}
|
||||
|
||||
|
||||
@pluginfunction("recognize_bots", "got ya", ptypes.PARSE, enabled=False)
|
||||
def recognize_bots(**args):
|
||||
# disabled until channel separation
|
||||
return
|
||||
unique_standard_phrases = (
|
||||
'independent bot and have nothing to do with other artificial intelligence systems',
|
||||
'new Debian Security Announce',
|
||||
'I\'m a bot (highlight me',
|
||||
)
|
||||
|
||||
def _add_to_list(username, message):
|
||||
if username not in config.runtime_config_store['other_bots']:
|
||||
config.runtime_config_store['other_bots'].append(username)
|
||||
config.runtimeconf_persist()
|
||||
log.info("Adding {} to the list of bots (now {})".format(username, config.runtime_config_store['other_bots']))
|
||||
return {
|
||||
'event': {
|
||||
'time': time.time() + 3,
|
||||
'msg': message
|
||||
}
|
||||
}
|
||||
|
||||
if any([phrase in args['data'] for phrase in unique_standard_phrases]):
|
||||
return _add_to_list(args['reply_user'], 'Making notes...')
|
||||
elif 'I\'ll be back' in args['data']:
|
||||
return _add_to_list(args['reply_user'], 'Hey there, buddy!')
|
||||
|
||||
|
||||
@pluginfunction('resolve-url-title', 'extract titles from urls', ptypes.PARSE, ratelimit_class=RATE_URL)
|
||||
def resolve_url_title(**args):
|
||||
user = args['reply_user']
|
||||
@@ -173,7 +142,7 @@ def resolve_url_title(**args):
|
||||
url_blacklist = config.runtime_config_store['url_blacklist'].values()
|
||||
|
||||
out = []
|
||||
for url in result:
|
||||
for url in result[:10]:
|
||||
if any([re.match(b, url) for b in url_blacklist]):
|
||||
log.info('url blacklist match for ' + url)
|
||||
break
|
||||
|
||||
@@ -88,7 +88,7 @@ class UrlBot(IdleBot):
|
||||
request_counter = int(config.runtimeconf_get('request_counter'))
|
||||
config.runtimeconf_set('request_counter', request_counter + 1)
|
||||
|
||||
if str is not type(message):
|
||||
if not isinstance(message, str):
|
||||
message = '\n'.join(message)
|
||||
|
||||
def cached(function, ttl=60):
|
||||
@@ -300,7 +300,7 @@ class UrlBot(IdleBot):
|
||||
if not plugin_enabled_get(plugin):
|
||||
continue
|
||||
|
||||
ret = plugin(reply_user=reply_user, data=data)
|
||||
ret = plugin(reply_user=reply_user, data=data, sender=msg_obj['from'])
|
||||
|
||||
if ret:
|
||||
self._run_action(ret, plugin, msg_obj)
|
||||
|
||||
Reference in New Issue
Block a user