mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
add multi-choice mod by braph
This commit is contained in:
@@ -15,6 +15,7 @@ import config
|
|||||||
from common import VERSION
|
from common import VERSION
|
||||||
from rate_limit import RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_SILENCE, RATE_NO_LIMIT
|
from rate_limit import RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_SILENCE, RATE_NO_LIMIT
|
||||||
from plugin_system import pluginfunction, ptypes, plugin_storage, plugin_enabled_get, plugin_enabled_set
|
from plugin_system import pluginfunction, ptypes, plugin_storage, plugin_enabled_get, plugin_enabled_set
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -92,7 +93,6 @@ def command_plugin_activation(argv, **args):
|
|||||||
|
|
||||||
@pluginfunction('list', 'list plugin and parser status', ptypes.COMMAND)
|
@pluginfunction('list', 'list plugin and parser status', ptypes.COMMAND)
|
||||||
def command_list(argv, **args):
|
def command_list(argv, **args):
|
||||||
|
|
||||||
log.info('list plugin called')
|
log.info('list plugin called')
|
||||||
|
|
||||||
if 'enabled' in argv and 'disabled' in argv:
|
if 'enabled' in argv and 'disabled' in argv:
|
||||||
@@ -282,15 +282,38 @@ def command_dice(argv, **args):
|
|||||||
@pluginfunction('choose', 'chooses randomly between arguments', ptypes.COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
@pluginfunction('choose', 'chooses randomly between arguments', ptypes.COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
||||||
def command_choose(argv, **args):
|
def command_choose(argv, **args):
|
||||||
alternatives = argv
|
alternatives = argv
|
||||||
if len(alternatives) < 2:
|
binary = ['Yes', 'No', 'Maybe']
|
||||||
|
|
||||||
|
# single choose request
|
||||||
|
if 'choose' not in alternatives:
|
||||||
|
log.info('sent random choice')
|
||||||
return {
|
return {
|
||||||
'msg': '{}: {}.'.format(args['reply_user'], random.choice(['Yes', 'No']))
|
'msg': '%s: I prefer %s!' % (args['reply_user'], random.choice(alternatives))
|
||||||
}
|
}
|
||||||
|
|
||||||
choice = random.choice(alternatives)
|
# multiple choices
|
||||||
log.info('sent random choice')
|
def choose_between(options):
|
||||||
|
responses = []
|
||||||
|
current_choices = []
|
||||||
|
|
||||||
|
for item in options:
|
||||||
|
if item == 'choose':
|
||||||
|
if len(current_choices) < 2:
|
||||||
|
responses.append(random.choice(binary))
|
||||||
|
else:
|
||||||
|
responses.append(random.choice(current_choices))
|
||||||
|
current_choices = []
|
||||||
|
else:
|
||||||
|
current_choices.append(item)
|
||||||
|
if len(current_choices) < 2:
|
||||||
|
responses.append(random.choice(binary))
|
||||||
|
else:
|
||||||
|
responses.append(random.choice(current_choices))
|
||||||
|
return responses
|
||||||
|
|
||||||
|
log.info('sent multiple random choices')
|
||||||
return {
|
return {
|
||||||
'msg': '%s: I prefer %s!' % (args['reply_user'], choice)
|
'msg': '%s: My choices are: %s!' % (args['reply_user'], ', '.join(choose_between(alternatives)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -564,8 +587,8 @@ def command_dsa_watcher(argv=None, **_):
|
|||||||
for dsa_about in reversed(dsa_about_list):
|
for dsa_about in reversed(dsa_about_list):
|
||||||
dsa_id = get_id_from_about_string(dsa_about)
|
dsa_id = get_id_from_about_string(dsa_about)
|
||||||
title = xmldoc.xpath(
|
title = xmldoc.xpath(
|
||||||
'//purl:item[@rdf:about="{}"]/purl:title/text()'.format(dsa_about),
|
'//purl:item[@rdf:about="{}"]/purl:title/text()'.format(dsa_about),
|
||||||
namespaces=nsmap
|
namespaces=nsmap
|
||||||
)[0]
|
)[0]
|
||||||
if after and dsa_id <= after:
|
if after and dsa_id <= after:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user