Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b09d1a348 | |||
| 01e5208cba |
@@ -55,7 +55,7 @@ async def post_reddit_periodically():
|
|||||||
async def get_latest_post(subreddit):
|
async def get_latest_post(subreddit):
|
||||||
post_limit = os.getenv("POST_LIMIT", 20)
|
post_limit = os.getenv("POST_LIMIT", 20)
|
||||||
url = f"https://www.reddit.com/r/{subreddit}/hot.rss?limit={post_limit}"
|
url = f"https://www.reddit.com/r/{subreddit}/hot.rss?limit={post_limit}"
|
||||||
headers = {"User-Agent": "Mozilla/5.0 (compatible; ich_iel-Bot/0.6.0)"}
|
headers = {"User-Agent": "Mozilla/5.0 (compatible; ich_iel-Bot/0.6.1)"}
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logging.error(f"Failed to fetch RSS feed: {response.status_code}")
|
logging.error(f"Failed to fetch RSS feed: {response.status_code}")
|
||||||
@@ -121,7 +121,7 @@ async def setChannel(message):
|
|||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def version(message):
|
async def version(message):
|
||||||
await message.channel.send("Version 0.6.0 is running\nSource code: https://github.com/michelleDeko/ich_iel-bot")
|
await message.channel.send("Version 0.6.1 is running\nSource code: https://github.com/michelleDeko/ich_iel-bot")
|
||||||
|
|
||||||
# the cat bot died, so i wanted to add this command to this bot
|
# the cat bot died, so i wanted to add this command to this bot
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@@ -176,6 +176,28 @@ async def racoon(message):
|
|||||||
return
|
return
|
||||||
await message.channel.send(file=fluxer.File(image_bytes, filename="racoon.jpg"))
|
await message.channel.send(file=fluxer.File(image_bytes, filename="racoon.jpg"))
|
||||||
|
|
||||||
|
# i just watched beastars and i realised that this bot needs a bnuy command
|
||||||
|
# maybe I will switch the API later since this one seems to only have gifs
|
||||||
|
@bot.command()
|
||||||
|
async def bnuy(message):
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get("https://api.bunnies.io/v2/loop/random/?media=gif,png") as response:
|
||||||
|
data = await response.json()
|
||||||
|
if response.status != 200 or not data or "media" not in data:
|
||||||
|
await message.channel.send("Failed to fetch image of a bunny")
|
||||||
|
return
|
||||||
|
image_url = data["media"].get("gif")
|
||||||
|
if not image_url:
|
||||||
|
await message.channel.send("Failed to fetch image of a bunny")
|
||||||
|
return
|
||||||
|
file_ext = "gif" if image_url.lower().endswith(".gif") else "png"
|
||||||
|
async with session.get(image_url) as image_response:
|
||||||
|
if image_response.status != 200:
|
||||||
|
await message.channel.send("Failed to fetch image of a bunny")
|
||||||
|
return
|
||||||
|
image_bytes = await image_response.read()
|
||||||
|
await message.channel.send(file=fluxer.File(image_bytes, filename=f"bnuy.{file_ext}"))
|
||||||
|
|
||||||
async def post_reddit():
|
async def post_reddit():
|
||||||
subreddit = os.getenv("SUBREDDIT", "ich_iel")
|
subreddit = os.getenv("SUBREDDIT", "ich_iel")
|
||||||
posts = await get_latest_post(subreddit)
|
posts = await get_latest_post(subreddit)
|
||||||
|
|||||||
Reference in New Issue
Block a user