From 9f9ef8923b3bafffa9ac8573268231368c1b7349 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Tue, 9 Feb 2016 23:12:54 +0100 Subject: [PATCH] .unstuck, added points, clearer descriptions, $$$ command --- NadekoBot/Classes/DBHandler.cs | 23 ++++++++++++++++ NadekoBot/Classes/Music/StreamRequest.cs | 2 +- NadekoBot/Classes/Trivia/TriviaGame.cs | 11 +++++++- NadekoBot/Classes/_DataModels/Currency.cs | 6 ----- .../Classes/_DataModels/CurrencyStateModel.cs | 7 +++++ ...saction.cs => CurrencyTransactionModel.cs} | 1 + NadekoBot/Classes/_DataModels/IDataModel.cs | 2 +- NadekoBot/Modules/Administration.cs | 8 ++++++ NadekoBot/Modules/Gambling.cs | 26 +++++++++++++++++++ NadekoBot/Modules/Music.cs | 2 +- NadekoBot/NadekoBot.csproj | 4 +-- 11 files changed, 80 insertions(+), 12 deletions(-) delete mode 100644 NadekoBot/Classes/_DataModels/Currency.cs create mode 100644 NadekoBot/Classes/_DataModels/CurrencyStateModel.cs rename NadekoBot/Classes/_DataModels/{CurrencyTransaction.cs => CurrencyTransactionModel.cs} (81%) diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index 9dcf325e..42108b17 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -18,6 +18,9 @@ namespace NadekoBot.Classes { _conn.CreateTable(); _conn.CreateTable(); _conn.CreateTable(); + _conn.CreateTable(); + _conn.CreateTable(); + _conn.Execute(Queries.TransactionTriggerQuery); } } @@ -45,6 +48,12 @@ namespace NadekoBot.Classes { } } + internal CurrencyState GetStateByUserId(long Id) { + using (var _conn = new SQLiteConnection(_filePath)) { + return _conn.Table().Where(x => x.UserId == Id).FirstOrDefault(); + } + } + internal T Delete(int Id) where T : IDataModel, new() { using (var _conn = new SQLiteConnection(_filePath)) { var found = _conn.Find(Id); @@ -68,3 +77,17 @@ namespace NadekoBot.Classes { } } } + +public static class Queries { + public static string TransactionTriggerQuery = @" +CREATE TRIGGER IF NOT EXISTS OnTransactionAdded +AFTER INSERT ON CurrencyTransaction +BEGIN +INSERT OR REPLACE INTO CurrencyState (Id, UserId, Value, DateAdded) + VALUES (COALESCE((SELECT Id from CurrencyState where UserId = NEW.UserId),(SELECT COALESCE(MAX(Id),0)+1 from CurrencyState)), + NEW.UserId, + COALESCE((SELECT Value+New.Value FROM CurrencyState Where UserId = NEW.UserId),NEW.Value), + NEW.DateAdded); +END +"; +} diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 9107cf42..4dc13689 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -260,7 +260,7 @@ namespace NadekoBot.Classes.Music { if (buffer.Length > 0) { Console.WriteLine("Prebuffering complete."); } else { - Console.WriteLine("Didn't buffer jack shit."); + Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey."); } int blockSize = 1920 * NadekoBot.client.Audio().Config.Channels; diff --git a/NadekoBot/Classes/Trivia/TriviaGame.cs b/NadekoBot/Classes/Trivia/TriviaGame.cs index 923ec642..fc0d1433 100644 --- a/NadekoBot/Classes/Trivia/TriviaGame.cs +++ b/NadekoBot/Classes/Trivia/TriviaGame.cs @@ -110,7 +110,16 @@ namespace NadekoBot.Classes.Trivia { await _channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**"); if (users[e.User] == WinRequirement) { ShouldStopGame = true; - await _channel.Send($":exclamation: We have a winner! Its {e.User.Mention}"); + await _channel.Send($":exclamation: We have a winner! Its {e.User.Mention}."); + // add points to the winner + await Task.Run(async () => { + DBHandler.Instance.InsertData(new _DataModels.CurrencyTransaction { + Reason = "Won Trivia", + UserId = (long)e.User.Id, + Value = 2, + }); + await e.User.SendMessage("👑Congratulations!👑\nYou got: 🌸🌸"); + }); } } } diff --git a/NadekoBot/Classes/_DataModels/Currency.cs b/NadekoBot/Classes/_DataModels/Currency.cs deleted file mode 100644 index b090db92..00000000 --- a/NadekoBot/Classes/_DataModels/Currency.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace NadekoBot.Classes._DataModels { - class Currency : IDataModel { - public long UserId { get; set; } - public long Value { get; set; } - } -} diff --git a/NadekoBot/Classes/_DataModels/CurrencyStateModel.cs b/NadekoBot/Classes/_DataModels/CurrencyStateModel.cs new file mode 100644 index 00000000..5583b805 --- /dev/null +++ b/NadekoBot/Classes/_DataModels/CurrencyStateModel.cs @@ -0,0 +1,7 @@ +namespace NadekoBot.Classes._DataModels { + class CurrencyState : IDataModel { + public long Value { get; set; } + [SQLite.Unique] + public long UserId { get; set; } + } +} diff --git a/NadekoBot/Classes/_DataModels/CurrencyTransaction.cs b/NadekoBot/Classes/_DataModels/CurrencyTransactionModel.cs similarity index 81% rename from NadekoBot/Classes/_DataModels/CurrencyTransaction.cs rename to NadekoBot/Classes/_DataModels/CurrencyTransactionModel.cs index 1cde21f3..acca89cb 100644 --- a/NadekoBot/Classes/_DataModels/CurrencyTransaction.cs +++ b/NadekoBot/Classes/_DataModels/CurrencyTransactionModel.cs @@ -2,5 +2,6 @@ class CurrencyTransaction : IDataModel { public string Reason { get; set; } public int Value { get; set; } + public long UserId { get; set; } } } diff --git a/NadekoBot/Classes/_DataModels/IDataModel.cs b/NadekoBot/Classes/_DataModels/IDataModel.cs index d2dc0b04..5c20fe92 100644 --- a/NadekoBot/Classes/_DataModels/IDataModel.cs +++ b/NadekoBot/Classes/_DataModels/IDataModel.cs @@ -2,7 +2,7 @@ using System; namespace NadekoBot.Classes._DataModels { - class IDataModel { + abstract class IDataModel { [PrimaryKey, AutoIncrement] public int Id { get; set; } [Newtonsoft.Json.JsonProperty("createdAt")] diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index fd8fca96..b98c12ca 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -567,6 +567,14 @@ namespace NadekoBot.Modules { }); }); + cgb.CreateCommand(".unstuck") + .Description("Clears the message queue. **OWNER ONLY**") + .Do(async e => { + if (e.User.Id != NadekoBot.OwnerID) + return; + await Task.Run(() => NadekoBot.client.MessageQueue.Clear()); + }); + /*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/Gambling.cs b/NadekoBot/Modules/Gambling.cs index ec77ff80..d06827f8 100644 --- a/NadekoBot/Modules/Gambling.cs +++ b/NadekoBot/Modules/Gambling.cs @@ -1,5 +1,6 @@ using Discord.Commands; using Discord.Modules; +using NadekoBot.Extensions; using System.Linq; namespace NadekoBot.Modules @@ -32,6 +33,31 @@ namespace NadekoBot.Modules var members = role.Members.Where(u => u.Status == Discord.UserStatus.Online); // only online await e.Channel.SendMessage($"**Raffled user:** {members.ToArray()[new System.Random().Next(0, members.Count())].Name}"); }); + /* + cgb.CreateCommand("$$") + .Description("Add moneyz") + .Parameter("val", ParameterType.Required) + .Do(e => { + var arg = e.GetArg("val"); + var num = int.Parse(arg); + Classes.DBHandler.Instance.InsertData( + new Classes._DataModels.CurrencyTransaction { + Value = num, + Reason = "Money plz", + UserId = (long)e.User.Id, + }); + }); + */ + cgb.CreateCommand("$$$") + .Description("Check how many NadekoPoints you have.") + .Do(async e => { + var pts = Classes.DBHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; + string str = $"`You have {pts} NadekoPoints".SnPl((int)pts)+"`\n"; + for (int i = 0; i < pts; i++) { + str += "🌸"; + } + await e.Channel.SendMessage(str); + }); }); } } diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 3e94809b..f78f6c62 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -48,7 +48,7 @@ namespace NadekoBot.Modules { cgb.CreateCommand("p") .Alias("pause") - .Description("Pauses the song") + .Description("Pauses or Unpauses the song") .Do(async e => { if (musicPlayers.ContainsKey(e.Server) == false) return; if (musicPlayers[e.Server].TogglePause()) diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 8541cb0f..8f04c6cd 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -133,8 +133,8 @@ - - + +