Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Newsgroups: comp.lang.python Subject: Re: How to use a variable to act as @rule in a Sopel IRC bot module? Date: Tue, 22 Dec 2015 21:19:32 +0000 (UTC) Lines: 33 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de RPFQGknrF/zNSRHd331uDwBsYgCqduUfYdjokJjjTrAg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:How': 0.09; 'subject:module': 0.09; 'def': 0.13; 'subject: \n ': 0.15; 'formatting,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:variable': 0.16; 'to:name:python list': 0.16; 'commands,': 0.22; "skip:' 40": 0.22; 'import': 0.24; 'appreciated.': 0.27; 'random': 0.29; 'asked': 0.29; 'rule': 0.33; 'skip:b 60': 0.33; 'subject:use': 0.35; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'from:no real name:2**0': 0.60; 'skip:\xc2 10': 0.67; 'terrible': 0.84 X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100750 Apologies for the terrible formatting, let me try that again: A: from sopel.module import commands, rule import random q_and_as =3D [('Why?', 'because'), ('Can I kick it?', 'nope')] @commands("quizme") def ask_q(bot, trigger): q =3D random.choice(q_and_as) bot.say(q[0]) =C2=A0@rule(q[1]) =C2=A0def correct(bot, trigger): bot.sat('Correctamundo!') B: ... @commands("quizme") def ask_q(bot, trigger): q =3D random.choice(q_and_as) =C2=A0bot.say(q[0]) answer(bot, trigger, q[1]) def answer(bot, trigger, answer): @rule(answer) def correct(bot, trigger): bot.say(' correctamundo!') If the above comes out wonky again I also asked on StackOverflow=20 (http://stackoverflow.com/questions/34419265/how-to-set-and-later-change-a-= rule-in-a-sopel-irc-bot-module-python).=20 Any help would be greatly appreciated.