Skip to content

Commit

Permalink
plugins system
Browse files Browse the repository at this point in the history
+ some functions were ported to plugins
  • Loading branch information
idooo committed Oct 18, 2014
1 parent 396200d commit fa412a8
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 398 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ nosetests.xml
conf/*.conf

nohup.out

conf/bot_.py
11 changes: 3 additions & 8 deletions pancake.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
conf_name = args.config
conf = library.config.Settings(conf_name)

bot = library.Bot(
conf.general['api_token'],
name=conf.general['bot_name'],
aws=conf.aws,
gecko=conf.geckoboard
)

bot.joinRooms(conf.general['rooms'])
bot = library.Bot(conf)

bot.join_rooms(conf.general['rooms'])
bot.start()
23 changes: 23 additions & 0 deletions plugins/arnold/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import random

from arnold_phrases import ARNOLD_PHRASES

class ArnoldPlugin():

help = "Arnold Schwarzenegger's phrase (/! name)"
command = "!"

@staticmethod
def response(mentioned_user, random_user):

phrase = random.choice(ARNOLD_PHRASES)

if "{}" not in phrase:
phrase = "{}, " + phrase

username = mentioned_user

if not username:
username = random_user

return phrase.format(username)
File renamed without changes.
25 changes: 25 additions & 0 deletions plugins/cats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import re
import requests

class CatGIFPlugin():

help = "Post a random cat gif"
command = "cat"

def __init__(self):
self.RE_URL = re.compile("<url>([^<]*)</url>", re.MULTILINE + re.IGNORECASE)

def response(self):
message = "Can't connect to cat API =("
params = {'format': 'xml', 'type': 'gif'}

r = requests.get('http://thecatapi.com/api/images/get', params=params)

if r.status_code == 200:
response = r.text

res = re.search(self.RE_URL, response)
if res:
message = res.groups()[0]

return message
22 changes: 22 additions & 0 deletions plugins/giphy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests

class GiphyPlugin():

help = "Get a random gif, with a optional search term (/gif keyboard cat)"
command = "gif"

@staticmethod
def response(message):
search_values = message.split('/gif', 1)
tags = ''
if len(search_values) == 2:
tags = '+'.join(search_values[1].split())

r = requests.get('http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=' + tags)

if r.status_code == 200:
response = r.json()
return response['data']['image_url']

else:
return "Can't connect to giphy API =("
23 changes: 23 additions & 0 deletions plugins/lego/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import random

from lego_quotes import LEGO_QUOTES

class LegoPlugin():

help = "LEGO Movie quote's (/lego name)"
command = "lego"

@staticmethod
def response(mentioned_user, random_user):

phrase = random.choice(LEGO_QUOTES)

if "{}" not in phrase:
phrase = "{}, " + phrase

username = mentioned_user

if not username:
username = random_user

return phrase.format(username)
File renamed without changes.
19 changes: 0 additions & 19 deletions src/aws_basic.py

This file was deleted.

Loading

0 comments on commit fa412a8

Please sign in to comment.