Skip to content
Snippets Groups Projects
Commit 96784a43 authored by Bruce Cowan's avatar Bruce Cowan
Browse files

Make use of regexes

parent 9949f0d3
No related branches found
No related tags found
No related merge requests found
# Copyright © 2016 Bruce Cowan <bruce@bcowan.eu>
# Copyright © 2016, 2018 Bruce Cowan <bruce@bcowan.eu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -13,27 +13,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
from errbot import BotPlugin
class Justforfun(BotPlugin):
"""This is just for fun"""
def activate(self):
super().activate()
self.good = re.compile(r'\bthanks?\b', re.IGNORECASE)
self.bad = re.compile(r'\b(silly|bad)\b', re.IGNORECASE)
self.congrats = re.compile(r'\bcongrat(s|ulations)\b', re.IGNORECASE)
def callback_mention(self, message, mentioned_people):
""" Listens for rude or nice things about the bot """
if self.bot_identifier not in mentioned_people:
return
# The bot has been mentioned
cmp_message = message.body.casefold()
good = ['thank']
bad = ['silly', 'bad']
congrat = ['congrats', 'congratulations']
if any(s in cmp_message for s in good):
if self.good.search(message.body):
self.send(message.to, "you're welcome", message)
if any(s in cmp_message for s in bad):
if self.bad.search(message.body):
self.send(message.to, "sorry", message)
if any(s in cmp_message for s in congrat):
if self.congrats.search(message.body):
self.send(message.to, "thank you", message)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment