mirror of
https://github.com/Nick80835/microbot
synced 2025-08-22 10:09:40 +00:00
add redb
This commit is contained in:
parent
fdc48d8b20
commit
eeb8870d94
@ -1,7 +1,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
import io
|
import io
|
||||||
from random import choice
|
from random import choice, shuffle
|
||||||
|
|
||||||
import praw
|
import praw
|
||||||
|
|
||||||
@ -37,6 +37,18 @@ async def titlefetcherfallback(sub):
|
|||||||
return choice(hot_list).title
|
return choice(hot_list).title
|
||||||
|
|
||||||
|
|
||||||
|
async def bodyfetcherfallback(sub):
|
||||||
|
hot = REDDIT.subreddit(sub).hot()
|
||||||
|
hot_list = list(hot.__iter__())
|
||||||
|
shuffle(hot_list)
|
||||||
|
|
||||||
|
for i in hot_list:
|
||||||
|
if i.selftext:
|
||||||
|
return i.selftext, i.title
|
||||||
|
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
async def imagefetcher(event, sub):
|
async def imagefetcher(event, sub):
|
||||||
image_url = False
|
image_url = False
|
||||||
|
|
||||||
@ -74,6 +86,27 @@ async def titlefetcher(event, sub):
|
|||||||
await event.reply(title)
|
await event.reply(title)
|
||||||
|
|
||||||
|
|
||||||
|
async def bodyfetcher(event, sub):
|
||||||
|
await event.edit(f"`Fetching from `**r/{sub}**`…`")
|
||||||
|
|
||||||
|
for _ in range(10):
|
||||||
|
post = REDDIT.subreddit(sub).random()
|
||||||
|
|
||||||
|
if not post:
|
||||||
|
body, title = await titlefetcherfallback(sub)
|
||||||
|
elif post.selftext:
|
||||||
|
body = post.selftext
|
||||||
|
title = post.title
|
||||||
|
|
||||||
|
if not body:
|
||||||
|
continue
|
||||||
|
|
||||||
|
await event.edit(f"**{title}**\n\n{body}")
|
||||||
|
return
|
||||||
|
|
||||||
|
await event.edit(f"`Failed to find any valid content on `**r/{sub}**`!`")
|
||||||
|
|
||||||
|
|
||||||
@ldr.add(pattern="redi")
|
@ldr.add(pattern="redi")
|
||||||
async def redimg(event):
|
async def redimg(event):
|
||||||
sub = event.pattern_match.group(1)
|
sub = event.pattern_match.group(1)
|
||||||
@ -94,6 +127,16 @@ async def redtit(event):
|
|||||||
await event.reply("Syntax: .redt <subreddit name>")
|
await event.reply("Syntax: .redt <subreddit name>")
|
||||||
|
|
||||||
|
|
||||||
|
@ldr.add(pattern="redb")
|
||||||
|
async def redbod(event):
|
||||||
|
sub = event.pattern_match.group(1)
|
||||||
|
|
||||||
|
if sub:
|
||||||
|
await bodyfetcher(event, sub)
|
||||||
|
else:
|
||||||
|
await event.edit("Syntax: .redb <subreddit name>")
|
||||||
|
|
||||||
|
|
||||||
@ldr.add(pattern="suffer")
|
@ldr.add(pattern="suffer")
|
||||||
async def makemesuffer(event):
|
async def makemesuffer(event):
|
||||||
await imagefetcher(event, "MakeMeSuffer")
|
await imagefetcher(event, "MakeMeSuffer")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user