feat(bot):

This commit is contained in:
Nyeki.py
2024-10-17 01:11:37 -03:00
parent 5011ab5f90
commit c745df0a9d
19 changed files with 1273 additions and 439 deletions
+97 -1
View File
@@ -1,4 +1,7 @@
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
import sys
import asyncio
import discord
from discord import errors
@@ -169,6 +172,32 @@ class Mods(base.Cog):
)
@commands.command()
@checks.is_moderator()
@transactions.atomic()
async def reports(self, ctx: commands.Context) -> None:
"""
Shows the next report to review.
"""
report = (
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
.order_by("id")
.limit(1)
.first()
.select_related("call")
.prefetch_related("call__call_rss", "call__call_rss__profile")
)
if report is None:
await ctx.send("✅ You're up to date! No reports left to check.")
return
await ctx.send(
embed=embeds.ReportEmbed(self.bot, report),
view=views.ReportView(self.bot, report),
)
@commands.command(aliases=["mod"])
@commands.is_owner()
@transactions.atomic()
async def moderator(
@@ -199,6 +228,73 @@ class Mods(base.Cog):
f"✅ **{profile_row.name}**'s moderator status was set to `{"on" if user_row.is_moderator else "off"}`."
)
@commands.command()
@commands.is_owner()
@transactions.atomic()
async def shutdown(
self, ctx: commands.Context, seconds: int = 60, *, reason: str | None
) -> None:
"""
Notifies all the in-call users of the scheduled shutdown and shuts down Payphone after x seconds.
Options:
- `[<seconds>]`: The amount of seconds to wait before shutdown.
- `[<reason>]`: The reason of the shutdown.
"""
oncall_channel_ids = list(
await self.bot.redis.smembers(constants.CHANNELS_ONCALL_SET)
)
searching_channel_ids = list(
await self.bot.redis.smembers(constants.CHANNELS_SEARCH_QUEUE)
)
channel_ids = [int(c) for c in oncall_channel_ids] + [
int(c) for c in searching_channel_ids
]
await ctx.send(f"⚡ Notifying `{len(channel_ids)}` channels of the shutdown.")
for channel_id in channel_ids:
try:
await self.bot.get_partial_messageable(channel_id).send(
f"⚡ Payphone will be shutdown <t:{int((datetime.now(timezone.utc) + timedelta(seconds=seconds)).timestamp())}:R> due to a maintenance restart."
+ (" Reason: " + reason if reason is not None else "")
)
except errors.DiscordException:
pass
await ctx.send(
f"⚡ All channels were notified of the shutdown. Payphone will shut down <t:{int((datetime.now(timezone.utc) + timedelta(seconds=seconds)).timestamp())}:R>."
)
await asyncio.sleep(seconds)
oncall_channel_ids = list(
await self.bot.redis.smembers(constants.CHANNELS_ONCALL_SET)
)
searching_channel_ids = list(
await self.bot.redis.smembers(constants.CHANNELS_SEARCH_QUEUE)
)
channel_ids = [int(c) for c in oncall_channel_ids] + [
int(c) for c in searching_channel_ids
]
for channel_id in channel_ids:
try:
await self.bot.get_partial_messageable(channel_id).send(
"⚡ The call will be ended due to a scheduled shutdown."
)
except errors.DiscordException:
pass
await ctx.send("⚡ Payphone was shut down.")
sys.exit()
def setup(b: bot.Payphone) -> None:
"""Load the cog into the bot.