Add sorting to reddit.py
This commit is contained in:
@@ -20,9 +20,9 @@ class Admin(commands.Cog):
|
||||
try:
|
||||
self.bot.load_extension(cog)
|
||||
except Exception as e:
|
||||
await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}')
|
||||
await ctx.send(f'**ERROR:** {type(e).__name__} - {e}')
|
||||
else:
|
||||
await ctx.send('**`SUCCESS`**')
|
||||
await ctx.send('**SUCCESS**')
|
||||
|
||||
|
||||
@commands.command(name="unload", hidden=True)
|
||||
@@ -34,9 +34,9 @@ class Admin(commands.Cog):
|
||||
try:
|
||||
self.bot.unload_extension(cog)
|
||||
except Exception as e:
|
||||
await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}')
|
||||
await ctx.send(f'**ERROR:** {type(e).__name__} - {e}')
|
||||
else:
|
||||
await ctx.send('**`SUCCESS`**')
|
||||
await ctx.send('**SUCCESS**')
|
||||
|
||||
|
||||
@commands.command(name="reload", hidden=True)
|
||||
@@ -49,9 +49,9 @@ class Admin(commands.Cog):
|
||||
self.bot.unload_extension(cog)
|
||||
self.bot.load_extension(cog)
|
||||
except Exception as e:
|
||||
await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}')
|
||||
await ctx.send(f'**ERROR:** {type(e).__name__} - {e}')
|
||||
else:
|
||||
await ctx.send('**`SUCCESS`**')
|
||||
await ctx.send('**SUCCESS**')
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
||||
@@ -24,8 +24,9 @@ class Help(commands.Cog):
|
||||
embed.add_field(name="Owner", value=self.bot.AppInfo.owner, inline=True)
|
||||
embed.add_field(name="Command Prefix", value=PREFIX, inline=True)
|
||||
embed.add_field(name="Source Code", value="[GitHub](https://github.com/crammk/aquabot)", inline=True)
|
||||
embed.add_field(name="Help", value="Use the 'help' to get a list of commands!")
|
||||
|
||||
footer_text = "This Bot is a project by [MarcMK](https://marcmk.de)."
|
||||
footer_text = "This Bot is a project by MarcMK."
|
||||
embed.set_footer(text=footer_text)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@@ -18,22 +18,33 @@ class Reddit(commands.Cog):
|
||||
|
||||
|
||||
@commands.command(name="reddit")
|
||||
async def reddit(self, ctx, sub: str):
|
||||
async def reddit(self, ctx, sub: str, sorting="hot", time_filter="all"):
|
||||
"""
|
||||
Send a post from a subreddit to chat
|
||||
Send a post from a subreddit to chat. Timefilters: all, day, hour, month, week, year
|
||||
"""
|
||||
reddit = praw.Reddit(client_id=REDDIT_CLIENT_ID,
|
||||
client_secret=REDDIT_CLIENT_SECRET,
|
||||
user_agent=REDDIT_CLIENT_USERAGENT)
|
||||
|
||||
posts = reddit.subreddit(sub).hot()
|
||||
try:
|
||||
if sorting == "hot":
|
||||
posts = reddit.subreddit(sub).hot()
|
||||
elif sorting == "top":
|
||||
posts = reddit.subreddit(sub).top(time_filter)
|
||||
elif sorting == "new":
|
||||
posts = reddit.subreddit(sub).new()
|
||||
|
||||
except ValueError as e:
|
||||
await ctx.send(f"Invalid Argument: {e}")
|
||||
|
||||
# WORKS
|
||||
rand_post = random.randint(1, 100)
|
||||
# Make sure you're not sending a pinned post
|
||||
for i in range(0, rand_post):
|
||||
post = next(x for x in posts if not x.stickied)
|
||||
submission = next(x for x in posts if not x.stickied)
|
||||
|
||||
await ctx.send(f"> '{post.title}' by {post.author.name}")
|
||||
await ctx.send(post.url)
|
||||
await ctx.send(f"'{submission.title}' by {submission.author.name} - 🔼 {submission.score}")
|
||||
await ctx.send(submission.url)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
||||
Reference in New Issue
Block a user