ready for prod :D

This commit is contained in:
dboerlage 2017-04-18 14:08:56 +02:00
parent 5f437d74ea
commit f52893e696
No known key found for this signature in database
GPG key ID: BDA07B7D3FCF147F
5 changed files with 34 additions and 11 deletions

View file

@ -10,6 +10,9 @@
<PackageReference Include="Google.Apis.YouTube.v3">
<Version>1.25.0.760</Version>
</PackageReference>
<PackageReference Include="HtmlAgilityPack.NetCore">
<Version>1.5.0.1</Version>
</PackageReference>
<PackageReference Include="RestSharp.NetCore">
<Version>105.2.4-rc4-24214-01</Version>
</PackageReference>

View file

@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
using Geekbot.net.Modules;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Geekbot.net.Lib
{
@ -12,5 +16,25 @@ namespace Geekbot.net.Lib
// ToDO: Check settings file, if invalid, reconfig it
// Console.WriteLine(Path.GetFullPath("./settings.json"));
}
public static void ParseOldDatabase(string path)
{
Console.WriteLine("Starting Database Conversion...");
path = Path.GetFullPath(path);
Console.WriteLine($"Old db location: {path}");
var redis = new RedisClient().Client;
Console.WriteLine("Connected to Redis...");
var allfiles = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories);
foreach ( var file in allfiles)
{
var info = new FileInfo(file);
if (info.Name.StartsWith("-")) continue;
Console.WriteLine(info.FullName);
dynamic json = JObject.Parse(File.ReadAllText(file));
var key = info.Name.Substring(0, info.Name.Length - 5) + "-messages";
Console.WriteLine($"{key} - {json.messages}");
redis.StringSet(key, json.messages.ToString());
}
}
}
}

View file

@ -9,7 +9,6 @@ namespace Geekbot.net.Modules
public class CatClient : ICatClient
{
//Manage a restClient
public CatClient()
{
Client = new RestClient("http://random.cat");

View file

@ -15,7 +15,7 @@ namespace Geekbot.net.Lib
try
{
var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
Client = redis.GetDatabase();
Client = redis.GetDatabase(6);
}
catch (Exception)
{

View file

@ -1,6 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Discord;
@ -8,7 +6,6 @@ using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Modules;
using StackExchange.Redis;
namespace Geekbot.net
{
@ -30,6 +27,11 @@ namespace Geekbot.net
Console.WriteLine("Starting...");
//Task.WaitAll(BootTasks.CheckSettingsFile());
if (args.Length == 2 && args[0] == "--parse-db")
{
BootTasks.ParseOldDatabase(args[1]);
Environment.Exit(1);
}
Task.WaitAll(new Program().MainAsync());
}
@ -54,7 +56,7 @@ namespace Geekbot.net
map = new DependencyMap();
map.Add<ICatClient>(new CatClient());
map.Add<IRedisClient>(redis);
map.Add(redis);
await InstallCommands();
Console.WriteLine("Connecting to Discord...");
@ -116,11 +118,6 @@ namespace Geekbot.net
public async Task HandleUserJoined(SocketGuildUser user)
{
// var list = Directory.EnumerateFiles("", "", SearchOption.AllDirectories).ToList();
// foreach (var file in list)
// {
//
// }
if (!user.IsBot)
{
var message = redis.Client.StringGet(user.Guild.Id + "-welcomeMsg");