Skip to content

Commit

Permalink
Merge pull request #19 from probablyjassin:enh/roles
Browse files Browse the repository at this point in the history
Enh/roles
  • Loading branch information
probablyjassin authored Nov 4, 2024
2 parents 8631be5 + 4367980 commit 535a470
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cogs/mogi/join_mogi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def join(self, ctx: MogiApplicationContext):
)

ctx.mogi.players.append(player)
await ctx.user.add_roles(get(ctx.guild.roles, name="InMogi"))
await ctx.user.add_roles(ctx.inmogi_role)
await ctx.respond(
f"{ctx.author.mention} has joined the mogi!\n{len(ctx.mogi.players)} players are in!"
)
Expand Down
2 changes: 1 addition & 1 deletion cogs/mogi/leave_mogi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def leave(self, ctx: MogiApplicationContext):
for player in ctx.mogi.players
if player.discord_id != ctx.author.id
]
await ctx.user.remove_roles(get(ctx.guild.roles, name="InMogi"))
await ctx.user.remove_roles(ctx.inmogi_role)
if len(ctx.mogi.players) == 0:
mogi_manager.destroy_mogi(ctx.channel.id)
return await ctx.respond("# This mogi has been closed.")
Expand Down
7 changes: 1 addition & 6 deletions cogs/mogi/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ class start(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot

@commands.Cog.listener()
async def on_ready(self):
self.MAIN_GUILD = get(self.bot.guilds, id=GUILD_IDS[0])
self.INMOGI_ROLE = get(self.MAIN_GUILD.roles, name="InMogi")

start = SlashCommandGroup(name="start", description="Start a mogi")

@start.command(name="vote", guild_ids=GUILD_IDS)
Expand All @@ -34,7 +29,7 @@ async def vote(self, ctx: MogiApplicationContext):
if len(ctx.mogi.players) > 12:
return await ctx.respond("Cant start with more than 12 players")
# user not in the mogi
if not self.INMOGI_ROLE in ctx.user.roles:
if not ctx.inmogi_role in ctx.user.roles:
return await ctx.respond(
"You can't start a mogi you aren't in", ephemeral=True
)
Expand Down
7 changes: 1 addition & 6 deletions cogs/mogi/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ class stop(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot

@commands.Cog.listener()
async def on_ready(self):
self.MAIN_GUILD = get(self.bot.guilds, id=GUILD_IDS[0])
self.INMOGI_ROLE = get(self.MAIN_GUILD.roles, name="InMogi")

@slash_command(name="stop", description="Halt the current mogi")
@is_mogi_in_progress()
async def stop(self, ctx: MogiApplicationContext):

# user not in the mogi
if not self.INMOGI_ROLE in ctx.user.roles:
if not ctx.inmogi_role in ctx.user.roles:
return await ctx.respond(
"You can't stop a mogi you aren't in", ephemeral=True
)
Expand Down
10 changes: 6 additions & 4 deletions cogs/profiles/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ async def register(self, ctx: MogiApplicationContext):
)

member: Member = ctx.user
if get(self.MAIN_GUILD.roles, name="Lounge Player") in member.roles:
if ctx.get_lounge_role("Lounge Player") in member.roles:
return await ctx.respond(
"You already have the Lounge Player role even though you don't have a player profile. Please ask a moderator for help.",
"You already have the Lounge Player role"
"even though you don't have a player profile."
"Ask a moderator for help.",
ephemeral=True,
)
try:
Expand All @@ -81,8 +83,8 @@ async def register(self, ctx: MogiApplicationContext):
"Some error occured creating your player record. Please ask a moderator.",
ephemeral=True,
)
await member.add_roles(get(self.MAIN_GUILD.roles, name="Lounge Player"))
await member.add_roles(get(self.MAIN_GUILD.roles, name="Lounge - Silver"))
await member.add_roles(ctx.get_lounge_role("Lounge Player"))
await member.add_roles(ctx.get_lounge_role("Lounge - Silver"))
await ctx.respond(
f"{member.mention} is now registered for Lounge as {username}\n You can view your profile at https://mk8dx-yuzu.github.io/{username}",
ephemeral=False,
Expand Down
11 changes: 11 additions & 0 deletions models/CustomMogiContext.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import discord
from discord.utils import get

from utils.data.mogi_manager import mogi_manager
from models.MogiModel import Mogi

from config import GUILD_IDS


class MogiApplicationContext(discord.ApplicationContext):
"""## `discord.ApplicationContext` but with the `mogi` attribute:
Expand All @@ -25,4 +29,11 @@ class MogiApplicationContext(discord.ApplicationContext):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.mogi: Mogi = mogi_manager.get_mogi(self.channel.id)

self.main_guild: discord.Guild = get(self.bot.guilds, id=GUILD_IDS[0])
self.inmogi_role: discord.Role = get(self.main_guild.roles, name="InMogi")

def get_lounge_role(self, name: str) -> discord.Role:
return get(self.main_guild.roles, name=name)
6 changes: 2 additions & 4 deletions utils/command_helpers/apply_update_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ async def update_roles(
await ctx.send(f"{discord_member.mention} is now in {new_rank.name}")

await discord_member.remove_roles(
get(ctx.guild.roles, name=f"Lounge - {current_rank}")
)
await discord_member.add_roles(
get(ctx.guild.roles, name=f"Lounge - {new_rank}")
ctx.get_lounge_role(f"Lounge - {current_rank}")
)
await discord_member.add_roles(ctx.get_lounge_role(f"Lounge - {new_rank}"))
6 changes: 3 additions & 3 deletions utils/command_helpers/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def predicate(ctx: MogiApplicationContext):
ctx=ctx,
condition=(
ctx.author.guild_permissions.is_superset(
get(ctx.guild.roles, name="Mogi Manager").permissions
ctx.get_lounge_role("Mogi Manager").permissions
)
),
error_message="You're not allowed to use this command.",
Expand All @@ -38,7 +38,7 @@ async def predicate(ctx: MogiApplicationContext):
ctx=ctx,
condition=(
ctx.author.guild_permissions.is_superset(
get(ctx.guild.roles, name="Moderator").permissions
ctx.get_lounge_role("Moderator").permissions
)
),
error_message="You're not allowed to use this command.",
Expand All @@ -53,7 +53,7 @@ async def predicate(ctx: MogiApplicationContext):
ctx=ctx,
condition=(
ctx.author.guild_permissions.is_superset(
get(ctx.guild.roles, name="Admin").permissions
ctx.get_lounge_role("Admin").permissions
)
),
error_message="You're not allowed to use this command.",
Expand Down

0 comments on commit 535a470

Please sign in to comment.