Added ..qdel, stop crying now ;p

This commit is contained in:
Master Kwoth 2016-05-21 16:15:02 +02:00
parent c7a83aa58a
commit 98d166e539

View File

@ -2,6 +2,7 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Classes.Conversations.Commands; using NadekoBot.Classes.Conversations.Commands;
using NadekoBot.DataModels;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Modules.Permissions.Classes;
using NadekoBot.Properties; using NadekoBot.Properties;
@ -73,6 +74,25 @@ namespace NadekoBot.Modules.Conversations
else else
await e.Channel.SendMessage("💢`No quote found.`").ConfigureAwait(false); 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<UserQuote>(uq => uq.Keyword == text);
else
Classes.DbHandler.Instance.DeleteWhere<UserQuote>(uq => uq.Keyword == text && uq.UserName == e.User.Name);
}).ConfigureAwait(false);
await e.Channel.SendMessage("`Done.`").ConfigureAwait(false);
});
}); });
manager.CreateCommands(NadekoBot.BotMention, cgb => manager.CreateCommands(NadekoBot.BotMention, cgb =>
@ -206,36 +226,36 @@ namespace NadekoBot.Modules.Conversations
} }
cgb.CreateCommand("slm") cgb.CreateCommand("slm")
.Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)") .Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)")
.Do(async e => .Do(async e =>
{ {
Message msg = null; Message msg = null;
var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false)) var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false))
.Where(m => m.MentionedUsers.Contains(e.User)) .Where(m => m.MentionedUsers.Contains(e.User))
.OrderByDescending(m => m.Timestamp); .OrderByDescending(m => m.Timestamp);
if (msgs.Any()) if (msgs.Any())
msg = msgs.First(); msg = msgs.First();
else else
{ {
var attempt = 0; var attempt = 0;
Message lastMessage = null; Message lastMessage = null;
while (msg == null && attempt++ < 5) while (msg == null && attempt++ < 5)
{ {
var msgsarr = await e.Channel.DownloadMessages(100, lastMessage?.Id).ConfigureAwait(false); var msgsarr = await e.Channel.DownloadMessages(100, lastMessage?.Id).ConfigureAwait(false);
msg = msgsarr msg = msgsarr
.Where(m => m.MentionedUsers.Contains(e.User)) .Where(m => m.MentionedUsers.Contains(e.User))
.OrderByDescending(m => m.Timestamp) .OrderByDescending(m => m.Timestamp)
.FirstOrDefault(); .FirstOrDefault();
lastMessage = msgsarr.OrderBy(m => m.Timestamp).First(); lastMessage = msgsarr.OrderBy(m => m.Timestamp).First();
} }
} }
if (msg != null) if (msg != null)
await e.Channel.SendMessage($"Last message mentioning you was at {msg.Timestamp}\n**Message from {msg.User.Name}:** {msg.RawText}") await e.Channel.SendMessage($"Last message mentioning you was at {msg.Timestamp}\n**Message from {msg.User.Name}:** {msg.RawText}")
.ConfigureAwait(false); .ConfigureAwait(false);
else else
await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false); await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false);
}); });
cgb.CreateCommand("hide") cgb.CreateCommand("hide")
.Description("Hides Nadeko in plain sight!11!!") .Description("Hides Nadeko in plain sight!11!!")