1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 20:23:12 +00:00

Role Reward Fixes

This commit is contained in:
wlinator 2024-04-03 13:48:22 -04:00
parent 63ae505d6b
commit 56274a7bb0
4 changed files with 86 additions and 9 deletions

View file

@ -94,7 +94,7 @@ CREATE TABLE level_rewards (
role_id BIGINT,
persistent BOOLEAN,
PRIMARY KEY (guild_id, role_id)
PRIMARY KEY (guild_id, level)
);
CREATE TABLE blacklist_user (

View file

@ -128,10 +128,16 @@ class XPHandler:
role = guild.get_role(role_id)
if role:
try:
await user.add_roles(role, reason=reason)
except (discord.Forbidden, discord.NotFound, discord.HTTPException):
pass
previous = _rew.replace_previous_reward(level)
if previous[1]:
role = guild.get_role(previous[0])
if role:
try:
await user.remove_roles(role, reason=reason)
except (discord.Forbidden, discord.NotFound, discord.HTTPException):
pass

View file

@ -7,7 +7,7 @@ from discord.ext import commands, bridge
from config.parser import JsonCache
from lib import formatter
from lib.embeds.greet import Greet
from modules.config import config, set_prefix
from modules.config import config, set_prefix, xp_reward
from services.GuildConfig import GuildConfig
strings = JsonCache.read_json("strings")
@ -49,18 +49,47 @@ class Config(commands.Cog):
await set_prefix.set_cmd(ctx, prefix)
@bridge.bridge_command(
name="xpreward",
aliases=["xprew", "xpr"],
name="xprewards",
aliases=["xpr"],
guild_only="True"
)
@commands.guild_only()
@commands.has_permissions(manage_roles=True)
async def xpreward_command(self, ctx, level: int, roles: discord.Role):
async def xp_reward_command_show(self, ctx):
"""
Reward members for reaching a level. Guide: https://gitlab.com/wlinator/Racu/wikis/Role-Rewards
[Read the guide before editing](https://gitlab.com/wlinator/Racu/wikis/Role-Rewards).
"""
pass
await xp_reward.show(ctx)
@bridge.bridge_command(
name="addxpreward",
aliases=["axpr"],
guild_only="True"
)
@commands.guild_only()
@commands.has_permissions(manage_roles=True)
async def xp_reward_command_add(self, ctx, level: int, role: discord.Role, persistent: bool):
"""
[Read the guide before editing](https://gitlab.com/wlinator/Racu/wikis/Role-Rewards).
"""
await xp_reward.add_reward(ctx, level, role.id, persistent)
@bridge.bridge_command(
name="removexpreward",
aliases=["rxpr"],
guild_only="True"
)
@commands.guild_only()
@commands.has_permissions(manage_roles=True)
async def xp_reward_command_remove(self, ctx, level: int):
"""
[Read the guide before editing](https://gitlab.com/wlinator/Racu/wikis/Role-Rewards).
"""
await xp_reward.remove_reward(ctx, level)
"""
The guild config code is a mess.
"""
config = SlashCommandGroup("config", "server config commands.", guild_only=True,
default_member_permissions=discord.Permissions(manage_channels=True))
birthday_config = config.create_subgroup(name="birthdays")

View file

@ -0,0 +1,42 @@
import discord
from services.level_reward import LevelReward
from config.parser import JsonCache
art = JsonCache.read_json("art")
async def show(ctx):
level_reward = LevelReward(ctx.guild.id)
embed = discord.Embed(
color=discord.Color.embed_background(),
description="[Read the guide before editing](https://gitlab.com/wlinator/Racu/wikis/Role-Rewards).\n"
)
icon = ctx.guild.icon if ctx.guild.icon else art["logo"]["opaque"]
embed.set_author(name="Level Rewards", icon_url=icon)
for level in sorted(sorted(level_reward.rewards.keys())):
role_id, persistent = level_reward.rewards.get(level)
role = ctx.guild.get_role(role_id)
embed.description += f"\n**Level {level}** -> {role.mention}"
if bool(persistent):
embed.description += " (persistent)"
await ctx.respond(embed=embed)
async def add_reward(ctx, level, role_id, persistent):
level_reward = LevelReward(ctx.guild.id)
level_reward.add_reward(level, role_id, persistent)
await show(ctx)
async def remove_reward(ctx, level):
level_reward = LevelReward(ctx.guild.id)
level_reward.remove_reward(level)
await show(ctx)