forked from idooo/pancake-hipchat-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration to the new plugins structure
+ version bump
- Loading branch information
Showing
13 changed files
with
187 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
class BlamePlugin(): | ||
|
||
help = "Blame somebody" | ||
command = "blame" | ||
|
||
@staticmethod | ||
def response(random_user): | ||
message = '{}, this is your fault!' | ||
return message.format(random_user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import requests | ||
|
||
class ChuckNorrisPlugin(): | ||
|
||
help = "Post a random Chuck's phrase" | ||
command = "chuck" | ||
|
||
@staticmethod | ||
def response(): | ||
|
||
message = "Can't connect to Chuck API =(" | ||
params = {'limitTo': '[nerdy]'} | ||
|
||
r = requests.get('http://api.icndb.com/jokes/random', params=params) | ||
|
||
if r.status_code == 200: | ||
response = r.json() | ||
|
||
if response['type'] == 'success': | ||
message = response['value']['joke'] | ||
|
||
return message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import requests | ||
import json | ||
|
||
class GeckoboardPlugin(): | ||
|
||
help = "Post message to Geckoboard" | ||
command = "board" | ||
|
||
widget_key = None | ||
api_key = None | ||
|
||
def __init__(self, conf): | ||
if not 'geckoboard' in conf: | ||
raise Exception("There is no [geckoboard] section in the config file") | ||
|
||
if not 'api' in conf['geckoboard'] or not 'widget' in conf['geckoboard']: | ||
raise Exception("You must specify 'widget' and 'api' options " | ||
"in [geckoboard] section in the config file") | ||
|
||
self.widget_key = conf['geckoboard']['widget'] | ||
self.api_key = conf['geckoboard']['api'] | ||
|
||
def response(self, message): | ||
|
||
message_parts = message.split(' ', 1) | ||
|
||
params = { | ||
"api_key": self.api_key, | ||
"data": { | ||
"item": [ | ||
{ "text": message_parts[1], "type":0 } | ||
] | ||
} | ||
} | ||
|
||
headers = {'Content-type': 'application/json'} | ||
r = requests.post('https://push.geckoboard.com/v1/send/' + self.widget_key, | ||
data=json.dumps(params), headers=headers) | ||
|
||
if r.status_code == 200: | ||
response = r.json() | ||
|
||
if response['success']: | ||
return 'Message was posted to Geckoboard' | ||
|
||
return 'Something went wrong' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import random | ||
|
||
class PonyPlugin(): | ||
|
||
help = "Post a random pony image" | ||
command = "pony" | ||
|
||
@staticmethod | ||
def response(): | ||
max_number = 160 | ||
return "http://ponyfac.es/{}/full.jpg".format(random.randint(1, max_number)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import random | ||
|
||
class AskMePlugin(): | ||
|
||
help = "Ask me a question" | ||
command = "?" | ||
|
||
@staticmethod | ||
def response(author): | ||
options = ['yes', 'no', 'no way!', 'yep!'] | ||
return '{0}, {1}'.format(author, random.choice(options)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import random | ||
|
||
class RollPlugin(): | ||
|
||
help = "Roll a random number 0 - 100" | ||
command = "roll" | ||
|
||
@staticmethod | ||
def response(author): | ||
return '{0} rolled {1}'.format(author, random.randint(0, 100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import random | ||
|
||
class RPSPlugin(): | ||
|
||
help = "Rock - Paper - Scissors - Lizard - Spock (type '/rps help' for help)" | ||
command = "rps" | ||
|
||
@staticmethod | ||
def response(message, author): | ||
if 'help' in message: | ||
return 'http://a.tgcdn.net/images/products/additional/large/db2e_lizard_spock.jpg' | ||
|
||
options = ['Rock', 'Paper', 'Scissors', 'Lizard', 'Spock'] | ||
return '{0} - {1}'.format(author, random.choice(options)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import random | ||
import requests | ||
|
||
class XKCDPlugin(): | ||
|
||
help = "Get random xkcd comics" | ||
command = "xkcd" | ||
|
||
@staticmethod | ||
def response(): | ||
|
||
max_value = 1335 | ||
value = random.randint(1, max_value) | ||
|
||
r = requests.get('http://xkcd.com/{}/info.0.json'.format(value)) | ||
|
||
if r.status_code == 200: | ||
response = r.json() | ||
return [response['img'], response['alt']] | ||
|
||
else: | ||
return "Can't connect to xkcd API =(" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters