Fix starboard

This commit is contained in:
Zeva Rose 2022-02-04 11:41:47 -07:00
parent 2595b87061
commit 1cf4108a44

View file

@ -95,13 +95,14 @@ class StarboardCog(Scale):
deleted = Starboard.objects(channel=channel.id, guild=ctx.guild.id).delete() deleted = Starboard.objects(channel=channel.id, guild=ctx.guild.id).delete()
if deleted: if deleted:
_ = Star.objects(starboard=channel.id).delete() _ = Star.objects(starboard=channel.id).delete()
await ctx.send(f"Starboard deleted from {channel.mention}.", ephemeral=True) await ctx.send(f"Starboard deleted from {channel.mention}.")
else: else:
await ctx.send(f"Starboard not found in {channel.mention}.", ephemeral=True) await ctx.send(f"Starboard not found in {channel.mention}.", ephemeral=True)
@context_menu(name="Star Message", context_type=CommandTypes.MESSAGE) @context_menu(name="Star Message", context_type=CommandTypes.MESSAGE)
async def _star_message(self, ctx: InteractionContext) -> None: async def _star_message(self, ctx: InteractionContext) -> None:
await self._star_add.invoke(ctx, ctx.target_message) await self._star_add._can_run(ctx)
await self._star_add.callback(ctx, message=str(ctx.target_id))
@slash_command(name="star", sub_cmd_name="add", description="Star a message") @slash_command(name="star", sub_cmd_name="add", description="Star a message")
@slash_option( @slash_option(
@ -159,10 +160,10 @@ class StarboardCog(Scale):
com_ctx = await self.bot.wait_for_component( com_ctx = await self.bot.wait_for_component(
messages=msg, messages=msg,
components=components, components=components,
check=lambda x: x.author.id == ctx.author.id, check=lambda x: ctx.author.id == x.context.author.id,
) )
starboard = channel_list[int(com_ctx.selected_options[0])] starboard = channel_list[int(com_ctx.context.values[0])]
exists = Star.objects( exists = Star.objects(
message=message.id, message=message.id,
@ -220,16 +221,16 @@ class StarboardCog(Scale):
active=True, active=True,
).save() ).save()
components[0]["components"][0]["disabled"] = True components[0].components[0].disabled = True
await com_ctx.edit_origin( await com_ctx.context.edit_origin(
content=f"Message saved to Starboard.\nSee it in {starboard.mention}", content=f"Message saved to Starboard.\nSee it in {starboard.mention}",
components=components, components=components,
) )
@slash_command(name="star", sub_cmd_name="delete", description="Delete a starred message") @slash_command(name="star", sub_cmd_name="delete", description="Delete a starred message")
@slash_option( @slash_option(
name="message", description="Star to delete", opt_type=OptionTypes.INTEGER, required=True name="id", description="Star ID to delete", opt_type=OptionTypes.INTEGER, required=True
) )
@slash_option( @slash_option(
name="starboard", name="starboard",
@ -265,14 +266,14 @@ class StarboardCog(Scale):
await ctx.send(f"No star exists with id {id}", ephemeral=True) await ctx.send(f"No star exists with id {id}", ephemeral=True)
return return
message = await starboard.fetch_message(star.star) message = await starboard.get_message(star.star)
if message: if message:
await message.delete() await message.delete()
star.active = False star.active = False
star.save() star.save()
await ctx.send(f"Star {id} deleted") await ctx.send(f"Star {id} deleted from {starboard.mention}")
def setup(bot: Snake) -> None: def setup(bot: Snake) -> None: