video urls can now be edited

This commit is contained in:
mudkipdev
2023-09-20 18:51:09 -06:00
parent 924cd1df8d
commit db662539ea
3 changed files with 63 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "scnewsbot" name = "scnewsbot"
version = "1.0.0" version = "1.0.1"
description = "A bot for the r/starcitizen Discord server." description = "A bot for the r/starcitizen Discord server."
authors = ["mudkipdev <mudkip@mudkip.dev>"] authors = ["mudkipdev <mudkip@mudkip.dev>"]
license = "MIT" license = "MIT"

View File

@@ -3,7 +3,7 @@ from discord.ext import commands
import discord import discord
from utils import Config from utils import Config
VERSION = "1.0.0" VERSION = "1.0.1"
INTENTS = discord.Intents.default() INTENTS = discord.Intents.default()
INTENTS.message_content = True INTENTS.message_content = True
INTENTS.members = True INTENTS.members = True

View File

@@ -20,10 +20,16 @@ INSTRUCTIONS = """\
""" """
async def get_ping_message(message: discord.Message, /) -> Optional[discord.Message]: async def get_follow_up_message(
async for ping in message.channel.history(limit=1, after=message.created_at): announcement: discord.Message, /, *, limit: int
if ping.author.id == message._state.user.id and ping.mentions: ) -> Optional[discord.Message]:
return ping index = 0
async for message in announcement.channel.history(after=announcement.created_at):
index += 1
if message.author.id == announcement._state.user.id and index == limit:
return message
def reformat_description(description: str) -> str: def reformat_description(description: str) -> str:
@@ -94,7 +100,11 @@ class AnnouncementCog(commands.Cog, name="Announcements"):
if message.author != self.bot.user and not message.embeds: if message.author != self.bot.user and not message.embeds:
await ctx.reply("That is not an announcement.") await ctx.reply("That is not an announcement.")
ping_message = await get_ping_message(message) video_message = await get_follow_up_message(message, limit=1)
ping_message = await get_follow_up_message(message, limit=2)
if video_message:
await video_message.delete()
if ping_message: if ping_message:
await ping_message.delete() await ping_message.delete()
@@ -236,7 +246,7 @@ class Announcement:
ping = None ping = None
ping_preview = None ping_preview = None
ping_message = await get_ping_message(message) ping_message = await get_follow_up_message(message, limit=2)
if ping_message: if ping_message:
split_message = ping_message.content.split(" - ") split_message = ping_message.content.split(" - ")
@@ -249,6 +259,7 @@ class Announcement:
url = None url = None
description = embed.description description = embed.description
video_message = await get_follow_up_message(message, limit=1)
if embed.description is not None: if embed.description is not None:
if len(embed.description.split("\n\n")) > 0: if len(embed.description.split("\n\n")) > 0:
@@ -259,7 +270,7 @@ class Announcement:
title=embed.title, title=embed.title,
url=url, url=url,
description=description, description=description,
video_url=message.content, video_url=video_message.content,
image_url=embed.image.url, image_url=embed.image.url,
channel=message.channel, channel=message.channel,
ping=ping, ping=ping,
@@ -356,6 +367,23 @@ class AnnouncementBuilderView(discord.ui.View):
) )
) )
@discord.ui.button(
custom_id="cancel", label="Cancel", style=discord.ButtonStyle.danger, row=2
)
async def cancel(
self, interaction: discord.Interaction, button: discord.ui.Button
) -> None:
if not self._has_permission(interaction.user):
await interaction.response.send_message(
"You cannot use this menu.", ephemeral=True
)
return
self.stop()
await interaction.response.send_message(
"Cancelled posting/editing this announcement."
)
@discord.ui.button(custom_id="anonymous", label="Anonymous?", row=2) @discord.ui.button(custom_id="anonymous", label="Anonymous?", row=2)
async def toggle_anonymous( async def toggle_anonymous(
self, interaction: discord.Interaction, button: discord.ui.Button self, interaction: discord.Interaction, button: discord.ui.Button
@@ -419,17 +447,20 @@ class AnnouncementBuilderView(discord.ui.View):
) )
if self.announcement_builder.edit: if self.announcement_builder.edit:
await interaction.response.send_message( await interaction.response.send_message("Your announcement was edited! 🎉")
"Your announcement was edited! 🎉", ephemeral=True
)
self.stop() self.stop()
embed = await self.announcement_builder.get_embed(bot=interaction.client) embed = await self.announcement_builder.get_embed(bot=interaction.client)
embed.remove_footer() embed.remove_footer()
await self.announcement_builder.message.edit( await self.announcement_builder.message.edit(embed=embed)
content=self.announcement_builder.announcement.video_url, embed=embed video_message = await get_follow_up_message(
self.announcement_builder.message, limit=1
) )
await video_message.edit(
content=self.announcement_builder.announcement.video_url
)
return return
if not announcement.channel: if not announcement.channel:
@@ -446,33 +477,29 @@ class AnnouncementBuilderView(discord.ui.View):
return return
await interaction.response.send_message( await interaction.response.send_message(
"Your announcement was posted! 🎉 https://i.imgur.com/HRoxTzg.gif", "Your announcement was posted! 🎉 https://i.imgur.com/HRoxTzg.gif"
ephemeral=True,
) )
self.stop() self.stop()
bot = interaction.client
bot = interaction.client
video_message = None
message = await announcement.channel.send( message = await announcement.channel.send(
content=announcement.video_url,
embed=await announcement.get_embed(bot=bot), embed=await announcement.get_embed(bot=bot),
) )
await message.add_reaction(ANNOUNCEMENT_EMOJI) await message.add_reaction(ANNOUNCEMENT_EMOJI)
if announcement.video_url:
video_message = await announcement.channel.send(announcement.video_url)
for channel_id in bot.config.repost_channels: for channel_id in bot.config.repost_channels:
repost_channel = await bot.fetch_channel(channel_id) repost_channel = await bot.fetch_channel(channel_id)
await repost_channel.send( await repost_channel.send(
content=announcement.video_url, embed=await announcement.get_embed(bot=bot, show_author=True)
embed=await announcement.get_embed(bot=bot, show_author=True),
) )
await repost_channel.send(announcement.video_url)
await repost_channel.send(f"(posted in {announcement.channel.mention})") await repost_channel.send(f"(posted in {announcement.channel.mention})")
if announcement.will_notify:
try:
await message.publish()
except discord.Forbidden:
# Not an announcement channel
pass
if announcement.ping and announcement.ping_preview: if announcement.ping and announcement.ping_preview:
await announcement.channel.send( await announcement.channel.send(
f"{announcement.ping.mention} - {announcement.ping_preview}", f"{announcement.ping.mention} - {announcement.ping_preview}",
@@ -483,6 +510,15 @@ class AnnouncementBuilderView(discord.ui.View):
announcement.ping.mention, allowed_mentions=allowed_mentions announcement.ping.mention, allowed_mentions=allowed_mentions
) )
if announcement.will_notify:
try:
await message.publish()
if video_message:
await video_message.publish()
except discord.Forbidden:
pass
class ChangeOptionModal(discord.ui.Modal): class ChangeOptionModal(discord.ui.Modal):
def __init__( def __init__(