def update_check(self):
await self.bot.wait_until_ready()
self.bot.logger.debug("Started GAF Steam Announcement RSS Update Check Loop")
while not self.bot.is_closed():
response, _, code = await net.get_url("http://steamcommunity.com/groups/TheNeverEndingGAF/rss/")
xml = await response.read()
root = etree.fromstring(xml)
last_pub = dateparser.parse(self.bot.config["pub_dates"]["gaf"])
new_posts = []
for element in root.xpath("//item"):
post_pub = dateparser.parse(element[3].text)
if post_pub > last_pub:
new_posts.append(element)
# Iterate over new posts
for i, p in reversed(list(enumerate(new_posts))):
# Update date if it's the newest post. Should be last elemen iterated through
if i == 0:
self.bot.config["pub_dates"]["gaf"] = p[3].text
await self.bot.update_config()
self.bot.logger.debug("Updated GAF pub date")
# Post to guilds
for guild in self.bot.guilds:
guild_config = await self.bot.get_guild_config(guild.id)
if guild_config["feeds"]["gaf"]["enabled"]:
channel = discord.utils.get(guild.channels, id=guild_config["feeds"]["gaf"]["channel"])
with channel.typing():
if len(html2text.html2text(p.find("description").text)) > 1900:
content = html2text.html2text(p.find("description").text[:1900]) + ". . ."
else:
content = html2text.html2text(p.find("description").text)
embed = discord.Embed(
title="{}".format(p.find("title").text),
colour=discord.Colour.gold(),
url="{}".format(p.find("link").text),
timestamp=dateparser.parse(p[3].text),
description=content
)
embed.set_thumbnail(url="http://www.neverendinggaf.com/graphics/logos/gaf-logo.jpg")
embed.set_footer(text="Author - {}".format(p.find("author").text))
if "@everyone" in content:
message_content = "**New Announcement** - Content Below @everyone"
else:
message_content = "**New Announcement** - Content Below"
message_content += "\n*Author* : {}".format(p.find("author").text)
await channel.send(content=message_content, embed=embed)
self.bot.logger.debug(f"Sent new GAF Steam Announcement to guild {guild} channel {channel}")
await asyncio.sleep(60)
评论列表
文章目录