diff options
| author | 2020-04-20 15:10:13 +0300 | |
|---|---|---|
| committer | 2020-04-20 15:10:13 +0300 | |
| commit | d3a1e346ab65f65e8addda68a2e5dc6860739448 (patch) | |
| tree | 7ee08b518e475d9b47c8e6a42672ce701ebbbee3 | |
| parent | Created PEP news task + minor changes in `News` (diff) | |
Added new function `News.get_webhook_names` + new variable `News.webhook_names`
Function fetch display names of these mail lists, that bot will post. These names will be used on Webhook author names. `News.webhook_names` storage these name and display name pairs.
| -rw-r--r-- | bot/cogs/news.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/bot/cogs/news.py b/bot/cogs/news.py index 6e9441997..878e533ef 100644 --- a/bot/cogs/news.py +++ b/bot/cogs/news.py @@ -19,7 +19,9 @@ class News(Cog): def __init__(self, bot: Bot): self.bot = bot + self.webhook_names = {} self.bot.loop.create_task(self.sync_maillists()) + self.bot.loop.create_task(self.get_webhook_names()) self.post_pep_news.start() @@ -39,6 +41,17 @@ class News(Cog): await self.bot.api_client.put("bot/bot-settings/news", json=response) + async def get_webhook_names(self) -> None: + """Get webhook author names from maillist API.""" + await self.bot.wait_until_guild_available() + + async with self.bot.http_session.get("https://mail.python.org/archives/api/lists") as resp: + lists = await resp.json() + + for mail in lists: + if mail["name"].split("@")[0] in constants.PythonNews.mail_lists: + self.webhook_names[mail["name"].split("@")[0]] = mail["display_name"] + @loop(minutes=20) async def post_pep_news(self) -> None: """Fetch new PEPs and when they don't have announcement in #python-news, create it.""" |