diff options
| author | 2020-04-20 11:46:17 +0300 | |
|---|---|---|
| committer | 2020-04-20 11:46:54 +0300 | |
| commit | bb48c5e6fea14bc8ec42b1188ceb5008fa259463 (patch) | |
| tree | 074df9db121f4f375ebc6d1bff0c721822f7ee4f | |
| parent | Added `News` cog loading (diff) | |
Added helper function `News.sync_maillists`
Function sync maillists listing with API, that hold IDs of message that have news. PEPs handling is over RSS, so this will added manually in this function.
| -rw-r--r-- | bot/cogs/news.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bot/cogs/news.py b/bot/cogs/news.py index 8eb8689c2..c850b4192 100644 --- a/bot/cogs/news.py +++ b/bot/cogs/news.py @@ -2,12 +2,35 @@ from discord.ext.commands import Cog from bot.bot import Bot +MAIL_LISTS = [ + "python-ideas", + "python-announce-list", + "pypi-announce" +] + class News(Cog): """Post new PEPs and Python News to `#python-news`.""" def __init__(self, bot: Bot): self.bot = bot + self.bot.loop.create_task(self.sync_maillists()) + + 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 + await self.bot.wait_until_guild_available() + + response = await self.bot.api_client.get("bot/bot-settings/news") + for mail in MAIL_LISTS: + if mail not in response["data"]: + response["data"][mail] = [] + + # Because we are handling PEPs differently, we don't include it to mail lists + if "pep" not in response["data"]: + response["data"]["pep"] = [] + + await self.bot.api_client.put("bot/bot-settings/news", json=response) def setup(bot: Bot) -> None: |