Starboard revamp, closes #76

This commit is contained in:
Zeva Rose 2021-08-03 01:55:15 -06:00
parent 2face4bac7
commit 7a2b407a9d
3 changed files with 57 additions and 17 deletions

View file

@ -25,7 +25,7 @@ jarvis = commands.Bot(
)
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
jarvis_self = Process()
__version__ = "1.9.5"
__version__ = "1.9.6"
jconfig = get_config()
db = DBManager(jconfig.mongo["connect"]).mongo

View file

@ -1,7 +1,14 @@
from discord import TextChannel
from discord.ext import commands
from discord.utils import find
from discord_slash import SlashContext, cog_ext
from discord_slash.utils.manage_commands import create_option
from discord_slash.utils.manage_components import (
create_actionrow,
create_select,
create_select_option,
wait_for_component,
)
from jarvis.db.types import Star, Starboard
from jarvis.utils import build_embed
@ -60,6 +67,7 @@ class StarboardCog(commands.Cog):
if not isinstance(channel, TextChannel):
await ctx.send("Channel must be a TextChannel", hidden=True)
return
exists = Starboard.get(channel=channel.id, guild=ctx.guild.id)
if exists:
await ctx.send(
@ -67,6 +75,11 @@ class StarboardCog(commands.Cog):
)
return
count = Starboard.get_many(guild=ctx.guild.id)
if count and len(count) >= 25:
await ctx.send("25 starboard limit reached", hidden=True)
return
_ = Starboard(
guild=ctx.guild.id,
channel=channel.id,
@ -115,12 +128,6 @@ class StarboardCog(commands.Cog):
option_type=3,
required=True,
),
create_option(
name="starboard",
description="Starboard to send message to",
option_type=7,
required=True,
),
create_option(
name="channel",
description="Channel that has the message, "
@ -135,20 +142,48 @@ class StarboardCog(commands.Cog):
self,
ctx: SlashContext,
message: str,
starboard: TextChannel,
channel: TextChannel = None,
):
if not channel:
channel = ctx.channel
exists = Starboard.get(channel=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,
)
starboards = Starboard.get_many(guild=ctx.guild.id)
if not starboards:
await ctx.send("No starboards exist.", hidden=True)
return
await ctx.defer()
channel_list = []
for starboard in starboards:
channel_list.append(
find(lambda x: x.id == starboard.channel, ctx.guild.channels)
)
select_channels = [
create_select_option(label=x.name, value=str(idx))
for idx, x in enumerate(channel_list)
]
select = create_select(
options=select_channels,
min_values=1,
max_values=1,
)
components = [create_actionrow(select)]
msg = await ctx.send(
content="Choose a starboard", components=components
)
com_ctx = await wait_for_component(
self.bot,
messages=msg,
components=components,
check=lambda x: x.author.id == ctx.author.id,
)
starboard = channel_list[int(com_ctx.selected_options[0])]
if message.startswith("https://"):
message = message.split("/")[-1]
@ -214,8 +249,12 @@ class StarboardCog(commands.Cog):
active=True,
).insert()
await ctx.send(
"Message saved to Starboard.\n" + f"See it in {starboard.mention}"
components[0]["components"][0]["disabled"] = True
await com_ctx.edit_origin(
content="Message saved to Starboard.\n"
+ f"See it in {starboard.mention}",
components=components,
)
@cog_ext.cog_subcommand(

View file

@ -53,6 +53,7 @@ class MessageEventHandler(object):
allowed = [x.code for x in guild_invites] + [
"dbrand",
"VtgZntXcnZ",
"gPfYGbvTCE",
]
if match.group(1) not in allowed:
await message.delete()