aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-04-20 12:59:35 +0300
committerGravatar ks129 <[email protected]>2020-04-20 12:59:35 +0300
commitab496d4b059673d9a8f3816119ad5fe37e2787cc (patch)
tree81586af5538a7f8e7559ff9c17e46c7e9d8c07fc
parentAdded #python-news channel webhook to `Webhooks` in constants (diff)
Created helper function `get_webhook` and added property in `News`
`News.get_webhook` fetch discord.Webhook by ID provided in config. `self.webhook` use webhook that it got from this function.
-rw-r--r--bot/cogs/news.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/bot/cogs/news.py b/bot/cogs/news.py
index c850b4192..69305c93d 100644
--- a/bot/cogs/news.py
+++ b/bot/cogs/news.py
@@ -1,5 +1,7 @@
+import discord
from discord.ext.commands import Cog
+from bot import constants
from bot.bot import Bot
MAIL_LISTS = [
@@ -15,10 +17,11 @@ class News(Cog):
def __init__(self, bot: Bot):
self.bot = bot
self.bot.loop.create_task(self.sync_maillists())
+ self.webhook = self.bot.loop.create_task(self.get_webhook())
async def sync_maillists(self) -> None:
"""Sync currently in-use maillists with API."""
- # Wait until guild is available to avoid running before API is ready
+ # Wait until guild is available to avoid running before everything is ready
await self.bot.wait_until_guild_available()
response = await self.bot.api_client.get("bot/bot-settings/news")
@@ -32,6 +35,10 @@ class News(Cog):
await self.bot.api_client.put("bot/bot-settings/news", json=response)
+ async def get_webhook(self) -> discord.Webhook:
+ """Get #python-news channel webhook."""
+ return await self.bot.fetch_webhook(constants.Webhooks.python_news)
+
def setup(bot: Bot) -> None:
"""Add `News` cog."""