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."

Comments

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)
print re.search(pattern,message)
 Respond  
ClaudeDiaz   -  Feb 01, 2017

Hahah, nice idea! I never tried to do something similar. I love your ambitious mood in learning Python. I cannot help you with that. But I have found the whole post for you on how to avoid punctuation. Read the article "How to remove all the punctuation in a string? (Python)" type in google. You know, you got me interested in the issue. If I happen to find out it faster than you and research the matter, I will gladly write my research paper for you what I've discovered, since I am a newbie in Python as well.

 Respond  
Vegito   -  Dec 15, 2016

I haven't tried CloudBot myself, what do you so far have working?

 Respond  
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.