Help with Python plugin for a bot.

By Protheus on Dec 14, 2016

Ok, so i'm slowly learning Python, and i'm trying to create a plugin for a bot that prints "Baby don't hurt me." in a channel whenever anyone types "What is love?". The thing is, i want it to ignore case and punctuation, so if a user types just "what is love" i'd like it to trigger the bot's response also. I have no. fucking. clue how to do this. Any help would be appreciated.

from cloudbot import hook

@hook.regex(r"^What is love?(!|\?|\.)?$")
def what_hook(match):
    return "Baby don't hurt me."


Sign in to comment.
gooshie   -  Feb 07, 2017
#!/usr/bin/env python

import re

message = "WhaT iS lOvE"

pattern = re.compile(r"What is love(!|\?|\.)?$",re.IGNORECASE)
print re.match(pattern,message) 
# re.match does not require ^

pattern = re.compile(r"^What is love(!|\?|\.)?$",re.IGNORECASE)
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.