|
@ -50,14 +50,19 @@ def format_entry(entry, author=None): |
|
|
|
|
|
|
|
|
return embed |
|
|
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) |
|
|
news_json = data.load_guild_data(guild.id, NEWS_JSON) |
|
|
if "news_channel" not in news_json: |
|
|
if "news_channel" not in news_json: |
|
|
return |
|
|
return "News channel not set." |
|
|
|
|
|
|
|
|
channel = get(guild.channels, id=news_json["news_channel"]) |
|
|
channel = get(guild.channels, id=news_json["news_channel"]) |
|
|
feed = await ksp_feed() |
|
|
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): |
|
|
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) |
|
|
return await ctx.respond(f"News channel set to {channel.mention}.", ephemeral=True) |
|
|
|
|
|
|
|
|
@news.command(description="Synchronize news feed.") |
|
|
@news.command(description="Synchronize news feed.") |
|
|
@discord.option("index", int, description="Send index-th most recent entry. (indexed from 0)") |
|
|
@discord.option("id", str, description="Id of entry to send.") |
|
|
async def post_news(self, ctx, index: int): |
|
|
async def post_news(self, ctx, id: int): |
|
|
await post_news(self.bot, ctx.guild, index) |
|
|
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) |
|
|
return await ctx.respond(f"News posted.", ephemeral=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|