Skip to content

Instantly share code, notes, and snippets.

@tomblench
Created March 31, 2014 10:50
Show Gist options
  • Save tomblench/9889760 to your computer and use it in GitHub Desktop.
Save tomblench/9889760 to your computer and use it in GitHub Desktop.
import re
import string
from errbot import BotPlugin, botcmd
class ofhave(BotPlugin):
def callback_message(self, conn, mess):
reply = self.couldShould(mess.getBody())
if reply:
self.send(
mess.getFrom(),
reply,
message_type=mess.getType()
)
def couldShould(me, sentence) :
pronMap = {"i": "you",
"you": "you",
"they": "they",
"we": "you",
"he": "he",
"she": "she",
"it": "it"};
# (could should would won't can't)
m = re.search("(I|you|they|we|he|she|it)\s+(could|couldn't|should|shouldn't|would|wouldn't|won't|will not|can't|cannot|can not)(\s+have|'ve)\s+([^-.;,]*)", sentence, re.I);
if (m) :
return (pronMap[m.group(1).lower()] + " " + m.group(2) + " of " + m.group(4) + "!");
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment