From b6d7268a7f232db65b521580d63b60f12fc4ee53 Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Mon, 21 Aug 2017 22:05:06 +0200 Subject: [PATCH] select by famhash: Add methods to get param in bot We need a method as callback to get bot specific params passed through to our bot class. Introduce -famhash parameter to work on specific famhash Related Task:[FS#146](https://fs.golderweb.de/index.php?do=details&task_id=146) --- red.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/red.py b/red.py index f4be812..8ea4f7b 100644 --- a/red.py +++ b/red.py @@ -60,7 +60,7 @@ def prepare_bot( task_slug, subtask, genFactory, subtask_args ): @rtype tuple """ # kwargs are passed to selected bot as **kwargs - kwargs = dict() + kwargs = subtask_args if not subtask or subtask == "discparser": # Default case: discparser @@ -83,6 +83,25 @@ def prepare_bot( task_slug, subtask, genFactory, subtask_args ): return ( subtask, Bot, genFactory, kwargs ) +def parse_red_args( argkey, value ): + """ + Process additional args for red.py + + @param argkey The arguments key + @type argkey str + @param value The arguments value + @type value str + + @return Tuple with (key, value) if given pair is relevant, else None + @rtype tuple or None + """ + + if argkey.startswith("-famhash"): + return ( "famhash", value ) + + return None + + def main(*args): """ Process command line arguments and invoke bot. @@ -110,7 +129,7 @@ def main(*args): # Parse local Args to get information about subtask ( subtask, genFactory, subtask_args ) = jogobot.bot.parse_local_args( - local_args ) + local_args, parse_red_args ) # select subtask and prepare args ( subtask, Bot, genFactory, kwargs ) = prepare_bot(