diff --git a/src/Evilbot.Common/Client.cs b/src/Evilbot.Common/Client.cs index 94095bc..bc92ab9 100644 --- a/src/Evilbot.Common/Client.cs +++ b/src/Evilbot.Common/Client.cs @@ -17,7 +17,6 @@ public class Client private readonly DiscordSocketClient _client; private readonly CommandService _commands; private readonly ConfigModel _config; - //private readonly LogHandler _logger; private readonly IServiceProvider _services; public Client(CommandService commands = null, ConfigModel config = null, LogHandler logger = null, PluginHandler plugins = null) @@ -40,7 +39,6 @@ public Client(CommandService commands = null, ConfigModel config = null, LogHand // Set up config and services for use in initialization _config = config ?? new ConfigHandler().GetConfig(); - //_logger = logger ?? new LogHandler(); _services = ConfigureServices(); } diff --git a/src/Evilbot.Common/Logging/ConsoleTextLogger.cs b/src/Evilbot.Common/Logging/ConsoleTextLogger.cs new file mode 100644 index 0000000..d7f2b63 --- /dev/null +++ b/src/Evilbot.Common/Logging/ConsoleTextLogger.cs @@ -0,0 +1,233 @@ +using System; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Discord.WebSocket; +using Evilbot.Common.Models; +using Evilbot.ConsoleUI; + +namespace Evilbot.Common.Logging +{ + public class ConsoleTextLogger : IEventLogger + { + private readonly ConfigModel _config; + private readonly TextLogFormatter _formatter; + + public ConsoleTextLogger() + { + _config ??= new ConfigHandler().GetConfig(); + _formatter = new TextLogFormatter(); + } + + public async Task ChannelCreated(SocketChannel channel) + { + _formatter.Log(logStyle: LogStyle.Good, message: $"Channel {channel} created"); + } + + public async Task ChannelDestroyed(SocketChannel channel) + { + _formatter.Log(logStyle: LogStyle.Good, message: $"Channel {channel} destroyed"); + } + + public async Task ChannelUpdated(SocketChannel channelBefore, SocketChannel channelAfter) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"Channel {channelBefore} updated to {channelAfter}"); + } + + public async Task Connected() + { + _formatter.Log(logStyle: LogStyle.Good, message: "Connected"); + } + + public async Task CurrentUserUpdated(SocketSelfUser userBefore, SocketSelfUser userAfter) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"User {userBefore} updated to {userAfter}"); + } + + public async Task Disconnected(Exception exception) + { + _formatter.Log(logStyle: LogStyle.Bad, message: $"Disconnected due to {exception}"); + } + + public async Task GuildAvailable(SocketGuild guild) + { + _formatter.Log(logStyle: LogStyle.Info, message: $"Guild {guild} available"); + } + + public async Task GuildMembersDownloaded(SocketGuild guild) + { + _formatter.Log(logStyle: LogStyle.Info, message: $"Guild members for {guild} downloaded"); + } + + public async Task GuildMemberUpdated(SocketGuildUser userBefore, SocketGuildUser userAfter) + { + if (userBefore.Status != userAfter.Status) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"User {userBefore} updated from {userBefore.Status} to {userAfter.Status}"); + } + + if (userBefore.Nickname != userAfter.Nickname) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"User {userBefore} updated from {userBefore.Nickname} to {userAfter.Nickname}"); + } + _formatter.Log(logStyle: LogStyle.Update, message: $"User {userBefore} updated from {userBefore.VoiceState.ToString()} to {userAfter.VoiceState.ToString()}"); + } + + public async Task GuildUnavailable(SocketGuild guild) + { + _formatter.Log(logStyle: LogStyle.Info, message: $"Guild {guild} unavailable"); + } + + public async Task GuildUpdated(SocketGuild guildBefore, SocketGuild guildAfter) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"Guild {guildBefore} updated to {guildAfter}"); + } + + public async Task JoinedGuild(SocketGuild guild) + { + _formatter.Log(logStyle: LogStyle.Good, message: $"Joined {guild}"); + } + + public async Task LatencyUpdated(int latencyBefore, int latencyAfter) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"Latency {latencyBefore} updated to {latencyAfter}"); + } + + public async Task LeftGuild(SocketGuild guild) + { + _formatter.Log(logStyle: LogStyle.Bad, message: $"Left {guild}"); + } + + public async Task Log(LogMessage logMessage) + { + _formatter.Log(LogStyle.Info, logMessage: logMessage); + } + + public async Task LoggedIn() + { + _formatter.Log(logStyle: LogStyle.Good, message: "Logged In"); + } + + public async Task LoggedOut() + { + _formatter.Log(logStyle: LogStyle.Bad, message: "Logged Out"); + } + + public async Task MessageDeleted(Cacheable cacheMessage, ISocketMessageChannel channel) + { + _formatter.Log(logStyle: LogStyle.Info, message: $"Message '{cacheMessage.Value}' deleted from #{channel}"); + } + + public async Task MessageReceived(SocketMessage message) + { + _formatter.Log(logStyle: LogStyle.Info, message: $"Message '{message}' received in #{message.Channel}"); + } + + public async Task MessageUpdated(Cacheable cacheMessageBefore, SocketMessage messageAfter, ISocketMessageChannel channel) + { + _formatter.Log(logStyle: LogStyle.Update, message: $"Message updated from '{cacheMessageBefore.Value}' to '{messageAfter}' in #{channel}"); + } + + public async Task ReactionAdded(Cacheable cacheMessage, ISocketMessageChannel channel, SocketReaction reaction) + { + } + + public async Task ReactionRemoved(Cacheable cacheMessage, ISocketMessageChannel channel, SocketReaction reaction) + { + } + + public async Task ReactionsCleared(Cacheable cacheMessage, ISocketMessageChannel channel) + { + } + + public async Task Ready() + { + } + + public async Task RecipientAdded(SocketGroupUser user) + { + } + + public async Task RecipientRemoved(SocketGroupUser user) + { + } + + public async Task RoleCreated(SocketRole role) + { + } + + public async Task RoleDeleted(SocketRole role) + { + } + + public async Task RoleUpdated(SocketRole roleBefore, SocketRole roleAfter) + { + } + + public async Task UserBanned(SocketUser user, SocketGuild guild) + { + } + + public async Task UserIsTyping(SocketUser user, ISocketMessageChannel channel) + { + } + + public async Task UserJoined(SocketGuildUser user) + { + } + + public async Task UserLeft(SocketGuildUser user) + { + } + + public async Task UserUnbanned(SocketUser user, SocketGuild guild) + { + } + + public async Task UserUpdated(SocketUser oldUser, SocketUser newUser) + { + } + + public async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState voiceStateBefore, SocketVoiceState voiceStateAfter) + { + } + + public async Task CommandLog(LogMessage logMessage) + { + _formatter.Log(logStyle: LogStyle.Update, logMessage: logMessage); + + } + + public async Task CommandExecuted(Optional command, ICommandContext context, IResult result) + { + // Command failed. Notify user and log to console + if (!result.IsSuccess) + { + var cleanResult = ResultCleaner($"{result}"); + + if (command.IsSpecified) + { + await context.Channel.SendMessageAsync(embed: EmbedHandler.Alert(cleanResult)); + _formatter.Log(logStyle: LogStyle.Alert, message: $"[Command Error] {context.User.Username}#{context.User.Discriminator} used {_config.Prefix}{command.Value.Name} in {context.Guild.Name}: #{context.Channel.Name} ({cleanResult})"); + } + else + { + await context.Channel.SendMessageAsync(embed: EmbedHandler.Bad(ResultCleaner($"{result}"))); + _formatter.Log(logStyle: LogStyle.Bad, message: $"[Command Fail] {context.User.Username}#{context.User.Discriminator} used unknown command in {context.Guild.Name}: #{context.Channel.Name} ({cleanResult})"); + } + return; + } + + // Command succeeded. Log to console + _formatter.Log(logStyle: LogStyle.Good, message: $"[Command Success] {context.User.Username}#{context.User.Discriminator} used .{command.Value.Name} in {context.Guild.Name}: #{context.Channel.Name}"); + return; + } + + private string ResultCleaner(string result) + { + var indexOfSpace = $"{result}".IndexOf(' '); + var substringResult = $"{result}".Substring(indexOfSpace + 1); + return substringResult.Remove(substringResult.Length - 1); + } + } +} \ No newline at end of file diff --git a/src/Evilbot.Common/Logging/DiscordEmbedLogger.cs b/src/Evilbot.Common/Logging/DiscordEmbedLogger.cs new file mode 100644 index 0000000..498b0a1 --- /dev/null +++ b/src/Evilbot.Common/Logging/DiscordEmbedLogger.cs @@ -0,0 +1,7 @@ +namespace Evilbot.Common.Logging +{ + public class DiscordEmbedLogger : IEventLogger + { + + } +} \ No newline at end of file diff --git a/src/Evilbot.Common/Logging/DiscordTextLogger.cs b/src/Evilbot.Common/Logging/DiscordTextLogger.cs new file mode 100644 index 0000000..8549269 --- /dev/null +++ b/src/Evilbot.Common/Logging/DiscordTextLogger.cs @@ -0,0 +1,7 @@ +namespace Evilbot.Common.Logging +{ + public class DiscordTextLogger : IEventLogger + { + + } +} \ No newline at end of file diff --git a/src/Evilbot.Common/Logging/FileTextLogger.cs b/src/Evilbot.Common/Logging/FileTextLogger.cs new file mode 100644 index 0000000..282fca3 --- /dev/null +++ b/src/Evilbot.Common/Logging/FileTextLogger.cs @@ -0,0 +1,7 @@ +namespace Evilbot.Common.Logging +{ + public class FileTextLogger : IEventLogger + { + + } +} \ No newline at end of file diff --git a/src/Evilbot.Common/Logging/IEventLogger.cs b/src/Evilbot.Common/Logging/IEventLogger.cs index 74998cf..213acc3 100644 --- a/src/Evilbot.Common/Logging/IEventLogger.cs +++ b/src/Evilbot.Common/Logging/IEventLogger.cs @@ -1,9 +1,163 @@ +using System; +using System.Threading.Tasks; using Discord; +using Discord.Commands; +using Discord.WebSocket; namespace Evilbot.Common.Logging { public interface IEventLogger { - void Log(LogStyle logStyle, string message = null, LogMessage logMessage = new LogMessage()); + public async Task ChannelCreated(SocketChannel channel) + { + } + + public async Task ChannelDestroyed(SocketChannel channel) + { + } + + public async Task ChannelUpdated(SocketChannel channelBefore, SocketChannel channelAfter) + { + } + + public async Task Connected() + { + } + + public async Task CurrentUserUpdated(SocketSelfUser userBefore, SocketSelfUser userAfter) + { + } + + public async Task Disconnected(Exception exception) + { + } + + public async Task GuildAvailable(SocketGuild guild) + { + } + + public async Task GuildMembersDownloaded(SocketGuild guild) + { + } + + public async Task GuildMemberUpdated(SocketGuildUser userBefore, SocketGuildUser userAfter) + { + } + + public async Task GuildUnavailable(SocketGuild guild) + { + } + + public async Task GuildUpdated(SocketGuild guildBefore, SocketGuild guildAfter) + { + } + + public async Task JoinedGuild(SocketGuild guild) + { + } + + public async Task LatencyUpdated(int latencyBefore, int latencyAfter) + { + } + + public async Task LeftGuild(SocketGuild guild) + { + } + + public async Task Log(LogMessage logMessage) + { + } + + public async Task LoggedIn() + { + } + + public async Task LoggedOut() + { + } + + public async Task MessageDeleted(Cacheable cacheMessage, ISocketMessageChannel channel) + { + } + + public async Task MessageReceived(SocketMessage message) + { + } + + public async Task MessageUpdated(Cacheable cacheMessageBefore, SocketMessage messageAfter, ISocketMessageChannel channel) + { + } + + public async Task ReactionAdded(Cacheable cacheMessage, ISocketMessageChannel channel, SocketReaction reaction) + { + } + + public async Task ReactionRemoved(Cacheable cacheMessage, ISocketMessageChannel channel, SocketReaction reaction) + { + } + + public async Task ReactionsCleared(Cacheable cacheMessage, ISocketMessageChannel channel) + { + } + + public async Task Ready() + { + } + + public async Task RecipientAdded(SocketGroupUser user) + { + } + + public async Task RecipientRemoved(SocketGroupUser user) + { + } + + public async Task RoleCreated(SocketRole role) + { + } + + public async Task RoleDeleted(SocketRole role) + { + } + + public async Task RoleUpdated(SocketRole roleBefore, SocketRole roleAfter) + { + } + + public async Task UserBanned(SocketUser user, SocketGuild guild) + { + } + + public async Task UserIsTyping(SocketUser user, ISocketMessageChannel channel) + { + } + + public async Task UserJoined(SocketGuildUser user) + { + } + + public async Task UserLeft(SocketGuildUser user) + { + } + + public async Task UserUnbanned(SocketUser user, SocketGuild guild) + { + } + + public async Task UserUpdated(SocketUser oldUser, SocketUser newUser) + { + } + + public async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState voiceStateBefore, SocketVoiceState voiceStateAfter) + { + } + + public async Task CommandLog(LogMessage logMessage) + { + } + + public async Task CommandExecuted(Optional command, ICommandContext context, IResult result) + { + } } } \ No newline at end of file diff --git a/src/Evilbot.Common/Logging/LogHandler.cs b/src/Evilbot.Common/Logging/LogHandler.cs index 92dcb38..3b3a0c7 100644 --- a/src/Evilbot.Common/Logging/LogHandler.cs +++ b/src/Evilbot.Common/Logging/LogHandler.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Discord; @@ -9,267 +10,63 @@ namespace Evilbot.Common.Logging { - public partial class LogHandler + public class LogHandler { private readonly DiscordSocketClient _client; private readonly CommandService _commands; - private readonly ConfigModel _config; - private readonly IEventLogger _consoleLogger; + private readonly List _loggers; public LogHandler(DiscordSocketClient client, CommandService commands) { _client = client; _commands = commands; - _config ??= new ConfigHandler().GetConfig(); - _consoleLogger = new ConsoleLogger(); + _loggers = new List(); + _loggers.Add(new ConsoleTextLogger()); } public async Task InitializeAsync() { - _client.ChannelCreated += ChannelCreated; - _client.ChannelDestroyed += ChannelDestroyed; - _client.ChannelUpdated += ChannelUpdated; - _client.Connected += Connected; - _client.CurrentUserUpdated += CurrentUserUpdated; - _client.Disconnected += Disconnected; - _client.GuildAvailable += GuildAvailable; - _client.GuildMembersDownloaded += GuildMembersDownloaded; - _client.GuildMemberUpdated += GuildMemberUpdated; - _client.GuildUnavailable += GuildUnavailable; - _client.GuildUpdated += GuildUpdated; - _client.JoinedGuild += JoinedGuild; - _client.LatencyUpdated += LatencyUpdated; - _client.LeftGuild += LeftGuild; - _client.Log += Log; - _client.LoggedIn += LoggedIn; - _client.LoggedOut += LoggedOut; - _client.MessageDeleted += MessageDeleted; - _client.MessageReceived += MessageReceived; - _client.MessageUpdated += MessageUpdated; - _client.ReactionAdded += ReactionAdded; - _client.ReactionRemoved += ReactionRemoved; - _client.ReactionsCleared += ReactionsCleared; - _client.Ready += Ready; - _client.RecipientAdded += RecipientAdded; - _client.RecipientRemoved += RecipientRemoved; - _client.RoleCreated += RoleCreated; - _client.RoleDeleted += RoleDeleted; - _client.RoleUpdated += RoleUpdated; - _client.UserBanned += UserBanned; - _client.UserIsTyping += UserIsTyping; - _client.UserJoined += UserJoined; - _client.UserLeft += UserLeft; - _client.UserUnbanned += UserUnbanned; - _client.UserUpdated += UserUpdated; - _client.UserVoiceStateUpdated += UserVoiceStateUpdated; - - _commands.Log += CommandLog; - _commands.CommandExecuted += CommandExecuted; - } - - private async Task ChannelCreated(SocketChannel channel) - { - _consoleLogger.Log(logStyle: LogStyle.Good, message: $"Channel {channel} created"); - } - - private async Task ChannelDestroyed(SocketChannel channel) - { - _consoleLogger.Log(logStyle: LogStyle.Good, message: $"Channel {channel} destroyed"); - } - - private async Task ChannelUpdated(SocketChannel channelBefore, SocketChannel channelAfter) - { - _consoleLogger.Log(logStyle: LogStyle.Update, message: $"Channel {channelBefore} updated to {channelAfter}"); - } - - private async Task Connected() - { - _consoleLogger.Log(logStyle: LogStyle.Good, message: "Connected"); - } - - private async Task CurrentUserUpdated(SocketSelfUser userBefore, SocketSelfUser userAfter) - { - _consoleLogger.Log(logStyle: LogStyle.Update, message: $"User {userBefore} updated to {userAfter}"); - } - - private async Task Disconnected(Exception exception) - { - _consoleLogger.Log(logStyle: LogStyle.Bad, message: $"Disconnected due to {exception}"); - } - - private async Task GuildAvailable(SocketGuild guild) - { - _consoleLogger.Log(logStyle: LogStyle.Info, message: $"Guild {guild} available"); - } - - private async Task GuildMembersDownloaded(SocketGuild guild) - { - _consoleLogger.Log(logStyle: LogStyle.Info, message: $"Guild members for {guild} downloaded"); - } - - private async Task GuildMemberUpdated(SocketGuildUser userBefore, SocketGuildUser userAfter) - { - _consoleLogger.Log(logStyle: LogStyle.Update, message: $"User {userBefore} updated to {userAfter}"); - if (userBefore.Activity.ToString() != "Rider" && userAfter.Activity.ToString() == "Rider") - { - Console.WriteLine($"Add Coding Now! role to {userAfter}"); - } - if (userBefore.Activity.ToString() == "Rider" && userAfter.Activity.ToString() != "Rider") - { - Console.WriteLine($"Removing Coding Now! role from {userAfter}"); - } - } - - private async Task GuildUnavailable(SocketGuild guild) - { - _consoleLogger.Log(logStyle: LogStyle.Info, message: $"Guild {guild} unavailable"); - } - - private async Task GuildUpdated(SocketGuild guildBefore, SocketGuild guildAfter) - { - _consoleLogger.Log(logStyle: LogStyle.Update, message: $"Guild {guildBefore} updated to {guildAfter}"); - } - - private async Task JoinedGuild(SocketGuild guild) - { - _consoleLogger.Log(logStyle: LogStyle.Good, message: $"Joined {guild}"); - } - - private async Task LatencyUpdated(int latencyBefore, int latencyAfter) - { - _consoleLogger.Log(logStyle: LogStyle.Update, message: $"Latency {latencyBefore} updated to {latencyAfter}"); - } - - private async Task LeftGuild(SocketGuild guild) - { - _consoleLogger.Log(logStyle: LogStyle.Bad, message: $"Left {guild}"); - } - - private async Task Log(LogMessage logMessage) - { - _consoleLogger.Log(LogStyle.Info, logMessage: logMessage); - } - - private async Task LoggedIn() - { - } - - private async Task LoggedOut() - { - } - - private async Task MessageDeleted(Cacheable cacheMessage, ISocketMessageChannel channel) - { - } - - private async Task MessageReceived(SocketMessage message) - { - } - - private async Task MessageUpdated(Cacheable cacheMessageBefore, SocketMessage messageAfter, ISocketMessageChannel channel) - { - } - - private async Task ReactionAdded(Cacheable cacheMessage, ISocketMessageChannel channel, SocketReaction reaction) - { - } - - private async Task ReactionRemoved(Cacheable cacheMessage, ISocketMessageChannel channel, SocketReaction reaction) - { - } - - private async Task ReactionsCleared(Cacheable cacheMessage, ISocketMessageChannel channel) - { - } - - private async Task Ready() - { - } - - private async Task RecipientAdded(SocketGroupUser user) - { - } - - private async Task RecipientRemoved(SocketGroupUser user) - { - } - - private async Task RoleCreated(SocketRole role) - { - } - - private async Task RoleDeleted(SocketRole role) - { - } - - private async Task RoleUpdated(SocketRole roleBefore, SocketRole roleAfter) - { - } - - private async Task UserBanned(SocketUser user, SocketGuild guild) - { - } - - private async Task UserIsTyping(SocketUser user, ISocketMessageChannel channel) - { - } - - private async Task UserJoined(SocketGuildUser user) - { - } - - private async Task UserLeft(SocketGuildUser user) - { - } - - private async Task UserUnbanned(SocketUser user, SocketGuild guild) - { - } - - private async Task UserUpdated(SocketUser oldUser, SocketUser newUser) - { - } - - private async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState voiceStateBefore, SocketVoiceState voiceStateAfter) - { - } - - private async Task CommandLog(LogMessage logMessage) - { - _consoleLogger.Log(logStyle: LogStyle.Update, logMessage: logMessage); - - } - - private async Task CommandExecuted(Optional command, ICommandContext context, IResult result) - { - // Command failed. Notify user and log to console - if (!result.IsSuccess) + foreach (var logger in _loggers) { - var cleanResult = ResultCleaner($"{result}"); - - if (command.IsSpecified) - { - await context.Channel.SendMessageAsync(embed: EmbedHandler.Alert(cleanResult)); - _consoleLogger.Log(logStyle: LogStyle.Alert, message: $"[Command Error] {context.User.Username}#{context.User.Discriminator} used {_config.Prefix}{command.Value.Name} in {context.Guild.Name}: #{context.Channel.Name} ({cleanResult})"); - } - else - { - await context.Channel.SendMessageAsync(embed: EmbedHandler.Bad(ResultCleaner($"{result}"))); - _consoleLogger.Log(logStyle: LogStyle.Bad, message: $"[Command Fail] {context.User.Username}#{context.User.Discriminator} used unknown command in {context.Guild.Name}: #{context.Channel.Name} ({cleanResult})"); - } - return; + _client.ChannelCreated += logger.ChannelCreated; + _client.ChannelDestroyed += logger.ChannelDestroyed; + _client.ChannelUpdated += logger.ChannelUpdated; + _client.Connected += logger.Connected; + _client.CurrentUserUpdated += logger.CurrentUserUpdated; + _client.Disconnected += logger.Disconnected; + _client.GuildAvailable += logger.GuildAvailable; + _client.GuildMembersDownloaded += logger.GuildMembersDownloaded; + _client.GuildMemberUpdated += logger.GuildMemberUpdated; + _client.GuildUnavailable += logger.GuildUnavailable; + _client.GuildUpdated += logger.GuildUpdated; + _client.JoinedGuild += logger.JoinedGuild; + _client.LatencyUpdated += logger.LatencyUpdated; + _client.LeftGuild += logger.LeftGuild; + _client.Log += logger.Log; + _client.LoggedIn += logger.LoggedIn; + _client.LoggedOut += logger.LoggedOut; + _client.MessageDeleted += logger.MessageDeleted; + _client.MessageReceived += logger.MessageReceived; + _client.MessageUpdated += logger.MessageUpdated; + _client.ReactionAdded += logger.ReactionAdded; + _client.ReactionRemoved += logger.ReactionRemoved; + _client.ReactionsCleared += logger.ReactionsCleared; + _client.Ready += logger.Ready; + _client.RecipientAdded += logger.RecipientAdded; + _client.RecipientRemoved += logger.RecipientRemoved; + _client.RoleCreated += logger.RoleCreated; + _client.RoleDeleted += logger.RoleDeleted; + _client.RoleUpdated += logger.RoleUpdated; + _client.UserBanned += logger.UserBanned; + _client.UserIsTyping += logger.UserIsTyping; + _client.UserJoined += logger.UserJoined; + _client.UserLeft += logger.UserLeft; + _client.UserUnbanned += logger.UserUnbanned; + _client.UserUpdated += logger.UserUpdated; + _client.UserVoiceStateUpdated += logger.UserVoiceStateUpdated; + _commands.Log += logger.CommandLog; + _commands.CommandExecuted += logger.CommandExecuted; } - - // Command succeeded. Log to console - _consoleLogger.Log(logStyle: LogStyle.Good, message: $"[Command Success] {context.User.Username}#{context.User.Discriminator} used .{command.Value.Name} in {context.Guild.Name}: #{context.Channel.Name}"); - return; - } - - private string ResultCleaner(string result) - { - var indexOfSpace = $"{result}".IndexOf(' '); - var substringResult = $"{result}".Substring(indexOfSpace + 1); - return substringResult.Remove(substringResult.Length - 1); } } } \ No newline at end of file diff --git a/src/Evilbot.Common/Logging/ConsoleLogger.cs b/src/Evilbot.Common/Logging/TextLogFormatter.cs similarity index 78% rename from src/Evilbot.Common/Logging/ConsoleLogger.cs rename to src/Evilbot.Common/Logging/TextLogFormatter.cs index 8827c2d..45c4a40 100644 --- a/src/Evilbot.Common/Logging/ConsoleLogger.cs +++ b/src/Evilbot.Common/Logging/TextLogFormatter.cs @@ -5,7 +5,7 @@ namespace Evilbot.Common.Logging { - public class ConsoleLogger : IEventLogger + public class TextLogFormatter { public void Log(LogStyle logStyle, string message = null, LogMessage logMessage = new LogMessage()) { @@ -18,10 +18,24 @@ public void Log(LogStyle logStyle, string message = null, LogMessage logMessage LogStyle.Update => ConsoleColor.Magenta, _ => ConsoleColor.Gray }; + + var style = logStyle switch + { + LogStyle.Good => "Good", + LogStyle.Bad => "Bad", + LogStyle.Info => "Info", + LogStyle.Alert => "Alert", + LogStyle.Update => "Update", + _ => "Neutral" + }; + if (message != null) { Console.Write($"[{DateTime.Now:dd/M/yyyy HH:mm:ss}]"); + Console.ForegroundColor = color; + Console.Write($" [{style}]"); + Console.ResetColor(); Console.WriteLine($" {message}"); return; }