Created
May 26, 2016 07:11
-
-
Save ultrabug/209967a6a4af88e3730713371699915e to your computer and use it in GitHub Desktop.
_Ultrabot helper module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
import random | |
import re | |
from sopel.module import priority, rate | |
# list of all the regexes and their associated responses | |
regexes = [ | |
{ | |
'regex': r'(?i).*(help).*$', | |
'response': ["Hey $nick, somebody in here will surely help you" + | |
" when he can (or wakes up), so stick around mate !"] | |
} | |
] | |
authorized_chans = ['#py3status'] | |
@priority('high') | |
@rate(120) | |
def helper(bot, trigger): | |
""" | |
Scan messages and react on some well-chosen keywords | |
""" | |
if trigger.sender in authorized_chans: | |
# only reply if we are in an authorized channel | |
for regex in regexes: | |
if re.match(regex['regex'], trigger.group(1)): | |
response = random.choice(regex['response']).replace( | |
'$nick', trigger.nick) | |
bot.say(response) | |
# add the @rules to the func | |
helper.rule = [] | |
for regex in regexes: | |
helper.rule.append(regex['regex']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment