-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from Growleythebear/skb-dev
Skb dev
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#Please fill in the information below to access the reddit API | ||
|
||
client_id = '' | ||
client_secret = '', | ||
password = '' | ||
user_agent = '' | ||
username = '' |
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,47 @@ | ||
#show spacecats test plugin | ||
# Adapted from work by LanceMaverick | ||
|
||
import random | ||
import logging | ||
from urllib.request import urlopen | ||
import telepot | ||
import telepot.aio | ||
import praw | ||
from skybeard.beards import BeardChatHandler | ||
from skybeard.predicates import regex_predicate | ||
from . import config | ||
|
||
class CorrgiBase(BeardChatHandler): | ||
__userhelp__ = """ | ||
Say give me corgis or show me corgis to see some corgis!""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.register_command( | ||
regex_predicate('(give|show) me corgis'), self.send_corgi) | ||
|
||
async def send_corgi(self, msg): | ||
reddit = praw.Reddit(client_id = config.client_id, | ||
client_secret = config.client_secret, | ||
username = config.username, | ||
password = config.password, | ||
user_agent = config.user_agent, | ||
) | ||
subreddit = reddit.subreddit('corgis') | ||
hot_posts = subreddit.hot(limit=10) | ||
url_list = [post.url for post in hot_posts] | ||
|
||
|
||
try: | ||
choice = random.choice(url_list) | ||
extensions = ['.jpg', '.jpeg', '.png', '.gif'] | ||
if any (ext in choice for ext in extensions): | ||
await self.sender.sendPhoto((choice.split("/")[-1], urlopen(choice))) | ||
else: | ||
await self.sender.sendMessage(choice) | ||
except Exception as e: | ||
logging.error(e) | ||
await self.sender.sendPhoto( | ||
("cat_photo.jpg", | ||
urlopen('http://cdn.meme.am/instances/500x/55452028.jpg'))) | ||
|