More cleanup, removed parse completely...

This commit is contained in:
Master Kwoth 2016-02-07 23:00:53 +01:00
parent 34989ae9f4
commit f61606f8bc
8 changed files with 19 additions and 52 deletions

View File

@ -1,6 +1,5 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Parse;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -36,7 +35,7 @@ namespace NadekoBot
_statsSW.Start(); _statsSW.Start();
_service.CommandExecuted += StatsCollector_RanCommand; _service.CommandExecuted += StatsCollector_RanCommand;
StartCollecting(); Task.Run(() => StartCollecting());
Console.WriteLine("Logging enabled."); Console.WriteLine("Logging enabled.");
} }

View File

@ -7,11 +7,8 @@
public string BotMention; public string BotMention;
public string GoogleAPIKey; public string GoogleAPIKey;
public ulong OwnerID; public ulong OwnerID;
public string ParseID;
public string ParseKey;
public string TrelloAppKey; public string TrelloAppKey;
public bool? ForwardMessages; public bool? ForwardMessages;
public string OsuApiKey;
public string SoundCloudClientID; public string SoundCloudClientID;
public string MashapeKey; public string MashapeKey;
} }

View File

@ -20,7 +20,6 @@ namespace NadekoBot.Commands {
var task = Classes.DBHandler.Instance.GetAllRows<Classes._DataModels.Request>(); var task = Classes.DBHandler.Instance.GetAllRows<Classes._DataModels.Request>();
string str = "Here are all current requests for NadekoBot:\n\n"; string str = "Here are all current requests for NadekoBot:\n\n";
int i = 1;
foreach (var reqObj in task) { foreach (var reqObj in task) {
str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" + str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" +
$"**{reqObj.RequestText}**\n----------\n"; $"**{reqObj.RequestText}**\n----------\n";

View File

@ -7,7 +7,6 @@ using Discord.Commands;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using Discord; using Discord;
using Parse;
using System.ComponentModel; using System.ComponentModel;
/* Voltana's legacy /* Voltana's legacy
@ -238,7 +237,7 @@ namespace NadekoBot.Commands {
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary[e.Server.Id].ToggleByePM(); 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."); 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 else
await e.Send("Bye messages will be sent in a bound channel from now on."); await e.Send("Bye messages will be sent in a bound channel from now on.");

View File

@ -1,22 +1,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Threading;
using System.Diagnostics; using System.Diagnostics;
using Parse;
namespace NadekoBot.Commands { namespace NadekoBot.Commands {
public static class SentencesProvider { public static class SentencesProvider {
internal static string GetRandomSentence() { internal static string GetRandomSentence() {
var data = new ParseQuery<ParseObject>("TypingArticles").FindAsync().Result; var data = Classes.DBHandler.Instance.GetAllRows<Classes._DataModels.TypingArticle>();
try { try {
return data.ToList()[(new Random()).Next(0, data.Count())].Get<string>("text"); return data.ToList()[new Random().Next(0, data.Count())].Text;
} catch (Exception) { } catch (Exception) {
return "Failed retrieving data from parse. Owner didn't add any articles to type using `typeadd`."; return "Failed retrieving data from parse. Owner didn't add any articles to type using `typeadd`.";
} }
@ -65,7 +62,7 @@ namespace NadekoBot.Commands {
await Task.Delay(1000); await Task.Delay(1000);
await msg.Edit("Starting new typing contest in **1**..."); await msg.Edit("Starting new typing contest in **1**...");
await Task.Delay(1000); await Task.Delay(1000);
await msg.Edit($":book:**{currentSentence.Replace(" "," \x200B")}**:book:"); await msg.Edit($":book:**{currentSentence.Replace(" ", " \x200B")}**:book:");
sw.Start(); sw.Start();
HandleAnswers(); HandleAnswers();
@ -113,7 +110,7 @@ namespace NadekoBot.Commands {
runningContests = new Dictionary<ulong, TypingGame>(); runningContests = new Dictionary<ulong, TypingGame>();
} }
public override Func<CommandEventArgs, Task> DoFunc()=> public override Func<CommandEventArgs, Task> DoFunc() =>
async e => { async e => {
if (runningContests.ContainsKey(e.User.Server.Id) && runningContests[e.User.Server.Id].IsActive) { 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."); await e.Send($"Contest already running in { runningContests[e.User.Server.Id].Channell.Mention } channel.");
@ -124,15 +121,14 @@ namespace NadekoBot.Commands {
return; return;
} }
var tg = new TypingGame(e.Channel); var tg = new TypingGame(e.Channel);
runningContests.Add(e.Server.Id,tg); runningContests.Add(e.Server.Id, tg);
await tg.Start(); await tg.Start();
}; };
private Func<CommandEventArgs,Task> QuitFunc() => private Func<CommandEventArgs, Task> QuitFunc() =>
async e => { async e => {
if (runningContests.ContainsKey(e.User.Server.Id) && 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); runningContests.Remove(e.User.Server.Id);
return; return;
} }
@ -150,14 +146,16 @@ namespace NadekoBot.Commands {
cgb.CreateCommand("typeadd") cgb.CreateCommand("typeadd")
.Description("Adds a new article to the typing contest. Owner only.") .Description("Adds a new article to the typing contest. Owner only.")
.Parameter("text",ParameterType.Unparsed) .Parameter("text", ParameterType.Unparsed)
.Do(e => { .Do(async e => {
if (e.User.Id != NadekoBot.OwnerID || string.IsNullOrWhiteSpace(e.GetArg("text"))) return; if (e.User.Id != NadekoBot.OwnerID || string.IsNullOrWhiteSpace(e.GetArg("text"))) return;
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.TypingArticle { Classes.DBHandler.Instance.InsertData(new Classes._DataModels.TypingArticle {
Text = e.GetArg("text"), Text = e.GetArg("text"),
DateAdded = DateTime.Now DateAdded = DateTime.Now
}); });
await e.Send("Added new article for typing.");
}); });
//todo add user submissions //todo add user submissions

View File

@ -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`"); 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) { }
}; };
} catch (Exception ex) { } catch {
await e.Channel.SendMessage(":anger: Failed retrieving osu signature :\\"); await e.Channel.SendMessage(":anger: Failed retrieving osu signature :\\");
} }
} }

View File

@ -2,7 +2,6 @@
using System; using System;
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Parse;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Modules; using NadekoBot.Modules;
using Discord.Modules; using Discord.Modules;
@ -22,7 +21,6 @@ namespace NadekoBot {
public static string TrelloAppKey; public static string TrelloAppKey;
public static bool ForwardMessages = false; public static bool ForwardMessages = false;
public static Credentials creds; public static Credentials creds;
public static bool ParseActive = false;
static void Main() { static void Main() {
//load credentials from credentials.json //load credentials from credentials.json
@ -49,26 +47,11 @@ namespace NadekoBot {
ForwardMessages = true; ForwardMessages = true;
Console.WriteLine("Forwarding messages."); 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)) if(string.IsNullOrWhiteSpace(creds.SoundCloudClientID))
Console.WriteLine("No soundcloud Client ID found. Soundcloud streaming is disabled."); Console.WriteLine("No soundcloud Client ID found. Soundcloud streaming is disabled.");
else else
Console.WriteLine("SoundCloud streaming enabled."); 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; OwnerID = creds.OwnerID;
password = creds.Password; password = creds.Password;
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -104,14 +104,6 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Parse, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Parse.1.6.2\lib\net45\Parse.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Parse.NetFx45, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Parse.1.6.2\lib\net45\Parse.NetFx45.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath> <HintPath>..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath>
<Private>True</Private> <Private>True</Private>