private Task RoleEdited(SocketRole prevSocketRole, SocketRole socketRole) { // Get roleContainers and check if role exists. List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE); RoleContainer roleContainer = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == prevSocketRole.Name.ToLower()); if (roleContainer != null) { roleContainer.name = socketRole.Name; // Check if administrative permissions have changed. If so make unjoinable. if (Data.ReceivedAdministrativePermission(prevSocketRole, socketRole)) { roleContainer.joinable = false; roleContainer.roleType = RoleType.Admin; } Data.SaveContainers(roleContainers, Data.FILE_PATH + Data.ROLE_FILE); } return(Task.CompletedTask); }
public async Task EditRoleAsync( [Summary("The name of the role the user wishes to edit (quotation marks are required if the name contains spaces)")] [Example("Overwatch")] [Example("\"Payday 2\"")] string role, [Summary("The type the role should be. (0-3 number input is also valid)")] [Example("Admin")] [Example("Color")] [Example("Game")] [Example("Other")] RoleType type, [Summary("If the role should be joinable or not.")] [Example("true")] [Example("false")] bool joinable) { IMessage m; // Get roleContainers and check if role exists. List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE); RoleContainer roleContainer = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == role.ToLower()); SocketRole socketRole = Context.Guild.Roles.FirstOrDefault(sr => sr.Name.ToLower() == role.ToLower()); if (roleContainer != null) { if (socketRole != null) { RoleType prevType = roleContainer.roleType; bool prevJoinable = roleContainer.joinable; roleContainer.roleType = type; roleContainer.joinable = joinable; Data.SaveContainers(roleContainers, Data.FILE_PATH + Data.ROLE_FILE); // Return feedback message. m = await ReplyAsync( embed : new EmbedBuilder() .WithColor(Data.COLOR_SUCCESS) .WithTitle("Role edited") .WithDescription($"The `{roleContainer.name}` role has been successfully edited from `{prevType} - {prevJoinable}` to `{roleContainer.roleType} - {roleContainer.joinable}`") .WithAutoDeletionFooter() .Build()); } else { m = await ReplyAsync( embed : new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("ERROR: Role not found") .WithDescription($"The `{role}` role you specified does not exist on the server.") .WithAutoDeletionFooter() .Build()); } } else { m = await ReplyAsync( embed : new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("ERROR: Role not found") .WithDescription($"The `{role}` role you specified does not exist in the database.") .WithAutoDeletionFooter() .Build()); } // Delete prompt and feedback messages. await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000); await Context.Message.DeleteAsync(); await m.DeleteAsync(); }
public async Task ScanRolesAsync() { // Get all SocketRoles on the server and give them properties corresponding to their permission level. // This is done to avoid administrative roles being joinable directly after the scan and to minimize the extra work needed by admins. List <RoleContainer> roleContainers = new List <RoleContainer>(); List <SocketGuildChannel> channels = Context.Guild.Channels.ToList(); foreach (SocketRole sr in Context.Guild.Roles) { bool joinable = false; RoleType roleType = RoleType.Other; if (Data.HasAdministrativePermission(sr)) { roleType = RoleType.Admin; joinable = false; } else { // Get all Overwrites for the current SocketRole (sr) //Context.Guild.Channels.Where(c => c.GetPermissionOverwrite(sr).HasValue).ToList().ForEach(c => roleOverwrites.AddRange(c.PermissionOverwrites.Where(o => o.TargetType == PermissionTarget.Role && o.TargetId == sr.Id))); List <Overwrite> roleOverwrites = new List <Overwrite>(); foreach (SocketGuildChannel c in channels) { List <Overwrite> channelOverwrites = c.PermissionOverwrites.ToList(); foreach (Overwrite o in channelOverwrites) { if (o.TargetType == PermissionTarget.Role && o.TargetId == sr.Id) { roleOverwrites.Add(o); } } } // Go through Overwrites and check channel specific permissions bool channelAccess = false, channelModerator = false; foreach (Overwrite o in roleOverwrites) { if (o.Permissions.ViewChannel == PermValue.Allow) { channelAccess = true; } if (o.Permissions.ManageMessages == PermValue.Allow) { channelModerator = true; } } if (sr.Permissions.ToList().Count <= 0) { if (channelAccess) { if (sr.IsMentionable) { roleType = RoleType.Other; // no privs, outside of channel access, mentionable joinable = false; } else { if (channelModerator) { roleType = RoleType.Moderator; // no privs, outside of specific channels, not mentionable joinable = false; } else { roleType = RoleType.Game; // no privs, outside of channel access, not mentionable joinable = true; } } } else { roleType = RoleType.Color; // no privs, not mentionable joinable = true; } } /*if (sr.Permissions.Connect || * sr.Permissions.SendMessages || * sr.Permissions.SendTTSMessages || * sr.Permissions.Speak || * sr.Permissions.ViewChannel) * { * roleType = RoleType.Game; * joinable = true; * }*/ } roleContainers.Add(new RoleContainer(sr.Name, joinable, roleType)); } // Sort the roleContainers after roleType and save them to file. roleContainers.Sort((a, b) => a.roleType.CompareTo(b.roleType)); Data.SaveContainers(roleContainers, Data.FILE_PATH + Data.ROLE_FILE); // Return feedback message. IMessage m = await ReplyAsync(embed : new EmbedBuilder() .WithTitle("Scan Complete") .WithDescription($"All roles on `{Context.Guild.Name}` have now been scanned. To get a list of them, use the `Roles` command. You can also further edit these roles by using the `Edit`, `Add` and `Remove` commands.") .WithAutoDeletionFooter() .Build()); // Delete prompt and feedback messages. await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000); await Context.Message.DeleteAsync(); await m.DeleteAsync(); }