Skip to content

Instantly share code, notes, and snippets.

@ultrabug
Created May 26, 2016 07:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultrabug/209967a6a4af88e3730713371699915e to your computer and use it in GitHub Desktop.
Save ultrabug/209967a6a4af88e3730713371699915e to your computer and use it in GitHub Desktop.
_Ultrabot helper module
# -*- 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