feat(bot): ⚰️ Remove p.shutdown command.
This commit is contained in:
@@ -228,99 +228,6 @@ class Mods(base.Cog):
|
|||||||
f"✅ **{profile_row.name}**'s moderator status was set to `{"on" if user_row.is_moderator else "off"}`."
|
f"✅ **{profile_row.name}**'s moderator status was set to `{"on" if user_row.is_moderator else "off"}`."
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command(aliases=["restart"])
|
|
||||||
@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.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if seconds > 0:
|
|
||||||
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
|
|
||||||
]
|
|
||||||
|
|
||||||
await ctx.send(f"⚡ Notifying `{len(channel_ids)}` channels of hang up.")
|
|
||||||
|
|
||||||
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(
|
|
||||||
"⚡ Notified all channels of calls hang up. Updating Payphone's status..."
|
|
||||||
)
|
|
||||||
|
|
||||||
await self.bot.change_presence(
|
|
||||||
activity=discord.CustomActivity(name="Payphone is restarting."),
|
|
||||||
status=discord.Status.do_not_disturb,
|
|
||||||
)
|
|
||||||
|
|
||||||
await self.bot.redis.delete(constants.CHANNELS_ONCALL_SET)
|
|
||||||
|
|
||||||
calls = await models.Call.filter(ended_at=None)
|
|
||||||
|
|
||||||
call_ids = [call.id for call in calls]
|
|
||||||
if call_ids:
|
|
||||||
await self.bot.redis.sadd(constants.CALL_IDS_TO_FLUSH, *call_ids)
|
|
||||||
|
|
||||||
await models.Call.filter(ended_at=None).update(
|
|
||||||
ended_at=datetime.now(timezone.utc)
|
|
||||||
)
|
|
||||||
|
|
||||||
await flush_messages.flush()
|
|
||||||
|
|
||||||
await ctx.send("⚡ Messages were flushed, payphone is ready to shut down.")
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def stats(
|
async def stats(
|
||||||
|
|||||||
Reference in New Issue
Block a user