def update_role_permission(role: Role, permission, enabled: bool): perms = get_role_permissions(role) if enabled and not has_own_permission(permission, perms): perms = perms ^ permissions[permission] elif not enabled and has_own_permission(permission, perms): perms = perms ^ permissions[permission] database.update_guild(role.guild.id, {"role_permission_" + str(role.id): perms})
def update_user_permission(member: Member, permission, enabled: bool): perms = get_user_permissions(member) if enabled and not has_own_permission(permission, perms): perms = perms ^ permissions[permission] elif not enabled and has_own_permission(permission, perms): perms = perms ^ permissions[permission] database.update_guild(member.guild.id, {"user_permission_" + str(member.id): perms})
def get_role_permissions(role: Role): guild = database.get_guild(role.guild.id) try: return guild["role_permission_" + str(role.id)] except KeyError: database.update_guild(role.guild.id, {"role_permission_" + str(role.id): 0}) return get_role_permissions(role)
def get_user_permissions(member: Member): guild = database.get_guild(member.guild.id) try: return guild["user_permission_" + str(member.id)] except KeyError: database.update_guild(member.guild.id, {"user_permission_" + str(member.id): 0}) return get_user_permissions(member)
def get_prefix(bot, message: Message): guild = database.get_guild(message.guild.id) try: p = guild["prefix"] except KeyError: database.update_guild(message.guild.id, {"prefix": guild_defaults["prefix"]}) return get_prefix(bot, message) return p, f"<@!{bot.user.id}> ", f"<@{bot.user.id}> "
def update_prefix(guild_id, prefix): database.update_guild(guild_id, {"prefix": prefix}) return database.get_guild(guild_id)["prefix"]
def get_log_channel(ctx: Context): try: return int(database.get_guild(ctx.guild.id)["log_channel"]) except KeyError: database.update_guild(ctx.guild.id, {"log_channel": "0"}) return get_log_channel(ctx)
def update_log_channel(channel: TextChannel): database.update_guild(channel.guild.id, {"log_channel": channel.id})