1
0
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:
Thorsten
2016-05-27 21:31:31 +02:00
parent 5b9ed2ef94
commit f7ab2cfbdd

View File

@@ -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']
return {
'msg': '{}: {}.'.format(args['reply_user'], random.choice(['Yes', 'No']))
}
choice = random.choice(alternatives) # single choose request
if 'choose' not in alternatives:
log.info('sent random choice') log.info('sent random choice')
return { return {
'msg': '%s: I prefer %s!' % (args['reply_user'], choice) 'msg': '%s: I prefer %s!' % (args['reply_user'], random.choice(alternatives))
}
# multiple choices
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 {
'msg': '%s: My choices are: %s!' % (args['reply_user'], ', '.join(choose_between(alternatives)))
} }