Skip to content

Commit

Permalink
add auto-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipdev committed Sep 21, 2023
1 parent db66253 commit f91debe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scnewsbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def _get_version(self) -> str:
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(
Expand Down
4 changes: 4 additions & 0 deletions scnewsbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def extensions(self) -> list:
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")
Expand Down

0 comments on commit f91debe

Please sign in to comment.