bereal-discord/bot/app.py

45 lines
1.2 KiB
Python

from time import time
import discord, asyncio
import os
from discord.ext import commands
from discord import app_commands
import database.controller
import bot.utils.ChangeStatus
intents = discord.Intents.default()
intents.members = True
intents.dm_messages = True
app = commands.Bot(command_prefix=",", intents=intents)
app.db = database.controller.Database("database.db")
# load cogs
async def load_cogs():
for filename in os.listdir("bot/commands"):
if filename.endswith(".py"):
await app.load_extension(f"bot.commands.{filename[:-3]}")
async def time_to_bereal():
# Get subscribers
t = int(time())
subscribers = app.db.get_subscribers()
app.loop.create_task(bot.utils.ChangeStatus.switch_to_online(app, t + 120))
# Send message to all subscribers
for subscriber in subscribers:
try:
user = await app.fetch_user(subscriber.user_id)
await user.send(f"# :warning: Time to BeReal. :warning:\nCapture a BeReal and see what you friends are up to!\n<t:{t}:R>")
except:
pass
app.time_to_bereal = time_to_bereal
@app.event
async def on_ready():
print("Running")
await bot.utils.ChangeStatus.switch_to_dnd(app)
await load_cogs()
await app.tree.sync()