commit
0078de8a7f
9 changed files with 150 additions and 64 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,3 +7,5 @@ Backup/
|
||||||
UpgradeLog.htm
|
UpgradeLog.htm
|
||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
Geekbot.net/Logs/*
|
||||||
|
!/Geekbot.net/Logs/.keep
|
||||||
|
|
|
@ -13,9 +13,7 @@
|
||||||
<PackageReference Include="Discord.Net">
|
<PackageReference Include="Discord.Net">
|
||||||
<Version>1.0.2</Version>
|
<Version>1.0.2</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Google.Apis.YouTube.v3">
|
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.29.1.991" />
|
||||||
<Version>1.29.1.976</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="HtmlAgilityPack.NetCore">
|
<PackageReference Include="HtmlAgilityPack.NetCore">
|
||||||
<Version>1.5.0.1</Version>
|
<Version>1.5.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
@ -23,15 +21,14 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||||
<PackageReference Include="RestSharp.NetCore">
|
<PackageReference Include="Serilog" Version="2.6.0-dev-00894" />
|
||||||
<Version>105.2.3</Version>
|
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
|
||||||
</PackageReference>
|
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.1-dev-00044" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
|
||||||
<PackageReference Include="StackExchange.Redis">
|
<PackageReference Include="StackExchange.Redis">
|
||||||
<Version>1.2.6</Version>
|
<Version>1.2.6</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="System.Net.Http">
|
<PackageReference Include="System.Net.Http" Version="4.3.3" />
|
||||||
<Version>4.3.2</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
|
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Runtime.Serialization.Json">
|
<PackageReference Include="System.Runtime.Serialization.Json">
|
||||||
<Version>4.3.0</Version>
|
<Version>4.3.0</Version>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib
|
namespace Geekbot.net.Lib
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,7 @@ namespace Geekbot.net.Lib
|
||||||
private readonly Random rnd;
|
private readonly Random rnd;
|
||||||
private readonly int totalCheckEmImages;
|
private readonly int totalCheckEmImages;
|
||||||
|
|
||||||
public CheckEmImageProvider(Random rnd)
|
public CheckEmImageProvider(Random rnd, ILogger logger)
|
||||||
{
|
{
|
||||||
var path = Path.GetFullPath("./Storage/checkEmPics");
|
var path = Path.GetFullPath("./Storage/checkEmPics");
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
@ -18,12 +19,12 @@ namespace Geekbot.net.Lib
|
||||||
checkEmImageArray = rawCheckEmPics.Split("\n");
|
checkEmImageArray = rawCheckEmPics.Split("\n");
|
||||||
totalCheckEmImages = checkEmImageArray.Length;
|
totalCheckEmImages = checkEmImageArray.Length;
|
||||||
this.rnd = rnd;
|
this.rnd = rnd;
|
||||||
Console.WriteLine($"-- Loaded {totalCheckEmImages} CheckEm Images");
|
logger.Information($"[Geekbot] [CheckEm] Loaded {totalCheckEmImages} CheckEm Images");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("checkEmPics File not found");
|
logger.Error("checkEmPics File not found");
|
||||||
Console.WriteLine($"Path should be {path}");
|
logger.Error($"Path should be {path}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
32
Geekbot.net/Lib/ErrorHandler.cs
Normal file
32
Geekbot.net/Lib/ErrorHandler.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using System;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Lib
|
||||||
|
{
|
||||||
|
public class ErrorHandler : IErrorHandler
|
||||||
|
{
|
||||||
|
private readonly ILogger logger;
|
||||||
|
// private readonly IDMChannel botOwnerDmChannel;
|
||||||
|
|
||||||
|
public ErrorHandler(ILogger logger /*, IDMChannel botOwnerDmChannel*/)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
// this.botOwnerDmChannel = botOwnerDmChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void HandleCommandException(Exception e, ICommandContext Context)
|
||||||
|
{
|
||||||
|
var errorMsg =
|
||||||
|
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\"";
|
||||||
|
logger.Error(e, errorMsg);
|
||||||
|
// await botOwnerDmChannel.SendMessageAsync($"{errorMsg}```{e.StackTrace}```");
|
||||||
|
// await Context.Channel.SendMessageAsync("Something went wrong...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IErrorHandler
|
||||||
|
{
|
||||||
|
void HandleCommandException(Exception e, ICommandContext Context);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib
|
namespace Geekbot.net.Lib
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,7 @@ namespace Geekbot.net.Lib
|
||||||
private readonly Random rnd;
|
private readonly Random rnd;
|
||||||
private readonly int totalFortunes;
|
private readonly int totalFortunes;
|
||||||
|
|
||||||
public FortunesProvider(Random rnd)
|
public FortunesProvider(Random rnd, ILogger logger)
|
||||||
{
|
{
|
||||||
var path = Path.GetFullPath("./Storage/fortunes");
|
var path = Path.GetFullPath("./Storage/fortunes");
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
@ -18,12 +19,12 @@ namespace Geekbot.net.Lib
|
||||||
fortuneArray = rawFortunes.Split("%");
|
fortuneArray = rawFortunes.Split("%");
|
||||||
totalFortunes = fortuneArray.Length;
|
totalFortunes = fortuneArray.Length;
|
||||||
this.rnd = rnd;
|
this.rnd = rnd;
|
||||||
Console.WriteLine($"-- Loaded {totalFortunes} Fortunes");
|
logger.Information($"[Geekbot] [Fortunes] Loaded {totalFortunes} Fortunes");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Fortunes File not found");
|
logger.Error("Fortunes File not found");
|
||||||
Console.WriteLine($"Path should be {path}");
|
logger.Error($"Path should be {path}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib
|
namespace Geekbot.net.Lib
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,7 @@ namespace Geekbot.net.Lib
|
||||||
private readonly Random rnd;
|
private readonly Random rnd;
|
||||||
private readonly int totalPandas;
|
private readonly int totalPandas;
|
||||||
|
|
||||||
public PandaProvider(Random rnd)
|
public PandaProvider(Random rnd, ILogger logger)
|
||||||
{
|
{
|
||||||
var path = Path.GetFullPath("./Storage/pandas");
|
var path = Path.GetFullPath("./Storage/pandas");
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
@ -18,12 +19,12 @@ namespace Geekbot.net.Lib
|
||||||
PandaArray = rawFortunes.Split("\n");
|
PandaArray = rawFortunes.Split("\n");
|
||||||
totalPandas = PandaArray.Length;
|
totalPandas = PandaArray.Length;
|
||||||
this.rnd = rnd;
|
this.rnd = rnd;
|
||||||
Console.WriteLine($"-- Loaded {totalPandas} Panda Images");
|
logger.Information($"[Geekbot] [Pandas] Loaded {totalPandas} Panda Images");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Pandas File not found");
|
logger.Error("Pandas File not found");
|
||||||
Console.WriteLine($"Path should be {path}");
|
logger.Error($"Path should be {path}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ namespace Geekbot.net.Lib
|
||||||
return PandaArray[rnd.Next(0, totalPandas)];
|
return PandaArray[rnd.Next(0, totalPandas)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IPandaProvider
|
public interface IPandaProvider
|
||||||
{
|
{
|
||||||
string GetRandomPanda();
|
string GetRandomPanda();
|
||||||
|
|
0
Geekbot.net/Logs/.keep
Executable file
0
Geekbot.net/Logs/.keep
Executable file
|
@ -4,6 +4,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Geekbot.net.Modules
|
namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
|
@ -11,11 +12,15 @@ namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
private readonly ICheckEmImageProvider checkEmImages;
|
private readonly ICheckEmImageProvider checkEmImages;
|
||||||
private readonly Random rnd;
|
private readonly Random rnd;
|
||||||
|
private readonly ILogger logger;
|
||||||
|
private readonly IErrorHandler errorHandler;
|
||||||
|
|
||||||
public CheckEm(Random RandomClient, ICheckEmImageProvider checkEmImages)
|
public CheckEm(Random RandomClient, ICheckEmImageProvider checkEmImages, ILogger logger, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
rnd = RandomClient;
|
this.rnd = RandomClient;
|
||||||
this.checkEmImages = checkEmImages;
|
this.checkEmImages = checkEmImages;
|
||||||
|
this.logger = logger;
|
||||||
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("checkem", RunMode = RunMode.Async)]
|
[Command("checkem", RunMode = RunMode.Async)]
|
||||||
|
@ -50,7 +55,7 @@ namespace Geekbot.net.Modules
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e.Message);
|
errorHandler.HandleCommandException(e, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Serilog;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
namespace Geekbot.net
|
namespace Geekbot.net
|
||||||
|
@ -19,36 +20,50 @@ namespace Geekbot.net
|
||||||
private IServiceCollection services;
|
private IServiceCollection services;
|
||||||
private IServiceProvider servicesProvider;
|
private IServiceProvider servicesProvider;
|
||||||
private RedisValue token;
|
private RedisValue token;
|
||||||
|
private ILogger logger;
|
||||||
|
private ulong botOwnerId;
|
||||||
|
|
||||||
private static void Main()
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____");
|
var logger = new LoggerConfiguration()
|
||||||
Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
.MinimumLevel.Debug()
|
||||||
Console.WriteLine(@"| | _| _| | _| | ' /| _ \| | | || |");
|
.WriteTo.LiterateConsole()
|
||||||
Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
|
.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true)
|
||||||
Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
.CreateLogger();
|
||||||
Console.WriteLine("=========================================");
|
|
||||||
Console.WriteLine("* Starting...");
|
|
||||||
|
|
||||||
new Program().MainAsync().GetAwaiter().GetResult();
|
var logo = new StringBuilder();
|
||||||
|
logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____");
|
||||||
|
logo.AppendLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
||||||
|
logo.AppendLine(@"| | _| _| | _| | ' /| _ \| | | || |");
|
||||||
|
logo.AppendLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
|
||||||
|
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||||
|
logo.AppendLine("=========================================");
|
||||||
|
Console.WriteLine(logo.ToString());
|
||||||
|
logger.Information("[Geekbot] Starting...");
|
||||||
|
new Program().MainAsync(logger).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task MainAsync()
|
private async Task MainAsync(ILogger logger)
|
||||||
{
|
{
|
||||||
Console.WriteLine("* Initing Stuff");
|
this.logger = logger;
|
||||||
|
logger.Information("[Geekbot] Initing Stuff");
|
||||||
client = new DiscordSocketClient();
|
|
||||||
|
client = new DiscordSocketClient(new DiscordSocketConfig
|
||||||
|
{
|
||||||
|
LogLevel = LogSeverity.Verbose
|
||||||
|
});
|
||||||
|
client.Log += DiscordLogger;
|
||||||
commands = new CommandService();
|
commands = new CommandService();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var redisMultiplexer = ConnectionMultiplexer.Connect("127.0.0.1:6379");
|
var redisMultiplexer = ConnectionMultiplexer.Connect("127.0.0.1:6379");
|
||||||
redis = redisMultiplexer.GetDatabase(6);
|
redis = redisMultiplexer.GetDatabase(6);
|
||||||
Console.WriteLine("-- Connected to Redis (db6)");
|
logger.Information($"[Redis] Connected to db {redis.Database}");
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Start Redis pls...");
|
logger.Information("Start Redis pls...");
|
||||||
Environment.Exit(102);
|
Environment.Exit(102);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,31 +74,39 @@ namespace Geekbot.net
|
||||||
var newToken = Console.ReadLine();
|
var newToken = Console.ReadLine();
|
||||||
redis.StringSet("discordToken", newToken);
|
redis.StringSet("discordToken", newToken);
|
||||||
token = newToken;
|
token = newToken;
|
||||||
|
|
||||||
Console.Write("Bot Owner User ID: ");
|
|
||||||
var ownerId = Console.ReadLine();
|
|
||||||
redis.StringSet("botOwner", ownerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var botOwner = redis.StringGet("botOwner");
|
||||||
|
if (botOwner.IsNullOrEmpty)
|
||||||
|
{
|
||||||
|
Console.Write("Bot Owner User ID: ");
|
||||||
|
botOwner = Console.ReadLine();
|
||||||
|
redis.StringSet("botOwner", botOwner);
|
||||||
|
}
|
||||||
|
botOwnerId = (ulong) botOwner;
|
||||||
|
|
||||||
services = new ServiceCollection();
|
services = new ServiceCollection();
|
||||||
var RandomClient = new Random();
|
var RandomClient = new Random();
|
||||||
var fortunes = new FortunesProvider(RandomClient);
|
var fortunes = new FortunesProvider(RandomClient, logger);
|
||||||
var checkEmImages = new CheckEmImageProvider(RandomClient);
|
var checkEmImages = new CheckEmImageProvider(RandomClient, logger);
|
||||||
var pandaImages = new PandaProvider(RandomClient);
|
var pandaImages = new PandaProvider(RandomClient, logger);
|
||||||
|
IErrorHandler errorHandler = new ErrorHandler(logger);
|
||||||
|
services.AddSingleton<IErrorHandler>(errorHandler);
|
||||||
services.AddSingleton(redis);
|
services.AddSingleton(redis);
|
||||||
services.AddSingleton(RandomClient);
|
services.AddSingleton(RandomClient);
|
||||||
|
services.AddSingleton<ILogger>(logger);
|
||||||
services.AddSingleton<IFortunesProvider>(fortunes);
|
services.AddSingleton<IFortunesProvider>(fortunes);
|
||||||
services.AddSingleton<ICheckEmImageProvider>(checkEmImages);
|
services.AddSingleton<ICheckEmImageProvider>(checkEmImages);
|
||||||
services.AddSingleton<IPandaProvider>(pandaImages);
|
services.AddSingleton<IPandaProvider>(pandaImages);
|
||||||
|
|
||||||
Console.WriteLine("* Connecting to Discord");
|
logger.Information("[Geekbot] Connecting to Discord");
|
||||||
|
|
||||||
await Login();
|
await Login();
|
||||||
|
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Login()
|
private async Task Login()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -93,35 +116,34 @@ namespace Geekbot.net
|
||||||
if (isConneted)
|
if (isConneted)
|
||||||
{
|
{
|
||||||
await client.SetGameAsync("Ping Pong");
|
await client.SetGameAsync("Ping Pong");
|
||||||
Console.WriteLine($"* Now Connected to {client.Guilds.Count} Servers");
|
logger.Information($"[Geekbot] Now Connected to {client.Guilds.Count} Servers");
|
||||||
|
|
||||||
Console.WriteLine("* Registering Stuff");
|
logger.Information("[Geekbot] Registering Stuff");
|
||||||
|
|
||||||
client.MessageReceived += HandleCommand;
|
client.MessageReceived += HandleCommand;
|
||||||
client.MessageReceived += HandleMessageReceived;
|
client.MessageReceived += HandleMessageReceived;
|
||||||
client.UserJoined += HandleUserJoined;
|
client.UserJoined += HandleUserJoined;
|
||||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||||
services.AddSingleton(commands);
|
services.AddSingleton(commands);
|
||||||
servicesProvider = services.BuildServiceProvider();
|
this.servicesProvider = services.BuildServiceProvider();
|
||||||
|
logger.Information("[Geekbot] Done and ready for use\n");
|
||||||
Console.WriteLine("* Done and ready for use\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (AggregateException)
|
catch (AggregateException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Could not connect to discord...");
|
logger.Information("Could not connect to discord...");
|
||||||
Environment.Exit(103);
|
Environment.Exit(103);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> isConnected()
|
private async Task<bool> isConnected()
|
||||||
{
|
{
|
||||||
while (!client.ConnectionState.Equals(ConnectionState.Connected))
|
while (!client.ConnectionState.Equals(ConnectionState.Connected))
|
||||||
await Task.Delay(25);
|
await Task.Delay(25);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleCommand(SocketMessage messageParam)
|
private async Task HandleCommand(SocketMessage messageParam)
|
||||||
{
|
{
|
||||||
var message = messageParam as SocketUserMessage;
|
var message = messageParam as SocketUserMessage;
|
||||||
if (message == null) return;
|
if (message == null) return;
|
||||||
|
@ -144,24 +166,23 @@ namespace Geekbot.net
|
||||||
var commandExec = commands.ExecuteAsync(context, argPos, servicesProvider);
|
var commandExec = commands.ExecuteAsync(context, argPos, servicesProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleMessageReceived(SocketMessage messsageParam)
|
private async Task HandleMessageReceived(SocketMessage messsageParam)
|
||||||
{
|
{
|
||||||
var message = messsageParam;
|
var message = messsageParam;
|
||||||
if (message == null) return;
|
if (message == null) return;
|
||||||
|
|
||||||
var statsRecorder = new StatsRecorder(message, redis);
|
var statsRecorder = new StatsRecorder(message, redis);
|
||||||
var userRec = statsRecorder.UpdateUserRecordAsync();
|
var userRec = statsRecorder.UpdateUserRecordAsync();
|
||||||
var guildRec = statsRecorder.UpdateGuildRecordAsync();
|
var guildRec = statsRecorder.UpdateGuildRecordAsync();
|
||||||
|
|
||||||
if (message.Author.Id == client.CurrentUser.Id) return;
|
if (message.Author.Id == client.CurrentUser.Id) return;
|
||||||
var channel = (SocketGuildChannel) message.Channel;
|
var channel = (SocketGuildChannel) message.Channel;
|
||||||
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " +
|
logger.Information($"[Message] {channel.Guild.Name} - {message.Channel} - {message.Author.Username} - {message.Content}");
|
||||||
message.Content);
|
|
||||||
await userRec;
|
await userRec;
|
||||||
await guildRec;
|
await guildRec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleUserJoined(SocketGuildUser user)
|
private async Task HandleUserJoined(SocketGuildUser user)
|
||||||
{
|
{
|
||||||
if (!user.IsBot)
|
if (!user.IsBot)
|
||||||
{
|
{
|
||||||
|
@ -173,5 +194,31 @@ namespace Geekbot.net
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task DiscordLogger(LogMessage message)
|
||||||
|
{
|
||||||
|
var logMessage = $"[{message.Source}] {message.Message}";
|
||||||
|
switch (message.Severity)
|
||||||
|
{
|
||||||
|
case LogSeverity.Verbose:
|
||||||
|
logger.Verbose(logMessage);
|
||||||
|
break;
|
||||||
|
case LogSeverity.Debug:
|
||||||
|
logger.Debug(logMessage);
|
||||||
|
break;
|
||||||
|
case LogSeverity.Info:
|
||||||
|
logger.Information(logMessage);
|
||||||
|
break;
|
||||||
|
case LogSeverity.Critical:
|
||||||
|
case LogSeverity.Error:
|
||||||
|
case LogSeverity.Warning:
|
||||||
|
logger.Error(message.Exception, logMessage);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logger.Information($"{logMessage} --- {message.Severity.ToString()}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue