This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetabot.py
69 lines (55 loc) · 2.24 KB
/
metabot.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import asyncio
import discord
import logging
import praw
import time
from discord.ext import commands
bot = commands.Bot()
logging.basicConfig(
filename="output.log",
filemode='a',
format="[%(asctime)s] [%(levelname)s] %(message)s",
datefmt="%H:%M:%S",
level=logging.INFO
)
reddit = praw.Reddit(
client_id="", # Replace with your Reddit app client ID
client_secret="", # Replace with your Reddit app client secret
user_agent="" # Replace with descriptive user agent for Reddit
)
subreddit = "fortnitebrmeta"
async def check_for_posts():
await bot.wait_until_ready()
bot_started_at = time.time()
logging.info(f"Logged into Discord as user: {bot.user.name}.")
cache = []
for submission in reddit.subreddit(subreddit).new(limit=10):
cache.append(submission.id)
try:
while True:
for submission in reddit.subreddit(subreddit).new(limit=10):
if submission.id not in cache:
if submission.created > bot_started_at:
logging.info(f"{submission.title} was posted by /u/{submission.author.name}")
channel = bot.get_channel(00000000000000000) # Replace with Discord channel ID
embed = discord.Embed(
title=submission.title,
url=submission.url,
color=discord.Color(0xff460a),
description=submission.selftext[0:250]
)
embed.set_author(name=f"/u/{submission.author.name}", url=f"https://reddit.com/u/{submission.author.name}")
embed.set_footer(text="Please don't forget to leave a ✅ react on this message when claiming the post!")
if len(embed.description) > 250:
embed.description = embed.description + "..."
await channel.send(embed=embed)
cache.append(submission.id)
await asyncio.sleep(5)
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
logging.error(e)
time.sleep(30)
pass
bot.loop.create_task(check_for_posts())
bot.run("") # Discord bot token