-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReddit.py
46 lines (41 loc) · 1.22 KB
/
Reddit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Reddit module
"""
import logging
from telegram import Bot, Update
import praw, prawcore
from settings import REDDITID, REDDITUA, REDDITSECRET
import constants # pylint: disable=E0401
LOGGER = logging.getLogger("Reddit")
REDDIT = praw.Reddit(client_id=REDDITID,
client_secret=REDDITSECRET,
user_agent=REDDITUA
)
def preload(*_):
"""
This loads whenever plugin starts
Even if you dont need it, you SHOULD put at least
return None, otherwise your plugin wont load
"""
return
def posts(bot: Bot, update: Update, user, args): # pylint: disable=W0613
"""
/r/subreddit
"""
try:
sub = update.message.text.split("/")[2]
subreddit = REDDIT.subreddit(sub)
message = "Hot posts in <b>/r/%s</b>:\n\n" % sub
for post in subreddit.hot(limit=10):
message += ' • <a href="%s">%s</a>\n' % (post.shortlink, post.title)
return message, constants.HTMLTXT
except (praw.exceptions.PRAWException, prawcore.exceptions.PrawcoreException):
pass
COMMANDS = [
{
"command":"/r/",
"function":posts,
"description":"10 hot posts in specifed subreddit",
"inline_support":True
}
]