From f91debeb9088f6fdd335588642035e341a9c9720 Mon Sep 17 00:00:00 2001 From: mudkipdev Date: Wed, 20 Sep 2023 19:12:22 -0600 Subject: [PATCH] add auto-publish --- example.config.toml | 2 ++ scnewsbot/bot.py | 11 +++++++++++ scnewsbot/utils.py | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/example.config.toml b/example.config.toml index ea4d69f..3d80372 100644 --- a/example.config.toml +++ b/example.config.toml @@ -7,7 +7,9 @@ extensions = [ "extensions.announcements", "extensions.templates" ] + repost_channels = [] +publish_channels = [] [permissions] # This works in a whitelist mode. The invoker of the command must be in an allowed guild and diff --git a/scnewsbot/bot.py b/scnewsbot/bot.py index 0b2815d..9eb36d9 100644 --- a/scnewsbot/bot.py +++ b/scnewsbot/bot.py @@ -45,6 +45,17 @@ class CoreCog(commands.Cog, name="Core"): async def on_ready(self) -> None: print("The bot is now ready.") + @commands.Cog.listener() + async def on_message(self, message: discord.Message) -> None: + if ( + message.channel.id in self.bot.config.publish_channels + and message.channel.type is discord.ChannelType.news + ): + try: + await message.publish() + except discord.Forbidden: + pass + @commands.hybrid_command(description="Shows you some info about the bot.") async def info(self, ctx: commands.Context) -> None: embed = discord.Embed( diff --git a/scnewsbot/utils.py b/scnewsbot/utils.py index 174f168..0e57743 100644 --- a/scnewsbot/utils.py +++ b/scnewsbot/utils.py @@ -25,6 +25,10 @@ class Config: def repost_channels(self) -> list[int]: return self.config["bot"].get("repost_channels", []) + @property + def publish_channels(self) -> list[int]: + return self.config["bot"].get("publish_channels", []) + @property def allowed_guilds(self) -> list: return self._get_allowed_objects("allowed_guilds")