Skip to content

Commit

Permalink
Merge pull request #89 from Growleythebear/skb-dev
Browse files Browse the repository at this point in the history
Skb dev
  • Loading branch information
LanceMaverick committed Feb 4, 2017
2 parents 51815a2 + 5c01995 commit a3c4d04
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions beards/corgibase/__config__.py.example
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 = ''
47 changes: 47 additions & 0 deletions beards/corgibase/__init__.py
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')))

0 comments on commit a3c4d04

Please sign in to comment.