public async Task ShowCustReact(int id) { CustomReaction[] customReactions; if (Context.Guild == null) { customReactions = GlobalReactions; } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[] { }); } var found = customReactions.FirstOrDefault(cr => cr?.Id == id); if (found == null) { await ReplyErrorLocalized("no_found_id").ConfigureAwait(false); return; } else { await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription($"#{id}") .AddField(efb => efb.WithName(GetText("trigger")).WithValue(found.Trigger)) .AddField(efb => efb.WithName(GetText("response")).WithValue(found.Response + "\n```css\n" + found.Response + "```")) ).ConfigureAwait(false); } }
public async Task ListCustReact(All x) { CustomReaction[] customReactions; if (Context.Guild == null) { customReactions = GlobalReactions.Where(cr => cr != null).ToArray(); } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[] { }).Where(cr => cr != null).ToArray(); } if (customReactions == null || !customReactions.Any()) { await ReplyErrorLocalized("no_found").ConfigureAwait(false); return; } var txtStream = await customReactions.GroupBy(cr => cr.Trigger) .OrderBy(cr => cr.Key) .Select(cr => new { Trigger = cr.Key, Responses = cr.Select(y => new { id = y.Id, text = y.Response }).ToList() }) .ToJson() .ToStream() .ConfigureAwait(false); if (Context.Guild == null) // its a private one, just send back { await Context.Channel.SendFileAsync(txtStream, "customreactions.txt", GetText("list_all")).ConfigureAwait(false); } else { await((IGuildUser)Context.User).SendFileAsync(txtStream, "customreactions.txt", GetText("list_all")).ConfigureAwait(false); } }
public async Task ListCustReact(int page = 1) { if (page < 1 || page > 1000) { return; } CustomReaction[] customReactions; if (Context.Guild == null) { customReactions = GlobalReactions.Where(cr => cr != null).ToArray(); } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty <CustomReaction>()).Where(cr => cr != null).ToArray(); } if (customReactions == null || !customReactions.Any()) { await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); } else { var lastPage = customReactions.Length / 20; await Context.Channel.SendPaginatedConfirmAsync(page, curPage => new EmbedBuilder().WithOkColor() .WithTitle("Custom reactions") .WithDescription(string.Join("\n", customReactions.OrderBy(cr => cr.Trigger) .Skip((curPage - 1) * 20) .Take(20) .Select(cr => $"`#{cr.Id}` `Trigger:` {cr.Trigger}"))), lastPage) .ConfigureAwait(false); } }
public async Task ShowCustReact(IUserMessage imsg, int id) { var channel = imsg.Channel as ITextChannel; ConcurrentHashSet <CustomReaction> customReactions; if (channel == null) { customReactions = GlobalReactions; } else { customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>()); } var found = customReactions.FirstOrDefault(cr => cr.Id == id); if (found == null) { await imsg.Channel.SendErrorAsync("No custom reaction found with that id.").ConfigureAwait(false); } else { await imsg.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor) .WithDescription($"#{id}") .AddField(efb => efb.WithName("Trigger").WithValue(found.Trigger)) .AddField(efb => efb.WithName("Response").WithValue(found.Response + "\n```css\n" + found.Response + "```")) .Build()).ConfigureAwait(false); } }
public async Task ListCustReactG(IUserMessage imsg, int page = 1) { var channel = imsg.Channel as ITextChannel; if (page < 1 || page > 10000) { return; } ConcurrentHashSet <CustomReaction> customReactions; if (channel == null) { customReactions = GlobalReactions; } else { customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>()); } if (customReactions == null || !customReactions.Any()) { await imsg.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); } else { await imsg.Channel.SendConfirmAsync($"Page {page} of custom reactions (grouped):", string.Join("\r\n", customReactions .GroupBy(cr => cr.Trigger) .OrderBy(cr => cr.Key) .Skip((page - 1) * 20) .Take(20) .Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))) .ConfigureAwait(false); } }
public async Task ListCustReact(int page = 1) { if (page < 1 || page > 1000) { return; } ConcurrentHashSet <CustomReaction> customReactions; if (Context.Guild == null) { customReactions = GlobalReactions; } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet <CustomReaction>()); } if (customReactions == null || !customReactions.Any()) { await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); } else { await Context.Channel.SendConfirmAsync( $"Page {page} of custom reactions:", string.Join("\n", customReactions.OrderBy(cr => cr.Trigger) .Skip((page - 1) * 20) .Take(20) .Select(cr => $"`#{cr.Id}` `Trigger:` {cr.Trigger}"))) .ConfigureAwait(false); } }
public async Task AddCustReact(IUserMessage imsg, string key, [Remainder] string message) { var channel = imsg.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key)) { return; } key = key.ToLowerInvariant(); if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator)) { try { await imsg.Channel.SendErrorAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { } return; } var cr = new CustomReaction() { GuildId = channel?.Guild.Id, IsRegex = false, Trigger = key, Response = message, }; using (var uow = DbHandler.UnitOfWork()) { uow.CustomReactions.Add(cr); await uow.CompleteAsync().ConfigureAwait(false); } if (channel == null) { GlobalReactions.Add(cr); } else { var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>()); reactions.Add(cr); } await imsg.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor) .WithTitle("New Custom Reaction") .WithDescription($"#{cr.Id}") .AddField(efb => efb.WithName("Trigger").WithValue(key)) .AddField(efb => efb.WithName("Response").WithValue(message)) .Build()).ConfigureAwait(false); }
public async Task DelCustReact(IUserMessage imsg, int id) { var channel = imsg.Channel as ITextChannel; if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator)) { try { await imsg.Channel.SendErrorAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { } return; } var success = false; CustomReaction toDelete; using (var uow = DbHandler.UnitOfWork()) { toDelete = uow.CustomReactions.Get(id); if (toDelete == null) //not found { return; } if ((toDelete.GuildId == null || toDelete.GuildId == 0) && channel == null) { uow.CustomReactions.Remove(toDelete); GlobalReactions.RemoveWhere(cr => cr.Id == toDelete.Id); success = true; } else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && channel?.Guild.Id == toDelete.GuildId) { uow.CustomReactions.Remove(toDelete); GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>()).RemoveWhere(cr => cr.Id == toDelete.Id); success = true; } if (success) { await uow.CompleteAsync().ConfigureAwait(false); } } if (success) { await imsg.Channel.SendConfirmAsync("Deleted custom reaction", toDelete.ToString()).ConfigureAwait(false); } else { await imsg.Channel.SendErrorAsync("Failed to find that custom reaction.").ConfigureAwait(false); } }
public async Task ListCustReact(int page = 1) { if (page < 1 || page > 1000) { return; } CustomReaction[] customReactions; if (Context.Guild == null) { customReactions = GlobalReactions.Where(cr => cr != null).ToArray(); } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty <CustomReaction>()).Where(cr => cr != null).ToArray(); } if (customReactions == null || !customReactions.Any()) { await ReplyErrorLocalized("no_found").ConfigureAwait(false); return; } var lastPage = customReactions.Length / 20; await Context.Channel.SendPaginatedConfirmAsync(page, curPage => new EmbedBuilder().WithOkColor() .WithTitle(GetText("name")) .WithDescription(string.Join("\n", customReactions.OrderBy(cr => cr.Trigger) .Skip((curPage - 1) * 20) .Take(20) .Select(cr => { var str = $"`#{cr.Id}` {cr.Trigger}"; if (cr.AutoDeleteTrigger) { str = "🗑" + str; } if (cr.DmResponse) { str = "📪" + str; } return(str); }))), lastPage) .ConfigureAwait(false); }
public async Task ListCustReactG(int page = 1) { if (page < 1 || page > 10000) { return; } ConcurrentHashSet <CustomReaction> customReactions; if (Context.Guild == null) { customReactions = GlobalReactions; } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet <CustomReaction>()); } if (customReactions == null || !customReactions.Any()) { await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); } else { var ordered = customReactions .GroupBy(cr => cr.Trigger) .OrderBy(cr => cr.Key) .ToList(); var lastPage = ordered.Count / 20; await Context.Channel.SendPaginatedConfirmAsync(page, (curPage) => new EmbedBuilder().WithOkColor() .WithTitle($"Custom Reactions (grouped)") .WithDescription(string.Join("\r\n", ordered .Skip((curPage - 1) * 20) .Take(20) .Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage) .ConfigureAwait(false); } }
public async Task ListCustReactG(int page = 1) { if (page < 1 || page > 10000) { return; } CustomReaction[] customReactions; if (Context.Guild == null) { customReactions = GlobalReactions.Where(cr => cr != null).ToArray(); } else { customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[] { }).Where(cr => cr != null).ToArray(); } if (customReactions == null || !customReactions.Any()) { await ReplyErrorLocalized("no_found").ConfigureAwait(false); } else { var ordered = customReactions .GroupBy(cr => cr.Trigger) .OrderBy(cr => cr.Key) .ToList(); var lastPage = ordered.Count / 20; await Context.Channel.SendPaginatedConfirmAsync(page, (curPage) => new EmbedBuilder().WithOkColor() .WithTitle(GetText("name")) .WithDescription(string.Join("\r\n", ordered .Skip((curPage - 1) * 20) .Take(20) .Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage) .ConfigureAwait(false); } }
public async Task ListCustReact(IUserMessage imsg, All x) { var channel = imsg.Channel as ITextChannel; ConcurrentHashSet <CustomReaction> customReactions; if (channel == null) { customReactions = GlobalReactions; } else { customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>()); } if (customReactions == null || !customReactions.Any()) { await imsg.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); } else { var txtStream = await customReactions.GroupBy(cr => cr.Trigger) .OrderBy(cr => cr.Key) .Select(cr => new { Trigger = cr.Key, Responses = cr.Select(y => y.Response).ToList() }) .ToJson() .ToStream() .ConfigureAwait(false); if (channel == null) // its a private one, just send back { await imsg.Channel.SendFileAsync(txtStream, "customreactions.txt", "List of all custom reactions").ConfigureAwait(false); } else { await((IGuildUser)imsg.Author).SendFileAsync(txtStream, "customreactions.txt", "List of all custom reactions").ConfigureAwait(false); } } }