private Task RoleCreated(SocketRole socketRole) { // Give the new role properties corresponding to its permission level. // This is done to avoid administrative roles being joinable directly after creation and to minimize the extra work needed by admins. bool joinable = false; RoleType roleType = RoleType.Other; if (Data.HasAdministrativePermission(socketRole)) { joinable = false; roleType = RoleType.Admin; } else if (socketRole.Permissions.Connect || socketRole.Permissions.SendMessages || socketRole.Permissions.SendTTSMessages || socketRole.Permissions.Speak || socketRole.Permissions.ViewChannel) { joinable = true; roleType = RoleType.Game; } // Create RoleContainer and add it to the file. RoleContainer roleContainer = new RoleContainer(socketRole.Name, joinable, roleType); Data.AddContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE); return(Task.CompletedTask); }
private Task RoleDeleted(SocketRole socketRole) { // Get RoleContainer if it exists. List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE); RoleContainer roleContainer = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == socketRole.Name.ToLower()); if (roleContainer != null) { // Remove RoleContainer. Data.RemoveContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE); } return(Task.CompletedTask); }
public async Task RemoveRoleAsync( [Summary("The name of the role the user wishes to remove")] [Example("Overwatch")] [Remainder] string role) { IMessage m; // Get RoleContainer if it exists. List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE); RoleContainer roleContainer = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == role.ToLower()); if (roleContainer != null) { // Remove RoleContainer. Data.RemoveContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE); // Return feedback message. m = await ReplyAsync( embed : new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("Role removed") .WithDescription($"The `{roleContainer.name}` role has been successfully removed from the database.") .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(); }
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 LeaveRoleAsync( [Summary("The name of the role(s) the user wishes to leave. Role names are seperated by ','s.")] [Example("Overwatch")] [Example("Overwatch, Dota 2, Payday 2")] [Remainder] string roles) { List <IMessage> msgs = new List <IMessage>(); List <string> roleNames = roles.Split(',').ToList(); for (int i = 0; i < roleNames.Count; i++) { roleNames[i] = roleNames[i].Trim(); } foreach (string rn in roleNames) { // Autocorrecting goes here. // Get the roleContainer corresponding to the role the user want to leave. List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE); RoleContainer roleContainer = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == rn.ToLower()); if (roleContainer != null) { if (((SocketGuildUser)Context.User).Roles.FirstOrDefault(r => r.Name.ToLower() == roleContainer.name.ToLower()) == null) { msgs.Add(await ReplyAsync( embed: new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("User not in role").WithDescription($"You do not have the `{roleContainer.name}` role. If you wanna join the role, use the `join` command.") .WithAutoDeletionFooter() .Build())); } else { if (roleContainer.joinable) { // Add role and return feedback message. SocketRole socketRole = Context.Guild.Roles.FirstOrDefault(r => r.Name.ToLower() == roleContainer.name.ToLower()); await((SocketGuildUser)Context.User).RemoveRoleAsync(socketRole); msgs.Add(await ReplyAsync( embed: new EmbedBuilder() .WithColor(Data.COLOR_SUCCESS) .WithTitle("Role Left") .WithDescription($"You have successfully left the `{socketRole.Name}` role and no longer have access to all the text and voice channels associated with it.") .WithAutoDeletionFooter() .Build())); } else { msgs.Add(await ReplyAsync( embed: new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("Access to role denied") .WithDescription($"The `{roleContainer.name}` role is not leaveable. It is strictly distributed by admins.") .WithAutoDeletionFooter() .Build())); } } } else { msgs.Add(await ReplyAsync( embed: new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("Role not found") .WithDescription($"Could not find a role matching the name `{rn}`.\nFor a full list of roles, use the `roles` command.") .WithAutoDeletionFooter() .Build())); } } // Delete prompt and feedback messages. await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000); await Context.Message.DeleteAsync(); foreach (var msg in msgs) { await msg.DeleteAsync(); } }