1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00
This commit is contained in:
Thorsten
2016-12-11 12:22:00 +01:00
parent 9c0ae3982a
commit 328e821f6d
5 changed files with 43 additions and 80 deletions

View File

@@ -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?"
]

View File

@@ -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/'

View File

@@ -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