From 4668985d263c8f3084299cf867aa67f5c63d92fd Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 10 Feb 2016 15:43:44 +0100 Subject: [PATCH] Donators commands, removed message cache --- NadekoBot/Classes/DBHandler.cs | 1 + NadekoBot/Classes/_DataModels/Donator.cs | 13 +++++++++ NadekoBot/Modules/Administration.cs | 37 ++++++++++++++++++++++++ NadekoBot/Modules/Conversations.cs | 2 +- NadekoBot/NadekoBot.cs | 4 ++- NadekoBot/NadekoBot.csproj | 1 + 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 NadekoBot/Classes/_DataModels/Donator.cs diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index 42108b17..e20c1fe0 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -20,6 +20,7 @@ namespace NadekoBot.Classes { _conn.CreateTable(); _conn.CreateTable(); _conn.CreateTable(); + _conn.CreateTable(); _conn.Execute(Queries.TransactionTriggerQuery); } } diff --git a/NadekoBot/Classes/_DataModels/Donator.cs b/NadekoBot/Classes/_DataModels/Donator.cs new file mode 100644 index 00000000..0a4e9030 --- /dev/null +++ b/NadekoBot/Classes/_DataModels/Donator.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Classes._DataModels { + class Donator : IDataModel { + public long UserId { get; set; } + public string UserName { get; set; } + public int Amount { get; set; } + } +} diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 7c3be946..e4df1a5a 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -562,6 +562,43 @@ namespace NadekoBot.Modules { return; await Task.Run(() => NadekoBot.client.MessageQueue.Clear()); }); + + cgb.CreateCommand(".donators") + .Description("List of lovely people who donated to keep this project alive.") + .Do(async e => { + await Task.Run(async () => { + var rows = Classes.DBHandler.Instance.GetAllRows(); + var donatorsOrdered = rows.OrderBy(d => d.Amount); + string str = $"`Total number of people who donated is {donatorsOrdered.Count()}`\n"; + foreach (var don in donatorsOrdered) { + str += don.UserName; + } + await e.Channel.SendMessage(str); + }); + }); + + //THIS IS INTENTED TO BE USED ONLY BY THE ORIGINAL BOT OWNER + cgb.CreateCommand(".adddon") + .Description("Add a donator to the database.") + .Parameter("donator") + .Parameter("amount") + .Do(e => { + try { + if (NadekoBot.OwnerID != e.User.Id) + return; + var donator = e.Server.FindUsers(e.GetArg("donator")).FirstOrDefault(); + var amount = int.Parse(e.GetArg("amount")); + Classes.DBHandler.Instance.InsertData(new Donator { + Amount = amount, + UserName = donator.Name, + UserId = (long)e.User.Id + }); + e.Channel.SendMessage("Successfuly added a new donator. 👑"); + } catch (Exception ex) { + Console.WriteLine(ex); + Console.WriteLine("---------------\nInner error:\n" + ex.InnerException); + } + }); /*cgb.CreateCommand(".voicetext") .Description("Enabled or disabled voice to text channel connection. Only people in a certain voice channel will see ") diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index 993c6c20..b0be74fa 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -276,7 +276,7 @@ namespace NadekoBot.Modules { .Do(async e => { Message msg = null; - var msgs = e.Channel.Messages + var msgs = (await e.Channel.DownloadMessages(100)) .Where(m => m.MentionedUsers.Contains(e.User)) .OrderByDescending(m => m.Timestamp); if (msgs.Count() > 0) diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index a5f03d62..f35d1421 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -61,7 +61,9 @@ namespace NadekoBot { } //create new discord client - client = new DiscordClient(); + client = new DiscordClient(new DiscordConfig { + MessageCacheSize = 0 + }); //create a command service var commandService = new CommandService(new CommandServiceConfig { diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 90ce03c9..ce5bfaa7 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -139,6 +139,7 @@ +