Skip to content

Commit

Permalink
Merge pull request #27 from EdVraz/master
Browse files Browse the repository at this point in the history
role creation
  • Loading branch information
EepyElvyra authored Nov 12, 2021
2 parents d5d4465 + 6b8b5f2 commit 6162aa7
Showing 1 changed file with 229 additions and 4 deletions.
233 changes: 229 additions & 4 deletions cogs/server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
from discord.ext.commands import Cog, AutoShardedBot
from discord_slash import cog_ext, SlashContext, ButtonStyle, ComponentContext
from discord_slash.utils import manage_components
from discord_slash.utils.manage_components import wait_for_component
from discord_slash.utils.manage_components import wait_for_component, create_select_option
from utils import utils, punishments

guildid = [908371267751661639]


class ServerUtils(Cog):
"""
Expand Down Expand Up @@ -589,6 +587,7 @@ async def _create_role(self, ctx: SlashContext, name: str, color: str):
)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm)
await ctx.channel.send("Done")
return

else:
pass
Expand Down Expand Up @@ -618,9 +617,235 @@ async def _create_role(self, ctx: SlashContext, name: str, color: str):
)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm)
await ctx.channel.send("Done")
return

else:
...
pass

sel = manage_components.create_select(
placeholder="Choose the permissions you want for your role (1/2)",
min_values=1, max_values=18,
options=[
create_select_option(
label="add reactions to messages",
value="add_reactions",
),
create_select_option(
label="attach files to messages",
value="attach_files",
),
create_select_option(
label="ban members",
value="ban_members",
),
create_select_option(
label="change own nickname",
value="change_nickname",
),
create_select_option(
label="connect to voice channels",
value="connect",
),
create_select_option(
label="create instant invite to a channel",
value="create_instant_invite",
),
create_select_option(
label="deafen other members in voice channels",
value="deafen_members",
),
create_select_option(
label="embed links in channels",
value="embed_links",
),
create_select_option(
label="send external emojis",
value="external_emojis",
),
create_select_option(
label="kick members",
value="kick_members",
),
create_select_option(
label="manage channels on the server",
value="manage_channels",
),
create_select_option(
label="manage emojis of the server",
value="manage_emojis",
),
create_select_option(
label="manage guild",
value="manage_guild",
),
create_select_option(
label="manage messages",
value="manage_messages",
),
create_select_option(
label="manage all nicknames",
value="manage_nicknames",
),
create_select_option(
label="manage the permission of roles",
value="manage_permissions",
),
create_select_option(
label="manage roles and their permissions",
value="manage_roles",
),
create_select_option(
label="manage webhooks",
value="manage_webhooks"
),
],
)
selrow = manage_components.create_actionrow(sel)
await admin.edit_origin(
content="Please choose the permissions you want to assign to the role (1/2)",
components=[selrow]
)

try:
firstperms = await wait_for_component(self.bot, components=[selrow], timeout=600)
await firstperms.defer(edit_origin=True)
except asyncio.TimeoutError:
selrow["components"][0]["disabled"] = True
await admin.origin_message.edit("Timed out.", components=[selrow])
return

roleperm.add_reactions = True if "add_reactions" in firstperms.selected_options else False
roleperm.attach_files = True if "attach_files" in firstperms.selected_options else False
roleperm.ban_members = True if "ban_members" in firstperms.selected_options else False
roleperm.change_nickname = True if "change_nickname" in firstperms.selected_options else False
roleperm.connect = True if "connect" in firstperms.selected_options else False
roleperm.create_instant_invite = True if "create_instant_invite" in firstperms.selected_options else False
roleperm.deafen_members = True if "deafen_members" in firstperms.selected_options else False
roleperm.embed_links = True if "embed_links" in firstperms.selected_options else False
roleperm.external_emojis = True if "external_emojis" in firstperms.selected_options else False
roleperm.kick_members = True if "kick_members" in firstperms.selected_options else False
roleperm.manage_channels = True if "manage_channels" in firstperms.selected_options else False
roleperm.manage_emojis = True if "manage_emojis" in firstperms.selected_options else False
roleperm.manage_guild = True if "manage_guild" in firstperms.selected_options else False
roleperm.manage_messages = True if "manage_messages" in firstperms.selected_options else False
roleperm.manage_nicknames = True if "manage_nicknames" in firstperms.selected_options else False
roleperm.manage_permissions = True if "manage_permissions" in firstperms.selected_options else False
roleperm.manage_roles = True if "manage_roles" in firstperms.selected_options else False
roleperm.manage_webhooks = True if "manage_webhooks" in firstperms.selected_options else False

sel2 = manage_components.create_select(
placeholder="Choose the permissions you want for your role (2/2)",
max_values=17, min_values=1,
options=[
create_select_option(
label="mention everyone in a message",
value="mention_everyone",
),
create_select_option(
label="move members across voice channels",
value="move_members",
),
create_select_option(
label="mute members in voice channels",
value="mute_members",
),
create_select_option(
label="priority speaker",
value="priority_speaker",
),
create_select_option(
label="read message history in channels",
value="read_message_history",
),
create_select_option(
label="read all messages in channels",
value="read_messages",
),
create_select_option(
label="request to speak in stage channels",
value="request_to_speak",
),
create_select_option(
label="send messages in channels",
value="send_messages",
),
create_select_option(
label="send TTS messages in channels",
value="send_tts_messages",
),
create_select_option(
label="speak in voice channels",
value="speak",
),
create_select_option(
label="stream in voice channels",
value="stream",
),
create_select_option(
label="use external emojis",
value="use_external_emojis",
),
create_select_option(
label="use slash commands in channels",
value="use_slash_commands",
),
create_select_option(
label="use voice activation in voice channels (else only push-to-talk)",
value="use_voice_activation",
),
create_select_option(
label="view the audit-log",
value="view_audit_log",
),
create_select_option(
label="view channels",
value="view_channel",
),
create_select_option(
label="view guild insights",
value="view_guild_insights",
),
],
)
sel2row = manage_components.create_actionrow(sel2)
await firstperms.edit_origin(
content="Please choose the permissions you want to assign to the role (2/2)",
components=[sel2row],
)

try:
secondperms = await wait_for_component(self.bot, components=[sel2row], timeout=600)
await secondperms.defer(edit_origin=True)
except asyncio.TimeoutError:
sel2row["components"][0]["disabled"] = True
await firstperms.origin_message.edit("Timed out.", components=[sel2row])
return

roleperm.mention_everyone = True if "mention_everyone" in secondperms.selected_options else False
roleperm.move_members = True if "move_members" in secondperms.selected_options else False
roleperm.mute_members = True if "mute_members" in secondperms.selected_options else False
roleperm.priority_speaker = True if "priority_speaker" in secondperms.selected_options else False
roleperm.read_message_history = True if "read_message_history" in secondperms.selected_options else False
roleperm.read_messages = True if "read_messages" in secondperms.selected_options else False
roleperm.request_to_speak = True if "request_to_speak" in secondperms.selected_options else False
roleperm.send_messages = True if "send_messages" in secondperms.selected_options else False
roleperm.send_tts_messages = True if "send_tts_messages" in secondperms.selected_options else False
roleperm.speak = True if "speak" in secondperms.selected_options else False
roleperm.stream = True if "stream" in secondperms.selected_options else False
roleperm.use_external_emojis = True if "use_external_emojis" in secondperms.selected_options else False
roleperm.use_slash_commands = True if "use_slash_commands" in secondperms.selected_options else False
roleperm.use_voice_activation = True if "use_voice_activation" in secondperms.selected_options else False
roleperm.view_audit_log = True if "view_audit_log" in secondperms.selected_options else False
roleperm.view_channel = True if "view_channel" in secondperms.selected_options else False
roleperm.view_guild_insights = True if "view_guild_insights" in secondperms.selected_options else False

sel2row["components"][0]["disabled"] = True
await secondperms.edit_origin(
content=f"Role '{name}' with color #{hexval} and your custom permissions, which have the value {roleperm.value}, is being created",
components=[sel2row]
),
await ctx.guild.create_role(name=name, color=color, permissions=roleperm)
await ctx.channel.send("Done!")


# @cog_ext.cog_subcommand(base="server", subcommand_group="role", name="edit", description="edits a role")
Expand Down

0 comments on commit 6162aa7

Please sign in to comment.