Starboard revamp, closes #76
This commit is contained in:
parent
2face4bac7
commit
7a2b407a9d
3 changed files with 57 additions and 17 deletions
|
@ -25,7 +25,7 @@ jarvis = commands.Bot(
|
||||||
)
|
)
|
||||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "1.9.5"
|
__version__ = "1.9.6"
|
||||||
|
|
||||||
jconfig = get_config()
|
jconfig = get_config()
|
||||||
db = DBManager(jconfig.mongo["connect"]).mongo
|
db = DBManager(jconfig.mongo["connect"]).mongo
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
from discord import TextChannel
|
from discord import TextChannel
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
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
|
||||||
|
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.db.types import Star, Starboard
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
|
@ -60,6 +67,7 @@ class StarboardCog(commands.Cog):
|
||||||
if not isinstance(channel, TextChannel):
|
if not isinstance(channel, TextChannel):
|
||||||
await ctx.send("Channel must be a TextChannel", hidden=True)
|
await ctx.send("Channel must be a TextChannel", hidden=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
exists = Starboard.get(channel=channel.id, guild=ctx.guild.id)
|
exists = Starboard.get(channel=channel.id, guild=ctx.guild.id)
|
||||||
if exists:
|
if exists:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
|
@ -67,6 +75,11 @@ class StarboardCog(commands.Cog):
|
||||||
)
|
)
|
||||||
return
|
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(
|
_ = Starboard(
|
||||||
guild=ctx.guild.id,
|
guild=ctx.guild.id,
|
||||||
channel=channel.id,
|
channel=channel.id,
|
||||||
|
@ -115,12 +128,6 @@ class StarboardCog(commands.Cog):
|
||||||
option_type=3,
|
option_type=3,
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
create_option(
|
|
||||||
name="starboard",
|
|
||||||
description="Starboard to send message to",
|
|
||||||
option_type=7,
|
|
||||||
required=True,
|
|
||||||
),
|
|
||||||
create_option(
|
create_option(
|
||||||
name="channel",
|
name="channel",
|
||||||
description="Channel that has the message, "
|
description="Channel that has the message, "
|
||||||
|
@ -135,20 +142,48 @@ class StarboardCog(commands.Cog):
|
||||||
self,
|
self,
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
message: str,
|
message: str,
|
||||||
starboard: TextChannel,
|
|
||||||
channel: TextChannel = None,
|
channel: TextChannel = None,
|
||||||
):
|
):
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = ctx.channel
|
channel = ctx.channel
|
||||||
exists = Starboard.get(channel=starboard.id, guild=ctx.guild.id)
|
starboards = Starboard.get_many(guild=ctx.guild.id)
|
||||||
if not exists:
|
if not starboards:
|
||||||
await ctx.send(
|
await ctx.send("No starboards exist.", hidden=True)
|
||||||
f"Starboard does not exist in {starboard.mention}. "
|
|
||||||
+ "Please create it first",
|
|
||||||
hidden=True,
|
|
||||||
)
|
|
||||||
return
|
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://"):
|
if message.startswith("https://"):
|
||||||
message = message.split("/")[-1]
|
message = message.split("/")[-1]
|
||||||
|
|
||||||
|
@ -214,8 +249,12 @@ class StarboardCog(commands.Cog):
|
||||||
active=True,
|
active=True,
|
||||||
).insert()
|
).insert()
|
||||||
|
|
||||||
await ctx.send(
|
components[0]["components"][0]["disabled"] = True
|
||||||
"Message saved to Starboard.\n" + f"See it in {starboard.mention}"
|
|
||||||
|
await com_ctx.edit_origin(
|
||||||
|
content="Message saved to Starboard.\n"
|
||||||
|
+ f"See it in {starboard.mention}",
|
||||||
|
components=components,
|
||||||
)
|
)
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
|
|
|
@ -53,6 +53,7 @@ class MessageEventHandler(object):
|
||||||
allowed = [x.code for x in guild_invites] + [
|
allowed = [x.code for x in guild_invites] + [
|
||||||
"dbrand",
|
"dbrand",
|
||||||
"VtgZntXcnZ",
|
"VtgZntXcnZ",
|
||||||
|
"gPfYGbvTCE",
|
||||||
]
|
]
|
||||||
if match.group(1) not in allowed:
|
if match.group(1) not in allowed:
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|
Loading…
Add table
Reference in a new issue