bool canChangeNickname(SocketGuildUser oper, SocketGuildUser target) { if (oper == null) { return(false); } var bUser = oper.Guild.CurrentUser; if (bUser.Hierarchy <= target.Hierarchy) { return(false); } if (oper.GuildPermissions.Administrator) { return(true); } if ((oper.Hierarchy > target.Hierarchy)) { return(oper.GuildPermissions.Administrator || oper.GuildPermissions.ManageNicknames); } else if (oper.Id == target.Id) { if (oper.GuildPermissions.ChangeNickname) { return(true); } var botU = Program.GetUser(oper); if (PermChecker.UserHasPerm(botU, Perms.Bot.User.ChangeServerNickname)) { return(true); } } return(false); }
async Task printActualFor(BotUser u) { var paginator = new StaticPaginatorBuilder(); var cPage = new PageBuilder(); cPage.Title = $"Permissions of {u.Name}"; cPage.Text = "These are the effective permissions of the user, taking into account wildcards, denials and allowals."; foreach (var perm in Service.AllNodes.Values) { if (!PermChecker.UserHasPerm(u, perm, out var inherit)) { continue; } string sep = inherit ? "**" : ""; var s = $"`{perm.Node}` {sep}{perm.Description}{sep}\r\n"; if ((cPage.Description.Length + s.Length) > 1024) { paginator.AddPage(cPage); cPage = new PageBuilder(); cPage.Title = $"Permissions of {u.Name}"; cPage.Text = "These are the effective permissions of the user, taking into account wildcards, denials and allowals."; } cPage.Description += s; } if (cPage.Description == "") { cPage.Description = "None."; } paginator.AddPage(cPage); await PagedReplyAsync(paginator); }
protected override void OnOpen() { string strToken = null; var cookie = Context.CookieCollection[AuthToken.SessionToken]; strToken ??= cookie?.Value; strToken ??= Context.QueryString.Get(AuthToken.SessionToken); strToken ??= Context.Headers.Get($"X-{AuthToken.SessionToken.ToUpper()}"); if (!Handler.findToken(strToken, out var usr, out _)) { Program.LogMsg($"{IP} attempted unknown WS log.", LogSeverity.Debug, "WSLog"); Context.WebSocket.Close(CloseStatusCode.Normal, "Unauthorized"); return; } if (!PermChecker.UserHasPerm(usr, Perms.Bot.Developer.SeeLatestLog)) { Program.LogMsg($"{IP}, {usr.Name} attempted forbidden log connection", LogSeverity.Warning, "WsLog"); Context.WebSocket.Close(CloseStatusCode.Normal, "Forbidden"); return; } User = usr; Program.LogMsg($"{User.Name} has begun watching the logs via WS", LogSeverity.Info, IP); lock (Program._lockObj) { foreach (var log in Program.lastLogs) { Send(log); } } Program.Log += Handle; }
public bool HasPerm(NodeInfo node) { if (BotUser == null) { return(false); } return(PermChecker.UserHasPerm(BotUser, node)); }
async Task doCheckFor(BotUser u, NodeInfo node) { var given = PermChecker.UserHasPerm(Context.BotUser, node, out var b); if (given) { await ReplyAsync($":ballot_box_with_check: {(u.Id == Context.User.Id ? "You have" : $"{u.Name} has")} that node {(b ? "via a wildcard" : "directly")}"); }
static async System.Threading.Tasks.Task <BotResult> runReactions(CallbackEventArgs e) { if (!(ulong.TryParse(e.State, out var guildId))) { return(new BotResult($"Failed to parse '{e.State}' as ulong.")); } if (!(instance.Messages.TryGetValue(guildId, out var setup))) { return(new BotResult($"Guild {guildId} has no reaction roles set up.")); } if (!(ulong.TryParse(e.ComponentId, out var roleId))) { return(new BotResult($"Failed to parse custom id as ulong: {e.ComponentId}")); } if (!(e.Message.Channel is ITextChannel txt)) { return(new BotResult($"Current channel, {e.Message.Channel} is not a text channel")); } var role = txt.Guild.GetRole(roleId); if (role == null) { return(new BotResult($"Role {roleId} does not exist.")); } var perm = $"roles.{role.Guild.Id}.{role.Id}"; var user = await txt.Guild.GetUserAsync(e.User.Id); var bUser = Program.GetUser(user); if (PermChecker.UserHasPerm(bUser, perm) == false) { return(new BotResult($"You lack the permission to toggle that role.\r\n" /*+ * $"Use `{Program.Prefix}perms viewo {bUser.Id}` to see what permissions they do have."*/)); } if (user.RoleIds.Any(x => x == roleId)) { await user.RemoveRoleAsync(role); await e.Interaction.FollowupAsync($"You no longer have the {role.Name} role", ephemeral : true); } else { await user.AddRoleAsync(role); await e.Interaction.FollowupAsync($"You now have the {role.Name} role", ephemeral : true); } return(new BotResult()); }