Skip to content

Commit

Permalink
video urls can now be edited
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipdev committed Sep 21, 2023
1 parent 924cd1d commit db66253
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "scnewsbot"
version = "1.0.0"
version = "1.0.1"
description = "A bot for the r/starcitizen Discord server."
authors = ["mudkipdev <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion scnewsbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import discord
from utils import Config

VERSION = "1.0.0"
VERSION = "1.0.1"
INTENTS = discord.Intents.default()
INTENTS.message_content = True
INTENTS.members = True
Expand Down
86 changes: 61 additions & 25 deletions scnewsbot/extensions/announcements.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
"""


async def get_ping_message(message: discord.Message, /) -> Optional[discord.Message]:
async for ping in message.channel.history(limit=1, after=message.created_at):
if ping.author.id == message._state.user.id and ping.mentions:
return ping
async def get_follow_up_message(
announcement: discord.Message, /, *, limit: int
) -> Optional[discord.Message]:
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:
Expand Down Expand Up @@ -94,7 +100,11 @@ async def delete(self, ctx: commands.Context, message: discord.Message) -> None:
if message.author != self.bot.user and not message.embeds:
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:
await ping_message.delete()

Expand Down Expand Up @@ -236,7 +246,7 @@ async def from_message(

ping = None
ping_preview = None
ping_message = await get_ping_message(message)
ping_message = await get_follow_up_message(message, limit=2)

if ping_message:
split_message = ping_message.content.split(" - ")
Expand All @@ -249,6 +259,7 @@ async def from_message(

url = None
description = embed.description
video_message = await get_follow_up_message(message, limit=1)

if embed.description is not None:
if len(embed.description.split("\n\n")) > 0:
Expand All @@ -259,7 +270,7 @@ async def from_message(
title=embed.title,
url=url,
description=description,
video_url=message.content,
video_url=video_message.content,
image_url=embed.image.url,
channel=message.channel,
ping=ping,
Expand Down Expand Up @@ -356,6 +367,23 @@ async def button_callback(
)
)

@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)
async def toggle_anonymous(
self, interaction: discord.Interaction, button: discord.ui.Button
Expand Down Expand Up @@ -419,17 +447,20 @@ async def publish(
)

if self.announcement_builder.edit:
await interaction.response.send_message(
"Your announcement was edited! 🎉", ephemeral=True
)
await interaction.response.send_message("Your announcement was edited! 🎉")
self.stop()

embed = await self.announcement_builder.get_embed(bot=interaction.client)
embed.remove_footer()

await self.announcement_builder.message.edit(
content=self.announcement_builder.announcement.video_url, embed=embed
await self.announcement_builder.message.edit(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

if not announcement.channel:
Expand All @@ -446,33 +477,29 @@ async def publish(
return

await interaction.response.send_message(
"Your announcement was posted! 🎉 https://i.imgur.com/HRoxTzg.gif",
ephemeral=True,
"Your announcement was posted! 🎉 https://i.imgur.com/HRoxTzg.gif"
)
self.stop()
bot = interaction.client

bot = interaction.client
video_message = None
message = await announcement.channel.send(
content=announcement.video_url,
embed=await announcement.get_embed(bot=bot),
)

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:
repost_channel = await bot.fetch_channel(channel_id)
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})")

if announcement.will_notify:
try:
await message.publish()
except discord.Forbidden:
# Not an announcement channel
pass

if announcement.ping and announcement.ping_preview:
await announcement.channel.send(
f"{announcement.ping.mention} - {announcement.ping_preview}",
Expand All @@ -483,6 +510,15 @@ async def publish(
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):
def __init__(
Expand Down

0 comments on commit db66253

Please sign in to comment.