feat: Status changes whenever it's time to BeReal and if it's too late
This commit is contained in:
parent
775cefc203
commit
81be67064b
@ -4,6 +4,7 @@ import os
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
import database.controller
|
import database.controller
|
||||||
|
import bot.utils.ChangeStatus
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
@ -23,15 +24,19 @@ async def time_to_bereal():
|
|||||||
t = int(time())
|
t = int(time())
|
||||||
subscribers = app.db.get_subscribers()
|
subscribers = app.db.get_subscribers()
|
||||||
|
|
||||||
|
app.loop.create_task(bot.utils.ChangeStatus.switch_to_online(app, t + 120))
|
||||||
|
|
||||||
# Send message to all subscribers
|
# Send message to all subscribers
|
||||||
for subscriber in subscribers:
|
for subscriber in subscribers:
|
||||||
user = await app.fetch_user(subscriber.user_id)
|
user = await app.fetch_user(subscriber.user_id)
|
||||||
await user.send(f"# :warning: It's time to BeReal.\nOpen BeReal. to post what you are doing right now.\n<t:{t}:R>")
|
await user.send(f"# :warning: Time to BeReal. :warning:\nCapture a BeReal and see what you friends are up to!\n<t:{t}:R>")
|
||||||
|
|
||||||
|
|
||||||
app.time_to_bereal = time_to_bereal
|
app.time_to_bereal = time_to_bereal
|
||||||
|
|
||||||
@app.event
|
@app.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("Running")
|
print("Running")
|
||||||
|
await bot.utils.ChangeStatus.switch_to_dnd(app)
|
||||||
await load_cogs()
|
await load_cogs()
|
||||||
await app.tree.sync()
|
await app.tree.sync()
|
||||||
|
19
bot/utils/ChangeStatus.py
Normal file
19
bot/utils/ChangeStatus.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import asyncio
|
||||||
|
import discord, time
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
async def switch_to_online(app: commands.Bot, expiration: int):
|
||||||
|
await app.change_presence(
|
||||||
|
status=discord.Status.online,
|
||||||
|
activity=discord.Activity(name="⚠️ Time to BeReal. | /subscribe", type=discord.ActivityType.watching),
|
||||||
|
)
|
||||||
|
await asyncio.sleep(expiration - time.time())
|
||||||
|
await switch_to_dnd(app)
|
||||||
|
|
||||||
|
|
||||||
|
async def switch_to_dnd(app: commands.Bot):
|
||||||
|
await app.change_presence(
|
||||||
|
status=discord.Status.do_not_disturb,
|
||||||
|
activity=discord.Activity(name="BeReal. Notifications | /subscribe", type=discord.ActivityType.watching),
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user