Cleanup, .parsetosql will merge parse data from data/parsedata to sql
This commit is contained in:
parent
f61606f8bc
commit
2d52d18847
@ -31,6 +31,16 @@ namespace NadekoBot.Classes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void InsertMany<T>(T objects) where T : IEnumerable<IDataModel> {
|
||||||
|
try {
|
||||||
|
using (var _conn = new SQLiteConnection(_filePath)) {
|
||||||
|
_conn.InsertAll(objects);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal void UpdateData<T>(T o) where T : IDataModel {
|
internal void UpdateData<T>(T o) where T : IDataModel {
|
||||||
using (var _conn = new SQLiteConnection(_filePath)) {
|
using (var _conn = new SQLiteConnection(_filePath)) {
|
||||||
_conn.Update(o, typeof(T));
|
_conn.Update(o, typeof(T));
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using SQLite;
|
using Newtonsoft.Json;
|
||||||
|
using SQLite;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -10,12 +11,15 @@ namespace NadekoBot.Classes._DataModels {
|
|||||||
public long ServerId { get; set; } = 0;
|
public long ServerId { get; set; } = 0;
|
||||||
public bool Greet { get; set; } = false;
|
public bool Greet { get; set; } = false;
|
||||||
public bool GreetPM { get; set; } = false;
|
public bool GreetPM { get; set; } = false;
|
||||||
|
[JsonProperty("greetChannel")]
|
||||||
public long GreetChannelId { get; set; } = 0;
|
public long GreetChannelId { get; set; } = 0;
|
||||||
public string GreetText { get; set; } = "Welcome %user%!";
|
public string GreetText { get; set; } = "Welcome %user%!";
|
||||||
public bool Bye { get; set; } = false;
|
public bool Bye { get; set; } = false;
|
||||||
public bool ByePM { get; set; } = false;
|
public bool ByePM { get; set; } = false;
|
||||||
|
[JsonProperty("byeChannel")]
|
||||||
public long ByeChannelId { get; set; } = 0;
|
public long ByeChannelId { get; set; } = 0;
|
||||||
public string ByeText { get; set; } = "%user% has left the server.";
|
public string ByeText { get; set; } = "%user% has left the server.";
|
||||||
|
[JsonProperty("createdAt")]
|
||||||
public DateTime DateAdded { get; set; } = DateTime.Now;
|
public DateTime DateAdded { get; set; } = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ namespace NadekoBot.Classes._DataModels {
|
|||||||
public long ChannelId { get; set; }
|
public long ChannelId { get; set; }
|
||||||
public string ChannelName { get; set; }
|
public string ChannelName { get; set; }
|
||||||
public string CommandName { get; set; }
|
public string CommandName { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonProperty("createdAt")]
|
||||||
public DateTime DateAdded { get; set; }
|
public DateTime DateAdded { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@ namespace NadekoBot.Classes._DataModels {
|
|||||||
public long UserId { get; set; }
|
public long UserId { get; set; }
|
||||||
public string ServerName { get; set; }
|
public string ServerName { get; set; }
|
||||||
public long ServerId { get; set; }
|
public long ServerId { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonProperty("Request")]
|
||||||
public string RequestText { get; set; }
|
public string RequestText { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonProperty("createdAt")]
|
||||||
public DateTime DateAdded { get; set; }
|
public DateTime DateAdded { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ namespace NadekoBot.Classes._DataModels {
|
|||||||
public int OnlineUsers { get; set; }
|
public int OnlineUsers { get; set; }
|
||||||
public TimeSpan Uptime { get; set; }
|
public TimeSpan Uptime { get; set; }
|
||||||
public int RealOnlineUsers { get; set; }
|
public int RealOnlineUsers { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonProperty("createdAt")]
|
||||||
public DateTime DateAdded { get; set; }
|
public DateTime DateAdded { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using SQLite;
|
using Newtonsoft.Json;
|
||||||
|
using SQLite;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -8,6 +9,7 @@ using System.Threading.Tasks;
|
|||||||
namespace NadekoBot.Classes._DataModels {
|
namespace NadekoBot.Classes._DataModels {
|
||||||
class TypingArticle : IDataModel {
|
class TypingArticle : IDataModel {
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
[JsonProperty("createdAt")]
|
||||||
public DateTime DateAdded { get; set; }
|
public DateTime DateAdded { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ namespace NadekoBot.Commands {
|
|||||||
DateAdded = DateTime.Now
|
DateAdded = DateTime.Now
|
||||||
});
|
});
|
||||||
|
|
||||||
await e.Send("Added new article for typing.");
|
await e.Send("Added new article for typing game.");
|
||||||
});
|
});
|
||||||
|
|
||||||
//todo add user submissions
|
//todo add user submissions
|
||||||
|
@ -10,15 +10,15 @@ using System.Threading.Tasks;
|
|||||||
using NadekoBot.Commands;
|
using NadekoBot.Commands;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NadekoBot.Classes._DataModels;
|
||||||
|
|
||||||
namespace NadekoBot.Modules {
|
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) {
|
||||||
@ -443,6 +443,7 @@ namespace NadekoBot.Modules {
|
|||||||
clearDictionary.TryRemove(e.Server, out throwaway);
|
clearDictionary.TryRemove(e.Server, out throwaway);
|
||||||
});
|
});
|
||||||
cgb.CreateCommand(".newname")
|
cgb.CreateCommand(".newname")
|
||||||
|
.Alias(".setname")
|
||||||
.Description("Give the bot a new name.")
|
.Description("Give the bot a new name.")
|
||||||
.Parameter("new_name", ParameterType.Unparsed)
|
.Parameter("new_name", ParameterType.Unparsed)
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
@ -549,6 +550,21 @@ namespace NadekoBot.Modules {
|
|||||||
}
|
}
|
||||||
await e.Channel.Send(send);
|
await e.Channel.Send(send);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand(".parsetosql")
|
||||||
|
.Description("Loads exported parsedata from /data/parsedata/ into sqlite database.")
|
||||||
|
.Do(async e => {
|
||||||
|
if (e.User.Id != NadekoBot.OwnerID)
|
||||||
|
return;
|
||||||
|
await Task.Run(() => {
|
||||||
|
SaveParseToDb<Announcement>("data/parsedata/Announcements.json");
|
||||||
|
SaveParseToDb<Classes._DataModels.Command>("data/parsedata/CommandsRan.json");
|
||||||
|
SaveParseToDb<Request>("data/parsedata/Requests.json");
|
||||||
|
SaveParseToDb<Stats>("data/parsedata/Stats.json");
|
||||||
|
SaveParseToDb<TypingArticle>("data/parsedata/TypingArticles.json");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/*cgb.CreateCommand(".voicetext")
|
/*cgb.CreateCommand(".voicetext")
|
||||||
.Description("Enabled or disabled voice to text channel connection. Only people in a certain voice channel will see ")
|
.Description("Enabled or disabled voice to text channel connection. Only people in a certain voice channel will see ")
|
||||||
|
|
||||||
@ -583,5 +599,15 @@ namespace NadekoBot.Modules {
|
|||||||
*/
|
*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SaveParseToDb<T>(string where) where T : IDataModel {
|
||||||
|
var data = File.ReadAllText(where);
|
||||||
|
var arr = JObject.Parse(data)["results"] as JArray;
|
||||||
|
var objects = new List<T>();
|
||||||
|
foreach (JObject obj in arr) {
|
||||||
|
objects.Add(obj.ToObject<T>());
|
||||||
|
}
|
||||||
|
Classes.DBHandler.Instance.InsertMany(objects);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,7 @@ 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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user