|
|
@ -50,14 +50,19 @@ def format_entry(entry, author=None): |
|
|
|
|
|
|
|
return embed |
|
|
|
|
|
|
|
async def post_news(bot, guild, index): |
|
|
|
async def post_news(bot, guild, entry_id): |
|
|
|
news_json = data.load_guild_data(guild.id, NEWS_JSON) |
|
|
|
if "news_channel" not in news_json: |
|
|
|
return |
|
|
|
return "News channel not set." |
|
|
|
|
|
|
|
channel = get(guild.channels, id=news_json["news_channel"]) |
|
|
|
feed = await ksp_feed() |
|
|
|
return await channel.send(embed=format_entry(feed.entries[index], author=feed.feed.author)) |
|
|
|
entries_with_id = list(filter(lambda e: e.id == f"https://ksp.mff.cuni.cz/news_{entry_id}", feed.entries)) |
|
|
|
if len(entries_with_id) == 0: |
|
|
|
return f"Entry with id ``{entry_id}`` not found." |
|
|
|
|
|
|
|
await channel.send(embed=format_entry(entries_with_id[0], author=feed.feed.author)) |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
class News(commands.Cog): |
|
|
@ -79,9 +84,11 @@ class News(commands.Cog): |
|
|
|
return await ctx.respond(f"News channel set to {channel.mention}.", ephemeral=True) |
|
|
|
|
|
|
|
@news.command(description="Synchronize news feed.") |
|
|
|
@discord.option("index", int, description="Send index-th most recent entry. (indexed from 0)") |
|
|
|
async def post_news(self, ctx, index: int): |
|
|
|
await post_news(self.bot, ctx.guild, index) |
|
|
|
@discord.option("id", str, description="Id of entry to send.") |
|
|
|
async def post_news(self, ctx, id: int): |
|
|
|
err = await post_news(self.bot, ctx.guild, id) |
|
|
|
if err: |
|
|
|
return await ctx.respond(err, ephemeral=True) |
|
|
|
return await ctx.respond(f"News posted.", ephemeral=True) |
|
|
|
|
|
|
|
|
|
|
|