Add star delete, closes #46
This commit is contained in:
parent
0519dbd91f
commit
6af3099b47
1 changed files with 66 additions and 1 deletions
|
@ -2,12 +2,13 @@ from datetime import datetime
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
import jarvis
|
|
||||||
from discord import Message, TextChannel
|
from discord import Message, TextChannel
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.utils import find
|
from discord.utils import find
|
||||||
from discord_slash import SlashContext, cog_ext
|
from discord_slash import SlashContext, cog_ext
|
||||||
from discord_slash.utils.manage_commands import create_option
|
from discord_slash.utils.manage_commands import create_option
|
||||||
|
|
||||||
|
import jarvis
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.db import DBManager
|
from jarvis.utils.db import DBManager
|
||||||
|
@ -238,6 +239,70 @@ class StarboardCog(commands.Cog):
|
||||||
"Message saved to Starboard.\n" + f"See it in {starboard.mention}"
|
"Message saved to Starboard.\n" + f"See it in {starboard.mention}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@cog_ext.cog_subcommand(
|
||||||
|
base="star",
|
||||||
|
name="delete",
|
||||||
|
description="Delete a starred message",
|
||||||
|
guild_ids=[
|
||||||
|
862402786116763668,
|
||||||
|
418094694325813248,
|
||||||
|
578757004059738142,
|
||||||
|
],
|
||||||
|
options=[
|
||||||
|
create_option(
|
||||||
|
name="id",
|
||||||
|
description="Star to delete",
|
||||||
|
option_type=4,
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
create_option(
|
||||||
|
name="starboard",
|
||||||
|
description="Starboard to delete star from",
|
||||||
|
option_type=7,
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def _star_get(
|
||||||
|
self,
|
||||||
|
ctx: SlashContext,
|
||||||
|
id: int,
|
||||||
|
starboard: TextChannel,
|
||||||
|
):
|
||||||
|
exists = self.db.jarvis.starboard.find_one(
|
||||||
|
{"target": starboard.id, "guild": ctx.guild.id}
|
||||||
|
)
|
||||||
|
if not exists:
|
||||||
|
await ctx.send(
|
||||||
|
f"Starboard does not exist in {starboard.mention}. "
|
||||||
|
+ "Please create it first",
|
||||||
|
hidden=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
star = self.db.jarvis.stars.find_one(
|
||||||
|
{
|
||||||
|
"starboard": starboard.id,
|
||||||
|
"id": id,
|
||||||
|
"guild": ctx.guild.id,
|
||||||
|
"active": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if not star:
|
||||||
|
await ctx.send(f"No star exists with id {id}", hidden=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
message = await starboard.fetch_message(star["star"])
|
||||||
|
if message:
|
||||||
|
await message.delete()
|
||||||
|
|
||||||
|
self.db.jarvis.stars.update_one(
|
||||||
|
{"starboard": starboard.id, "id": id, "guild": ctx.guild.id},
|
||||||
|
{"$set": {"active": False}},
|
||||||
|
)
|
||||||
|
|
||||||
|
await ctx.send(f"Star {id} deleted")
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(StarboardCog(bot))
|
bot.add_cog(StarboardCog(bot))
|
||||||
|
|
Loading…
Add table
Reference in a new issue