Cleanup, tried to make parse optional

This commit is contained in:
Master Kwoth 2016-02-04 19:02:08 +01:00
parent 3b66f8106a
commit 4fce93c5cf
8 changed files with 39 additions and 62 deletions

1
.gitignore vendored
View File

@ -25,6 +25,7 @@ obj/
!**/Bin/Debug/WebSocket4Net.dll !**/Bin/Debug/WebSocket4Net.dll
!**/Bin/Debug/data/* !**/Bin/Debug/data/*
!**/Bin/Debug/data/ !**/Bin/Debug/data/
Tests/
# NuGet Packages # NuGet Packages
*.nupkg *.nupkg

View File

@ -72,17 +72,23 @@ namespace NadekoBot
private async Task StartCollecting() { private async Task StartCollecting() {
while (true) { while (true) {
await Task.Delay(new TimeSpan(1, 0, 0));
try {
var obj = new ParseObject("Stats"); var obj = new ParseObject("Stats");
obj["OnlineUsers"] = NadekoBot.client.Servers.Sum(x => x.Users.Count()); obj["OnlineUsers"] = await Task.Run(() => NadekoBot.client.Servers.Sum(x => x.Users.Count()));
obj["ConnectedServers"] = NadekoBot.client.Servers.Count(); obj["ConnectedServers"] = NadekoBot.client.Servers.Count();
obj.SaveAsync(); await obj.SaveAsync();
await Task.Delay(new TimeSpan(1, 0, 0)); } catch (Exception) {
Console.WriteLine("Parse exception in StartCollecting");
break;
}
} }
} }
//todo - batch save this //todo - batch save this
private void StatsCollector_RanCommand(object sender, CommandEventArgs e) private void StatsCollector_RanCommand(object sender, CommandEventArgs e)
{ {
try {
_commandsRan++; _commandsRan++;
var obj = new ParseObject("CommandsRan"); var obj = new ParseObject("CommandsRan");
@ -97,6 +103,9 @@ namespace NadekoBot
obj["CommandName"] = e.Command.Text; obj["CommandName"] = e.Command.Text;
obj.SaveAsync(); obj.SaveAsync();
} catch (Exception) {
Console.WriteLine("Parse error in ran command.");
}
} }
} }
} }

View File

@ -1,39 +0,0 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Classes
{
/// <summary>
/// Shit parser. I used this to convert shit-format to json format
/// </summary>
class SParser
{
public static void DoShitParse() {
string[] lines = File.ReadAllLines("questions.txt");
JArray qs = new JArray();
foreach (var line in lines)
{
if (!line.Contains(";")) continue;
JObject j = new JObject();
if (line.Contains(":"))
{
j["Category"] = line.Substring(0, line.LastIndexOf(":"));
j["Question"] = line.Substring(line.LastIndexOf(":") + 1, line.LastIndexOf(";") - line.LastIndexOf(":") - 1);
}
else {
j["Question"] = line.Substring(0, line.LastIndexOf(";"));
}
j["Answer"] = line.Substring(line.LastIndexOf(";") + 1, line.Length - line.LastIndexOf(";") - 1).Trim();
qs.Add(j);
}
File.WriteAllText("questions2.txt", qs.ToString());
}
}
}

View File

@ -14,7 +14,10 @@ namespace NadekoBot.Modules {
class Administration : DiscordModule { class Administration : DiscordModule {
public Administration() : base() { public Administration() : base() {
commands.Add(new HelpCommand()); commands.Add(new HelpCommand());
if(NadekoBot.ParseActive)
commands.Add(new ServerGreetCommand()); commands.Add(new ServerGreetCommand());
else
Console.WriteLine("Parse not active. Server greet disabled.");
} }
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager) {

View File

@ -20,7 +20,10 @@ namespace NadekoBot.Modules {
private string firestr = "🔥 ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้ 🔥"; private string firestr = "🔥 ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้ 🔥";
public Conversations() : base() { public Conversations() : base() {
commands.Add(new CopyCommand()); commands.Add(new CopyCommand());
if(NadekoBot.ParseActive)
commands.Add(new RequestsCommand()); commands.Add(new RequestsCommand());
else
Console.WriteLine("Requests don't work, parse not valid.");
} }
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager) {

View File

@ -59,7 +59,7 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("q") cgb.CreateCommand("q")
.Alias("yq") .Alias("yq")
.Description("Queue a song using keywords or link. **You must be in a voice channel**.\n**Usage**: `!m q Dream Of Venice`") .Description("Queue a song using keywords or link. Bot will join your voice channel. **You must be in a voice channel**.\n**Usage**: `!m q Dream Of Venice`")
.Parameter("query", ParameterType.Unparsed) .Parameter("query", ParameterType.Unparsed)
.Do(async e => await QueueSong(e,e.GetArg("query"))); .Do(async e => await QueueSong(e,e.GetArg("query")));

View File

@ -21,6 +21,7 @@ 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,9 +50,9 @@ namespace NadekoBot {
} }
if (string.IsNullOrWhiteSpace(creds.ParseID) || string.IsNullOrWhiteSpace(creds.ParseKey)) { if (string.IsNullOrWhiteSpace(creds.ParseID) || string.IsNullOrWhiteSpace(creds.ParseKey)) {
Console.WriteLine("Parse key and/or ID not found. Those are mandatory."); Console.WriteLine("Parse key and/or ID not found. Those are mandatory.");
Console.ReadKey(); ParseActive = false;
return; } else ParseActive = true;
}
if(string.IsNullOrWhiteSpace(creds.OsuApiKey)) if(string.IsNullOrWhiteSpace(creds.OsuApiKey))
Console.WriteLine("No osu API key found. Osu functionality is disabled."); Console.WriteLine("No osu API key found. Osu functionality is disabled.");
else else

View File

@ -138,7 +138,6 @@
<Compile Include="Classes\Music\StreamRequest.cs" /> <Compile Include="Classes\Music\StreamRequest.cs" />
<Compile Include="Classes\Music\SoundCloud.cs" /> <Compile Include="Classes\Music\SoundCloud.cs" />
<Compile Include="Commands\TriviaCommand.cs" /> <Compile Include="Commands\TriviaCommand.cs" />
<Compile Include="Classes\SParser.cs" />
<Compile Include="Classes\Trivia\TriviaGame.cs" /> <Compile Include="Classes\Trivia\TriviaGame.cs" />
<Compile Include="Classes\Trivia\TriviaQuestion.cs" /> <Compile Include="Classes\Trivia\TriviaQuestion.cs" />
<Compile Include="Classes\Trivia\TriviaQuestionPool.cs" /> <Compile Include="Classes\Trivia\TriviaQuestionPool.cs" />