Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100750 > unrolled thread

Re: How to use a variable to act as @rule in a Sopel IRC bot module?

Started by<arresteddevlopment@tuta.io>
First post2015-12-22 21:19 +0000
Last post2015-12-22 21:19 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Re: How to use a variable to act as @rule in a Sopel IRC bot module? <arresteddevlopment@tuta.io> - 2015-12-22 21:19 +0000

#100750 — Re: How to use a variable to act as @rule in a Sopel IRC bot module?

From<arresteddevlopment@tuta.io>
Date2015-12-22 21:19 +0000
SubjectRe: How to use a variable to act as @rule in a Sopel IRC bot module?
Message-ID<mailman.71.1450819185.2237.python-list@python.org>
Apologies for the terrible formatting, let me try that again:

A:
from sopel.module import commands, rule
import random

q_and_as = [('Why?', 'because'), ('Can I kick it?', 'nope')]

@commands("quizme")
def ask_q(bot, trigger):
     q = random.choice(q_and_as)
     bot.say(q[0])
     @rule(q[1])
     def correct(bot, trigger):
     bot.sat('Correctamundo!')

B:
...
@commands("quizme")
def ask_q(bot, trigger):
     q = random.choice(q_and_as)
     bot.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 
(http://stackoverflow.com/questions/34419265/how-to-set-and-later-change-a-rule-in-a-sopel-irc-bot-module-python). 
Any help would be greatly appreciated.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web