diff --git a/techsupport_bot/commands/application.py b/techsupport_bot/commands/application.py index 70530850..952b3999 100644 --- a/techsupport_bot/commands/application.py +++ b/techsupport_bot/commands/application.py @@ -12,6 +12,7 @@ import ui from core import auxiliary, cogs, extensionconfig from discord import app_commands +from functions import holidays if TYPE_CHECKING: import bot @@ -182,6 +183,8 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None config (munch.Munch): The guild config for the executing loop guild (discord.Guild): The guild the loop is executing for """ + if holidays.isGuildClosed(self.bot, guild): + return channels = config.extensions.application.notification_channels.value for channel in channels: channel = guild.get_channel(int(channel)) @@ -719,6 +722,9 @@ async def check_if_can_apply(self: Self, applicant: discord.Member) -> bool: Returns: bool: True if they can apply, False if they cannot apply """ + if holidays.isGuildClosed(self.bot, applicant.guild): + return False + config = self.bot.guild_configs[str(applicant.guild.id)] role = applicant.guild.get_role( int(config.extensions.application.application_role.value) @@ -992,7 +998,8 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None embed.description = f"{embed.description}\n{event}" else: embed.description = f"{event}" - await channel.send(embed=embed) + if not holidays.isGuildClosed(self.bot, guild): + await channel.send(embed=embed) apps = await self.get_applications_by_status(ApplicationStatus.PENDING, guild) if not apps: @@ -1012,7 +1019,8 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None embed.description = "\n".join(list_of_applicants) - await channel.send(embed=embed) + if not holidays.isGuildClosed(self.bot, guild): + await channel.send(embed=embed) async def wait(self: Self, config: munch.Munch, guild: discord.Guild) -> None: """The queues the pending application reminder based on the cron config diff --git a/techsupport_bot/commands/duck.py b/techsupport_bot/commands/duck.py index 8820e2ea..ca5da744 100644 --- a/techsupport_bot/commands/duck.py +++ b/techsupport_bot/commands/duck.py @@ -16,6 +16,7 @@ from core import auxiliary, cogs, extensionconfig, moderation from discord import Color as embed_colors from discord.ext import commands +from functions import holidays if TYPE_CHECKING: import bot @@ -157,6 +158,9 @@ async def execute( banned_user (discord.User, optional): A user that is not allowed to claim the duck. Defaults to None. """ + if holidays.isGuildClosed(self.bot, guild): + return + if not channel: config = self.bot.guild_configs[str(guild.id)] log_channel = config.get("logging_channel") diff --git a/techsupport_bot/commands/factoids.py b/techsupport_bot/commands/factoids.py index 5c0fd44c..4cbca3d7 100644 --- a/techsupport_bot/commands/factoids.py +++ b/techsupport_bot/commands/factoids.py @@ -35,6 +35,7 @@ from croniter import CroniterBadCronError from discord import app_commands from discord.ext import commands +from functions import holidays if TYPE_CHECKING: import bot @@ -1176,7 +1177,8 @@ async def cronjob( content = factoid.message try: - message = await channel.send(content=content, embed=embed) + if not holidays.isGuildClosed(self.bot, ctx.guild): + message = await channel.send(content=content, embed=embed) except discord.errors.HTTPException as exception: config = self.bot.guild_configs[str(ctx.guild.id)] @@ -1189,9 +1191,11 @@ async def cronjob( exception=exception, ) # Sends the raw factoid instead of the embed as fallback - message = await channel.send(content=factoid.message) + if not holidays.isGuildClosed(self.bot, ctx.guild): + message = await channel.send(content=factoid.message) - await self.send_to_irc(channel, message, factoid.message) + if not holidays.isGuildClosed(self.bot, ctx.guild): + await self.send_to_irc(channel, message, factoid.message) @commands.group( brief="Executes a factoid command", diff --git a/techsupport_bot/commands/kanye.py b/techsupport_bot/commands/kanye.py index 66e21e34..8aac652e 100644 --- a/techsupport_bot/commands/kanye.py +++ b/techsupport_bot/commands/kanye.py @@ -10,6 +10,7 @@ import munch from core import auxiliary, cogs, extensionconfig from discord.ext import commands +from functions import holidays if TYPE_CHECKING: import bot @@ -100,6 +101,8 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None config (munch.Munch): The guild config where the loop is taking place guild (discord.Guild): The guild where the loop is taking place """ + if holidays.isGuildClosed(self.bot, guild): + return quote = await self.get_quote() embed = self.generate_themed_embed(quote=quote) diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 86f6301a..b41a2081 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -24,6 +24,7 @@ import ui from core import auxiliary, cogs, extensionconfig from discord.ext import commands +from functions import holidays if TYPE_CHECKING: import bot @@ -86,6 +87,10 @@ async def on_message(self: Self, message: discord.Message) -> None: Args: message (discord.Message): Every sent message, gets filtered to only dms """ + channel = Ts_client.get_channel(MODMAIL_FORUM_ID) + if holidays.isGuildClosed(Ts_client, channel.guild): + await message.add_reaction("🎄") + return if isinstance(message.channel, discord.DMChannel) and not message.author.bot: # Log all DMs regardless of what happens to them diff --git a/techsupport_bot/commands/news.py b/techsupport_bot/commands/news.py index 957d1262..d8d1c562 100644 --- a/techsupport_bot/commands/news.py +++ b/techsupport_bot/commands/news.py @@ -12,6 +12,7 @@ from botlogging import LogContext, LogLevel from core import cogs, extensionconfig from discord import app_commands +from functions import holidays if TYPE_CHECKING: import bot @@ -180,6 +181,8 @@ async def execute(self: Self, config: munch.Munch, guild: discord.Guild) -> None config (munch.Munch): The guild config for the guild looping guild (discord.Guild): The guild where the loop is running """ + if holidays.isGuildClosed(self.bot, guild): + return channel = guild.get_channel(int(config.extensions.news.channel.value)) if not channel: return diff --git a/techsupport_bot/core/databases.py b/techsupport_bot/core/databases.py index 7f5be522..87ebe171 100644 --- a/techsupport_bot/core/databases.py +++ b/techsupport_bot/core/databases.py @@ -192,6 +192,20 @@ class Grab(bot.db.Model): ) nsfw: bool = bot.db.Column(bot.db.Boolean, default=False) + class HolidayClose(bot.db.Model): + """The postgres table for holiday closures + Currently used in holidays.py + + Attributes: + pk (int): The automatic primary key + guild_id (str): The ID of the user banned from modmail + """ + + __tablename__ = "holiday_closeda" + + pk = bot.db.Column(bot.db.Integer, primary_key=True, autoincrement=True) + guild_id: str = bot.db.Column(bot.db.String, default=None) + class IRCChannelMapping(bot.db.Model): """The postgres table for IRC->discord maps Currently used in relay.py @@ -371,6 +385,7 @@ class Votes(bot.db.Model): bot.models.Factoid = Factoid bot.models.FactoidJob = FactoidJob bot.models.Grab = Grab + bot.models.HolidayClose = HolidayClose bot.models.IRCChannelMapping = IRCChannelMapping bot.models.ModmailBan = ModmailBan bot.models.UserNote = UserNote diff --git a/techsupport_bot/functions/__init__.py b/techsupport_bot/functions/__init__.py index df256aa0..7dae9ff5 100644 --- a/techsupport_bot/functions/__init__.py +++ b/techsupport_bot/functions/__init__.py @@ -1,4 +1,5 @@ """Functions are commandless cogs""" from .automod import * +from .holidays import * from .nickname import * diff --git a/techsupport_bot/functions/holidays.py b/techsupport_bot/functions/holidays.py new file mode 100644 index 00000000..63f9827a --- /dev/null +++ b/techsupport_bot/functions/holidays.py @@ -0,0 +1,10 @@ +import discord + + +async def isGuildClosed(bot: object, guild: discord.Guild) -> bool: + db_enty = await bot.models.HolidayClose.query.where( + bot.models.HolidayClose.guild_id == str(guild.id) + ).gino.first() + if db_enty: + return True + return False