Skip to content

Commit

Permalink
Added /meme command
Browse files Browse the repository at this point in the history
  • Loading branch information
idooo committed Feb 3, 2015
1 parent 853adb9 commit f62d675
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ Please note: it must be HipChat API version 1 key.
#### Plugins:
There are some builtin plugins enabled by default:

+ get random cat gif (http://thecatapi.com)
+ get staging servers status
+ get random Chuck's geek phrase (http://api.icndb.com)
+ get random pony picture (http://ponyfac.es/)
+ get random cat gif (thank you [thecatapi.com](http://thecatapi.com))
+ get random Chuck's geek phrase (thanks [api.icndb.com](http://api.icndb.com))
+ get random pony picture (thanks [ponyfac.es](http://ponyfac.es/))
+ play Rock-Paper-Scissors-Lizard-Spock
+ blame somebody
+ roll number from 0 to 100
+ get random Arnold Schwarzenegger's phrase
+ get random XKCD comics (http://xkcd.com/xxxx/info.0.json)
+ get random gif by keyword (http://api.giphy.com/)
+ get random [XKCD](http://xkcd.com) comics
+ get random gif by keyword (thank you [giphy](http://api.giphy.com/))
+ get random LEGO Movie quotes
+ ask bot a question
+ generate a meme (thanks [memecaptain.com](http://memecaptain.com) and [sassy bot](https://bitbucket.org/atlassianlabs/ac-koa-hipchat-sassy))

Type `/help` to see all available commands and detailed description

Expand Down
63 changes: 63 additions & 0 deletions plugins/meme/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import re
import requests

from memes import MEMES

class MemePlugin():

command = "meme"
help = "Creates a meme. Type `/" + command + "` to get help"

matchers = []
meme_help = ["Creates a meme with one of the following patterns:"]

def __init__(self):
for meme in MEMES:
self.matchers.append({
'picture': meme['picture'],
'groups': meme['groups'],
'pattern': re.compile(meme['pattern'], re.IGNORECASE)
})
self.meme_help.append("/" + self.command + " " + meme['help'])

def __check_matches(self, message):
message = message.replace('/' + self.command, '').strip()

for match in self.matchers:
res = re.search(match['pattern'], message)
if res:
obj = {
'u': match['picture'],
't1': '',
't2': ''
}
groups = res.groups()

if (isinstance(match['groups'][0], int) and len(groups) > 0 or
match['groups'][0] == '' and isinstance(match['groups'][1], int) and len(groups) > 0):
obj['t1'] = groups[0]

if isinstance(match['groups'][1], int) and len(groups) > 1:
obj['t2'] = groups[1]

return obj

return None

def response(self, message):
default_response = "Do not know about this meme. Try `/" + self.command + "` to get help"

if message.strip() == '/' + self.command:
return "\n".join(self.meme_help)

params = self.__check_matches(message)

if params:
r = requests.get('http://memecaptain.com/g', params=params)

if r.status_code == 200:
return r.json()['imageUrl']

return "We have return code " + str(r.status_code) + " here. Very strange..."

return default_response
134 changes: 134 additions & 0 deletions plugins/meme/memes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
MEMES = [
{
'pattern': '^(y u no) (.*)',
'help': 'y u no {text}',
'picture': 'http://memecaptain.com/y_u_no.jpg',
'groups': [0, 1]
},
{
'pattern': '^aliens? guy (.+)',
'help': 'aliens guy {text}',
'picture': 'http://memecaptain.com/aliens.jpg',
'groups': ['', 0]
},
{
'pattern': '^((?:prepare|brace) (?:yourself|yourselves)) (.+)',
'help': 'brace yourself {text}',
'picture': 'http://i.imgur.com/cOnPlV7.jpg',
'groups': [0, 1]
},
{
'pattern': '^(.*) (all the .*)',
'help': '{text} all the {things}',
'picture': 'http://memecaptain.com/all_the_things.jpg',
'groups': [0, 1]
},
{
'pattern': '^(i don\'?t (?:always|normally) .*) (but when i do,? .*)',
'help': 'I don\'t always {something} but when I do {text}',
'picture': 'http://memecaptain.com/most_interesting.jpg',
'groups': [0, 1]
},
{
'pattern': '^(.*)(\stoo damn .*)',
'help': '{text} too damn {something}',
'picture': 'http://memecaptain.com/too_damn_high.jpg',
'groups': [0, 1]
},
{
'pattern': '^(not sure if .*) (or .*)',
'help': 'not sure if {something} or {something else}',
'picture': 'http://memecaptain.com/fry.png',
'groups': [0, 1]
},
{
'pattern': '^(yo dawg .*) (so .*)',
'help': 'yo dawg {text} so {text}',
'picture': 'http://memecaptain.com/xzibit.jpg',
'groups': [0, 1]
},
{
'pattern': '^(all your .*) (are belong to .*)',
'help': 'all your {text} are belong to {text}',
'picture': 'http://i.imgur.com/gzPiQ8R.jpg',
'groups': [0, 1]
},
{
'pattern': '^(one does not simply) (.*)',
'help': 'one does not simply {text}',
'picture': 'http://memecaptain.com/boromir.jpg',
'groups': [0, 1]
},
{
'pattern': '^(if you .*\s)(.* gonna have a bad time)',
'help': 'if you {text} gonna have a bad time',
'picture': 'http://memecaptain.com/bad_time.jpg',
'groups': [0, 1]
},
{
'pattern': '^(if .*), ((?:are|can|do|does|how|is|may|might|should|then|what|when|where|which|who|why|will|won\'t|would) .*)',
'help': 'if {text}, {word that can start a question} {text}?',
'picture': 'http://memecaptain.com/philosoraptor.jpg',
'groups': [0, 1]
},
{
'pattern': '^((?:how|what|when|where|who|why) the (?:hell|heck|fuck|shit|crap|damn)) (.*)',
'help': '{word that can start a question} the {expletive} {text}',
'picture': 'http://memecaptain.com/src_images/z8IPtw',
'groups': [0, 1]
},
{
'pattern': '^(?:success|nailed it) when (.*) then (.*)',
'help': 'success when {text} then {text}',
'picture': 'http://memecaptain.com/success_kid.jpg',
'groups': [0, 1]
},
{
'pattern': '^(?:fwp|cry) when (.*) then (.*)',
'help': 'cry when {text} then {text}',
'picture': 'http://v1.memecaptain.com/first_world_problems.jpg',
'groups': [0, 1]
},
{
'pattern': '^bad luck when (.*) then (.*)',
'help': 'bad luck when {text} then {text}',
'picture': 'http://v1.memecaptain.com/bad_luck_brian.jpg',
'groups': [0, 1]
},
{
'pattern': '^scumbag(?: steve)? (.*) then (.*)',
'help': 'scumbag {text} then {text}',
'picture': 'http://v1.memecaptain.com/scumbag_steve.jpg',
'groups': [0, 1]
},
{
'pattern': '^(what if i told you) (.+)',
'help': 'what if I told you {text}',
'picture': 'http://memecaptain.com/src_images/fWle1w',
'groups': [0, 1]
},
{
'pattern': '^(i hate) (.+)',
'help': 'I hate {text}',
'picture': 'http://memecaptain.com/src_images/_k6JVg',
'groups': [0, 1]
},
{
'pattern': '^(why can\'?t (?:i|we|you|he|she|it|they)) (.+)',
'help': 'why can\'t {personal pronoun} {text}',
'picture': 'http://i0.kym-cdn.com/photos/images/newsfeed/000/075/683/limes_guy.jpg',
'groups': [0, 1]
},
{
'pattern': '^(.+),? (how (?:do (?:they|I)|does (?:he|she|it)) work\??)',
'help': '{things}, how do they work?',
'picture': 'http://i2.kym-cdn.com/photos/images/original/000/046/123/magnets.jpg',
'groups': [0, 1]
},
{
'pattern': '^(.+?(?:a{3,}|e{3,}|i{3,}|o{3,}|u{3,}|y{3,}).*)',
'help': '{text}{3 x a|e|i|o|u|y}{text}',
'picture': 'http://memecaptain.com/src_images/L50mqA',
'groups': [0, 1]
},
]

0 comments on commit f62d675

Please sign in to comment.