diff --git a/NadekoBot/Modules/Conversations/Conversations.cs b/NadekoBot/Modules/Conversations/Conversations.cs index 177f0478..c83463aa 100644 --- a/NadekoBot/Modules/Conversations/Conversations.cs +++ b/NadekoBot/Modules/Conversations/Conversations.cs @@ -2,6 +2,7 @@ using Discord; using Discord.Commands; using Discord.Modules; using NadekoBot.Classes.Conversations.Commands; +using NadekoBot.DataModels; using NadekoBot.Extensions; using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Properties; @@ -73,6 +74,25 @@ namespace NadekoBot.Modules.Conversations else await e.Channel.SendMessage("💢`No quote found.`").ConfigureAwait(false); }); + + cgb.CreateCommand("..qdel") + .Description("Deletes all quotes with the specified keyword. You have to either be bot owner or the creator of the quote to delete it.\n**Usage**: `..qdel abc`") + .Parameter("quote", ParameterType.Required) + .Do(async e => + { + var text = e.GetArg("quote")?.Trim(); + if (string.IsNullOrWhiteSpace(text)) + return; + await Task.Run(() => + { + if (NadekoBot.IsOwner(e.User.Id)) + Classes.DbHandler.Instance.DeleteWhere(uq => uq.Keyword == text); + else + Classes.DbHandler.Instance.DeleteWhere(uq => uq.Keyword == text && uq.UserName == e.User.Name); + }).ConfigureAwait(false); + + await e.Channel.SendMessage("`Done.`").ConfigureAwait(false); + }); }); manager.CreateCommands(NadekoBot.BotMention, cgb => @@ -206,36 +226,36 @@ namespace NadekoBot.Modules.Conversations } cgb.CreateCommand("slm") - .Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)") - .Do(async e => - { + .Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)") + .Do(async e => + { - Message msg = null; - var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false)) + Message msg = null; + var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false)) .Where(m => m.MentionedUsers.Contains(e.User)) .OrderByDescending(m => m.Timestamp); - if (msgs.Any()) - msg = msgs.First(); - else - { - var attempt = 0; - Message lastMessage = null; - while (msg == null && attempt++ < 5) - { - var msgsarr = await e.Channel.DownloadMessages(100, lastMessage?.Id).ConfigureAwait(false); - msg = msgsarr + if (msgs.Any()) + msg = msgs.First(); + else + { + var attempt = 0; + Message lastMessage = null; + while (msg == null && attempt++ < 5) + { + var msgsarr = await e.Channel.DownloadMessages(100, lastMessage?.Id).ConfigureAwait(false); + msg = msgsarr .Where(m => m.MentionedUsers.Contains(e.User)) .OrderByDescending(m => m.Timestamp) .FirstOrDefault(); - lastMessage = msgsarr.OrderBy(m => m.Timestamp).First(); - } - } - if (msg != null) - await e.Channel.SendMessage($"Last message mentioning you was at {msg.Timestamp}\n**Message from {msg.User.Name}:** {msg.RawText}") + lastMessage = msgsarr.OrderBy(m => m.Timestamp).First(); + } + } + if (msg != null) + await e.Channel.SendMessage($"Last message mentioning you was at {msg.Timestamp}\n**Message from {msg.User.Name}:** {msg.RawText}") .ConfigureAwait(false); - else - await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false); - }); + else + await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false); + }); cgb.CreateCommand("hide") .Description("Hides Nadeko in plain sight!11!!")