From f61606f8bc853ab3a49dc2c3e13329d443cfca1c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 7 Feb 2016 23:00:53 +0100 Subject: [PATCH] More cleanup, removed parse completely... --- NadekoBot/Classes/NadekoStats.cs | 5 ++-- NadekoBot/Classes/_JSONModels.cs | 3 --- NadekoBot/Commands/RequestsCommand.cs | 1 - NadekoBot/Commands/ServerGreetCommand.cs | 5 ++-- NadekoBot/Commands/SpeedTyping.cs | 30 +++++++++++------------- NadekoBot/Modules/Searches.cs | 2 +- NadekoBot/NadekoBot.cs | 17 -------------- NadekoBot/NadekoBot.csproj | 8 ------- 8 files changed, 19 insertions(+), 52 deletions(-) diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index 521e6d46..35f03e9c 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -1,6 +1,5 @@ using Discord; using Discord.Commands; -using Parse; using System; using System.Collections.Generic; using System.Diagnostics; @@ -35,8 +34,8 @@ namespace NadekoBot _statsSW = new Stopwatch(); _statsSW.Start(); _service.CommandExecuted += StatsCollector_RanCommand; - - StartCollecting(); + + Task.Run(() => StartCollecting()); Console.WriteLine("Logging enabled."); } diff --git a/NadekoBot/Classes/_JSONModels.cs b/NadekoBot/Classes/_JSONModels.cs index 4a7d67c5..6aaaa621 100644 --- a/NadekoBot/Classes/_JSONModels.cs +++ b/NadekoBot/Classes/_JSONModels.cs @@ -7,11 +7,8 @@ public string BotMention; public string GoogleAPIKey; public ulong OwnerID; - public string ParseID; - public string ParseKey; public string TrelloAppKey; public bool? ForwardMessages; - public string OsuApiKey; public string SoundCloudClientID; public string MashapeKey; } diff --git a/NadekoBot/Commands/RequestsCommand.cs b/NadekoBot/Commands/RequestsCommand.cs index 55275b52..61e3849c 100644 --- a/NadekoBot/Commands/RequestsCommand.cs +++ b/NadekoBot/Commands/RequestsCommand.cs @@ -20,7 +20,6 @@ namespace NadekoBot.Commands { var task = Classes.DBHandler.Instance.GetAllRows(); string str = "Here are all current requests for NadekoBot:\n\n"; - int i = 1; foreach (var reqObj in task) { str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" + $"**{reqObj.RequestText}**\n----------\n"; diff --git a/NadekoBot/Commands/ServerGreetCommand.cs b/NadekoBot/Commands/ServerGreetCommand.cs index d249f0d1..5c997f7e 100644 --- a/NadekoBot/Commands/ServerGreetCommand.cs +++ b/NadekoBot/Commands/ServerGreetCommand.cs @@ -7,7 +7,6 @@ using Discord.Commands; using System.Collections.Concurrent; using NadekoBot.Extensions; using Discord; -using Parse; using System.ComponentModel; /* Voltana's legacy @@ -129,7 +128,7 @@ namespace NadekoBot.Commands { get { return (ulong)_model.ServerId; } set { _model.ServerId = (long)value; } } - + public AnnounceControls(Classes._DataModels.Announcement model) { this._model = model; } @@ -238,7 +237,7 @@ namespace NadekoBot.Commands { AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); AnnouncementsDictionary[e.Server.Id].ToggleByePM(); - if(AnnouncementsDictionary[e.Server.Id].ByePM) + if (AnnouncementsDictionary[e.Server.Id].ByePM) await e.Send("Bye messages will be sent in a PM from now on.\n :warning: Keep in mind this might fail if the user and the bot have no common servers after the user leaves."); else await e.Send("Bye messages will be sent in a bound channel from now on."); diff --git a/NadekoBot/Commands/SpeedTyping.cs b/NadekoBot/Commands/SpeedTyping.cs index 98564331..88986f40 100644 --- a/NadekoBot/Commands/SpeedTyping.cs +++ b/NadekoBot/Commands/SpeedTyping.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; using Discord; using Discord.Commands; using NadekoBot.Extensions; -using System.Threading; using System.Diagnostics; -using Parse; -namespace NadekoBot.Commands { +namespace NadekoBot.Commands { public static class SentencesProvider { internal static string GetRandomSentence() { - var data = new ParseQuery("TypingArticles").FindAsync().Result; + var data = Classes.DBHandler.Instance.GetAllRows(); try { - return data.ToList()[(new Random()).Next(0, data.Count())].Get("text"); + return data.ToList()[new Random().Next(0, data.Count())].Text; } catch (Exception) { return "Failed retrieving data from parse. Owner didn't add any articles to type using `typeadd`."; } @@ -30,7 +27,7 @@ namespace NadekoBot.Commands { public bool IsActive; private Stopwatch sw; private List finishedUserIds; - + public TypingGame(Channel channel) { this.channel = channel; IsActive = false; @@ -65,10 +62,10 @@ namespace NadekoBot.Commands { await Task.Delay(1000); await msg.Edit("Starting new typing contest in **1**..."); await Task.Delay(1000); - await msg.Edit($":book:**{currentSentence.Replace(" "," \x200B")}**:book:"); + await msg.Edit($":book:**{currentSentence.Replace(" ", " \x200B")}**:book:"); sw.Start(); HandleAnswers(); - + while (i > 0) { await Task.Delay(1000); i--; @@ -113,7 +110,7 @@ namespace NadekoBot.Commands { runningContests = new Dictionary(); } - public override Func DoFunc()=> + public override Func DoFunc() => async e => { if (runningContests.ContainsKey(e.User.Server.Id) && runningContests[e.User.Server.Id].IsActive) { await e.Send($"Contest already running in { runningContests[e.User.Server.Id].Channell.Mention } channel."); @@ -124,15 +121,14 @@ namespace NadekoBot.Commands { return; } var tg = new TypingGame(e.Channel); - runningContests.Add(e.Server.Id,tg); + runningContests.Add(e.Server.Id, tg); await tg.Start(); }; - private Func QuitFunc() => + private Func QuitFunc() => async e => { if (runningContests.ContainsKey(e.User.Server.Id) && - await runningContests[e.User.Server.Id].Stop()) - { + await runningContests[e.User.Server.Id].Stop()) { runningContests.Remove(e.User.Server.Id); return; } @@ -150,14 +146,16 @@ namespace NadekoBot.Commands { cgb.CreateCommand("typeadd") .Description("Adds a new article to the typing contest. Owner only.") - .Parameter("text",ParameterType.Unparsed) - .Do(e => { + .Parameter("text", ParameterType.Unparsed) + .Do(async e => { if (e.User.Id != NadekoBot.OwnerID || string.IsNullOrWhiteSpace(e.GetArg("text"))) return; Classes.DBHandler.Instance.InsertData(new Classes._DataModels.TypingArticle { Text = e.GetArg("text"), DateAdded = DateTime.Now }); + + await e.Send("Added new article for typing."); }); //todo add user submissions diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 1e8bc79d..a8781bf9 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -224,7 +224,7 @@ namespace NadekoBot.Modules { await e.Send($"`Profile Link:`https://osu.ppy.sh/u/{Uri.EscapeDataString(e.GetArg("usr"))}\n`Image provided by https://lemmmy.pw/osusig`"); } catch (Exception) { } }; - } catch (Exception ex) { + } catch { await e.Channel.SendMessage(":anger: Failed retrieving osu signature :\\"); } } diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 2bb396e5..c7635dcb 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -2,7 +2,6 @@ using System; using System.IO; using Newtonsoft.Json; -using Parse; using Discord.Commands; using NadekoBot.Modules; using Discord.Modules; @@ -22,7 +21,6 @@ namespace NadekoBot { public static string TrelloAppKey; public static bool ForwardMessages = false; public static Credentials creds; - public static bool ParseActive = false; static void Main() { //load credentials from credentials.json @@ -49,26 +47,11 @@ namespace NadekoBot { ForwardMessages = true; Console.WriteLine("Forwarding messages."); } - if (string.IsNullOrWhiteSpace(creds.ParseID) || string.IsNullOrWhiteSpace(creds.ParseKey)) { - Console.WriteLine("Parse key and/or ID not found. Some functionality will be missing."); - ParseActive = false; - } else ParseActive = true; - - if(string.IsNullOrWhiteSpace(creds.OsuApiKey)) - Console.WriteLine("No osu API key found. Osu functionality is disabled."); - else - Console.WriteLine("Osu enabled."); if(string.IsNullOrWhiteSpace(creds.SoundCloudClientID)) Console.WriteLine("No soundcloud Client ID found. Soundcloud streaming is disabled."); else Console.WriteLine("SoundCloud streaming enabled."); - //init parse - if (ParseActive) - try { - ParseClient.Initialize(creds.ParseID, creds.ParseKey); - } catch (Exception) { Console.WriteLine("Parse exception. Probably wrong parse credentials."); } - OwnerID = creds.OwnerID; password = creds.Password; } catch (Exception ex) { diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 8bc35565..fb1cbfb8 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -104,14 +104,6 @@ ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll True - - ..\packages\Parse.1.6.2\lib\net45\Parse.dll - True - - - ..\packages\Parse.1.6.2\lib\net45\Parse.NetFx45.dll - True - ..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll True