Fixed .ura hierarchy check
fixed compilation warning
This commit is contained in:
parent
8498f40f2c
commit
c3e3f5fabb
3 changed files with 16 additions and 25 deletions
src/EllieBot
Db/Extensions
Modules/Utility/UserRole
strings/responses
|
@ -29,12 +29,12 @@ public static class GuildConfigExtensions
|
|||
/// </summary>
|
||||
/// <param name="ctx">Db Context</param>
|
||||
/// <param name="guildId">Id of the guild to get stream role settings for.</param>
|
||||
/// <returns>Guild'p stream role settings</returns>
|
||||
/// <returns>Guild's stream role settings</returns>
|
||||
public static async Task<StreamRoleSettings> GetOrCreateStreamRoleSettings(this DbContext ctx, ulong guildId)
|
||||
{
|
||||
var srs = ctx.Set<StreamRoleSettings>()
|
||||
var srs = await ctx.Set<StreamRoleSettings>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.FirstOrDefault();
|
||||
.FirstOrDefaultAsyncEF();
|
||||
|
||||
if (srs is not null)
|
||||
return srs;
|
||||
|
|
|
@ -20,22 +20,12 @@ public partial class Utility
|
|||
[UserPerm(GuildPerm.ManageRoles)]
|
||||
public async Task UserRoleAssign(IGuildUser user, IRole role)
|
||||
{
|
||||
var modUser = (IGuildUser)ctx.User;
|
||||
|
||||
if (modUser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
{
|
||||
await Response().Error(strs.userrole_hierarchy_error).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var botUser = ((SocketGuild)ctx.Guild).CurrentUser;
|
||||
|
||||
if (botUser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
if (!await CheckRoleHierarchy(role))
|
||||
{
|
||||
await Response().Error(strs.hierarchy).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var success = await _urs.AddRoleAsync(ctx.Guild.Id, user.Id, role.Id);
|
||||
|
||||
if (!success)
|
||||
|
@ -50,16 +40,16 @@ public partial class Utility
|
|||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.ManageRoles)]
|
||||
public async Task UserRoleRemove(IUser user, IRole role)
|
||||
=> await UserRoleRemove(user, role.Id);
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.ManageRoles)]
|
||||
public async Task UserRoleRemove(IUser user, ulong roleId)
|
||||
{
|
||||
var modUser = (IGuildUser)ctx.User;
|
||||
var role = ctx.Guild.GetRole(roleId);
|
||||
|
||||
if (modUser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
{
|
||||
await Response().Error(strs.userrole_hierarchy_error).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var success = await _urs.RemoveRoleAsync(ctx.Guild.Id, user.Id, role.Id);
|
||||
var success = await _urs.RemoveRoleAsync(ctx.Guild.Id, user.Id, roleId);
|
||||
if (!success)
|
||||
{
|
||||
await Response().Error(strs.userrole_not_found).SendAsync();
|
||||
|
@ -67,7 +57,9 @@ public partial class Utility
|
|||
}
|
||||
|
||||
await Response()
|
||||
.Confirm(strs.userrole_removed(Format.Bold(user.ToString()), Format.Bold(role.Name)))
|
||||
.Confirm(strs.userrole_removed(
|
||||
Format.Bold(user.ToString()),
|
||||
Format.Bold(role?.Name ?? roleId.ToString())))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
|
|
|
@ -1204,7 +1204,6 @@
|
|||
"userrole_icon_success": "The icon for {0} has been saved.",
|
||||
"userrole_icon_fail": "Failed to set the role icon.",
|
||||
"userrole_icon_invalid": "The role icon cannot be empty.",
|
||||
"userrole_hierarchy_error": "You can't assign or modify roles that are higher than or equal to your, or bots highest role.",
|
||||
"userrole_role_not_exists": "That role doesn't exist.",
|
||||
"whos_playing_game": "{0} users are playing {1}",
|
||||
"schedule_list_title": "Scheduled Commands",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue