private async Task RemoveManagedRole(CommandArgs <RoleBotConfig> args) { ulong roleID = ulong.Parse(args["roleID"]); if (args.Config.ManagedRoles.Remove(roleID)) { DiscordRole role = args.Guild.GetRole(roleID); if (role != null) { await role.DeleteAsync(); await args.Channel.SendMessageAsync($"**{role.Name}** has been deleted."); // Remove all emojis associated with the managed role. Stack <string> associatedEmojis = new Stack <string>(); foreach (var emojiRole in args.Config.EmojiRoles) { if (emojiRole.Value == roleID) { associatedEmojis.Push(emojiRole.Key); } } foreach (string emojiName in associatedEmojis) { args.Config.EmojiRoles.Remove(emojiName); } } } else { await args.Channel.SendMessageAsync("This role is not managed by this bot."); } }
public async Task DeleteAsync(CommandContext ctx, [Description("desc-role")] DiscordRole role, [RemainingText, Description("desc-rsn")] string?reason = null) { await role.DeleteAsync(ctx.BuildInvocationDetailsString(reason)); await ctx.InfoAsync(this.ModuleColor); }
public async Task DeleteAsync(CommandContext ctx, [Description("Role.")] DiscordRole role, [RemainingText, Description("Reason.")] string reason = null) { string name = Formatter.Bold(role.Name); await role.DeleteAsync(ctx.BuildInvocationDetailsString(reason)); await this.InformAsync(ctx, $"Successfully deleted role: {Formatter.Bold(name)}", important : false); }
public async Task CreatePrivateLobby(CommandContext ctx, string lobbyName, params DiscordMember[] allowedUsers) { try { await ctx.Channel.DeleteMessageAsync(ctx.Message); DiscordChannel parentCategory = await ctx.Client.GetChannelAsync(ParentCategoryId); DiscordChannel waitChannel = await ctx.Client.GetChannelAsync(WaitChannelId); if (!waitChannel.Users.Contains(ctx.User)) { throw new NBWaitRoomException(); } DiscordRole createdRole = await ctx.Guild.CreateRoleAsync(lobbyName); DiscordChannel createdLobby = await ctx.Guild.CreateVoiceChannelAsync( lobbyName == "_"?$"Lobby - {ctx.Member.DisplayName}" : lobbyName, parent : parentCategory); await createdLobby.PlaceMemberAsync(ctx.Member); await createdLobby.AddOverwriteAsync(ctx.Guild.GetRole(DefaultRole), deny : Permissions.AccessChannels); await createdLobby.AddOverwriteAsync(createdRole, allow : Permissions.AccessChannels); await createdLobby.AddOverwriteAsync(ctx.Member, allow : Permissions.MuteMembers | Permissions.DeafenMembers); IReadOnlyCollection <DiscordMember> allMembers = await ctx.Guild.GetAllMembersAsync(); await ctx.Member.GrantRoleAsync(createdRole); foreach (DiscordMember member in allowedUsers) { await member.GrantRoleAsync(createdRole); } while (true) { await Task.Delay(5000); if (createdLobby.Users.Count() <= 0) { await createdLobby.DeleteAsync(); await createdRole.DeleteAsync(); return; } } } catch (NBException ex) { await ex.SendException(ctx); } }
public async Task EndTask(CommandContext ctx, [Description("Role of the task")] DiscordRole role) { if (role == null) { await ctx.Channel.SendMessageAsync( $"Please specify the role of the task like so: `?{nameof(EndTask).ToLower()} (@mention)<{nameof(role).ToLower()}>`"); return; } var task = await _taskRepository.Read(role); if (task == null) { await ctx.Channel.SendMessageAsync($"Could not find the task with role {role.Mention}"); return; } if (task.StartTime == DateTime.MinValue) { await ctx.Channel.SendMessageAsync( $"This task with has not begun yet. Use the `?{nameof(BeginTask).ToLower()}` command to start a task"); return; } if (task.EndTime != DateTime.MinValue) { await ctx.Channel.SendMessageAsync("The task has already ended"); return; } //Start the work time on it task.EndTime = DateTime.Now; //Update it await _taskRepository.Update(task); await role.DeleteAsync("finished task"); var timeTaken = (task.EndTime - task.StartTime).Duration(); var embedBuilder = new DiscordEmbedBuilder { Title = "Ended a task", Description = $"Time taken for {task.TaskName} was: {string.Format("{0:00}:{1:00}:{2:00}", timeTaken.Hours, timeTaken.Minutes, timeTaken.Seconds)}", Timestamp = task.EndTime }; await ctx.Channel.SendMessageAsync(embedBuilder); }
public async Task DeleteRole(CommandContext ctx, [Description("Server role to delete")][RemainingText] DiscordRole role = null) { if (role is null) { await BotServices.SendEmbedAsync(ctx, Resources.ERR_ROLE_EXISTING, EmbedType.Warning).ConfigureAwait(false); } else { await role.DeleteAsync().ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Successfully removed the server role " + Formatter.Bold(role.Name), EmbedType.Good).ConfigureAwait(false); } }
public async Task DeleteRole(CommandContext ctx, [RemainingText] DiscordRole role) { if (role == null) { await BotServices.SendErrorEmbedAsync(ctx, ":mag: Role not found in this server!"); } else { await ctx.TriggerTypingAsync(); await role.DeleteAsync(); await ctx.RespondAsync($"Role **{role.Name}** has been **removed**"); } }
public async Task DeleteRole(CommandContext ctx, [Description("Server role to remove.")][RemainingText] DiscordRole role = null) { if (role is null) { await BotServices.SendResponseAsync(ctx, Resources.ERR_ROLE_EXISTING, ResponseType.Warning) .ConfigureAwait(false); return; } await role.DeleteAsync().ConfigureAwait(false); await ctx.RespondAsync("Successfully removed the server role " + Formatter.Bold(role.Name)) .ConfigureAwait(false); }
public async Task RemoveColor(DiscordUser user, DiscordGuild server, DiscordChannel channel) { IReadOnlyDictionary <ulong, DiscordRole> roles = server.Roles; if (!roles.Any(xr => xr.Value.Name == user.Id.ToString())) { await channel.SendMessageAsync("There was no color to remove!"); return; } DiscordRole cur = roles.First(xr => xr.Value.Name == user.Id.ToString()).Value; await cur.DeleteAsync("Color deletion"); await channel.SendMessageAsync("Color removed successfully."); Console.WriteLine("User {0}'s color was removed.", user.Username); return; }
public async Task Destroy(CommandContext ctx, DiscordRole dRole, [RemainingText] string reason = null) { await dRole.DeleteAsync(reason); await ctx.Channel.SendMessageAsync($"{dRole.Name} just got obliterated!"); }
public async Task TeamVersusTeam(CommandContext ctx, int size1, string team1, int size2, string team2, TimeSpan duration) { try { await ctx.Channel.DeleteMessageAsync(ctx.Message); var interactivity = ctx.Client.GetInteractivity(); DiscordEmbedBuilder embed = new DiscordEmbedBuilder { Title = $"{team1} vs {team2}", Color = DiscordColor.Cyan }; DiscordMessage embedMessage = await ctx.Channel.SendMessageAsync(embed : embed); DiscordEmoji team1Emoji = DiscordEmoji.FromName(ctx.Client, EmojiTeam2String); DiscordEmoji team2Emoji = DiscordEmoji.FromName(ctx.Client, EmojiTeam2String); await embedMessage.CreateReactionAsync(team1Emoji); await embedMessage.CreateReactionAsync(team2Emoji); var reactions = await interactivity.CollectReactionsAsync(embedMessage, duration); List <DiscordUser> team1Users = new List <DiscordUser>(); List <DiscordUser> team2Users = new List <DiscordUser>(); SplitTeams(ctx, team1Emoji, reactions, team1Users, team2Users); Console.WriteLine("Finish placing users"); foreach (DiscordUser user in team1Users) { Console.WriteLine($"{user.IsBot} {user.Username}"); } foreach (DiscordUser user in team2Users) { Console.WriteLine($"{user.IsBot} {user.Username}"); } team1Users.ForEach(user => team2Users.Remove(user)); team2Users.ForEach(user => team1Users.Remove(user)); DiscordRole team1Role = await ctx.Guild.CreateRoleAsync($"Team {team1}"); DiscordRole team2Role = await ctx.Guild.CreateRoleAsync($"Team {team2}"); team1Users .Take(size1) .ToList() .ForEach(async user => await(await ctx.Guild.GetMemberAsync(user.Id)).GrantRoleAsync(team1Role)); team2Users .Take(size2) .ToList() .ForEach(async user => await(await ctx.Guild.GetMemberAsync(user.Id)).GrantRoleAsync(team2Role)); DiscordChannel parentCategory = await ctx.Guild.CreateChannelCategoryAsync($"{team1} vs {team2}"); await parentCategory.AddOverwriteAsync(ctx.Guild.GetRole(DefaultRole), deny : Permissions.AccessChannels); await parentCategory.AddOverwriteAsync(team1Role, allow : Permissions.AccessChannels); await parentCategory.AddOverwriteAsync(team2Role, allow : Permissions.AccessChannels); DiscordChannel commonChannel = await ctx.Guild.CreateVoiceChannelAsync( "Common", parent : parentCategory, user_limit : size1 + size2 ); DiscordChannel team1Lobby = await ctx.Guild.CreateVoiceChannelAsync( team1, parent : parentCategory, user_limit : size1); DiscordChannel team2Lobby = await ctx.Guild.CreateVoiceChannelAsync( team2, parent : parentCategory, user_limit : size2); await team1Lobby.AddOverwriteAsync(team2Role, deny : Permissions.AccessChannels); await team2Lobby.AddOverwriteAsync(team1Role, deny : Permissions.AccessChannels); await team1Lobby.AddOverwriteAsync(team1Role, allow : Permissions.AccessChannels); await team2Lobby.AddOverwriteAsync(team2Role, allow : Permissions.AccessChannels); DiscordChannel textChannel = await ctx.Guild.CreateTextChannelAsync( "Common Chat", parent : parentCategory ); DiscordChannel team1Chat = await ctx.Guild.CreateTextChannelAsync( $"{team1} Chat", parent : parentCategory ); DiscordChannel team2Chat = await ctx.Guild.CreateTextChannelAsync( $"{team2} Chat", parent : parentCategory ); await team1Chat.AddOverwriteAsync(team2Role, deny : Permissions.AccessChannels); await team2Chat.AddOverwriteAsync(team1Role, deny : Permissions.AccessChannels); await team1Chat.AddOverwriteAsync(team1Role, allow : Permissions.AccessChannels); await team2Chat.AddOverwriteAsync(team2Role, allow : Permissions.AccessChannels); while (true) { await Task.Delay(10000); if (team1Lobby.Users.Count() <= 0 && team2Lobby.Users.Count() <= 0 && commonChannel.Users.Count() <= 0) { await commonChannel.DeleteAsync(); await team1Lobby.DeleteAsync(); await team2Lobby.DeleteAsync(); await textChannel.DeleteAsync(); await team1Chat.DeleteAsync(); await team2Chat.DeleteAsync(); await team1Role.DeleteAsync(); await team2Role.DeleteAsync(); await parentCategory.DeleteAsync(); return; } } } catch (NBException ex) { await ex.SendException(ctx); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task DeleteRole(CommandContext ctx, [Description("Die zu löschende RollenId")] ulong roleId) { DiscordRole role = ctx.Guild.GetRole(roleId); await role.DeleteAsync().ConfigureAwait(false); }