Skip to content

Commit

Permalink
Removed PrintExceptionToLog method
Browse files Browse the repository at this point in the history
  • Loading branch information
MythicalCuddles committed Jan 20, 2020
1 parent 5afd889 commit be448e4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
6 changes: 3 additions & 3 deletions DiscordBot/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static bool IsUserIgnoredByBot(this IUser user)
return User.Load(user.Id).IsBotIgnoringUser;
}

public static void AwardEXPToUser(this IUser user, SocketGuild guild, int exp = 1)
public static async void AwardEXPToUser(this IUser user, SocketGuild guild, int exp = 1)
{
if (user.IsBot)
{
Expand All @@ -117,7 +117,7 @@ public static void AwardEXPToUser(this IUser user, SocketGuild guild, int exp =
}
catch (Exception e)
{
ConsoleHandler.PrintExceptionToLog("UserExtensions", e);
await new LogMessage(LogSeverity.Warning, "UserExtensions", e.Message).PrintToConsole();
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ public static async Task AttemptLevelUp(this IUser user, SocketGuild guild)
}
catch (Exception e)
{
ConsoleHandler.PrintExceptionToLog("UserExtensions", e);
await new LogMessage(LogSeverity.Warning, "UserExtensions", e.Message).PrintToConsole();
}
}
}
Expand Down
37 changes: 33 additions & 4 deletions DiscordBot/Handlers/ConsoleHandler.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
using System;
using System.Threading.Tasks;
using Discord;
using DiscordBot.Extensions;

namespace DiscordBot.Handlers
{
public static class ConsoleHandler
{
private const LogSeverity ExceptionSeverity = LogSeverity.Error; // For overloading methods below to handle multiple exceptions.

public static void PrintExceptionToLog(string source, Exception e)
internal static Task Log(LogMessage logMessage)
{
new LogMessage(ExceptionSeverity, source, e.Message);
// NOTE: The extension .PrintToConsole uses method so do not change it!
var cc = Console.ForegroundColor;
switch (logMessage.Severity)
{
case LogSeverity.Critical:
case LogSeverity.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;

case LogSeverity.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;

case LogSeverity.Info:
Console.ForegroundColor = ConsoleColor.White;
break;

case LogSeverity.Verbose:
case LogSeverity.Debug:
Console.ForegroundColor = ConsoleColor.DarkGray;
break;

default:
Console.ForegroundColor = ConsoleColor.Blue;
break;
}
Console.WriteLine($@"{DateTime.Now,-19} [{logMessage.Severity,8}] {logMessage.Source}: {logMessage.Message}");
Console.ForegroundColor = cc;
return Task.CompletedTask;
// EON
}
}
}
2 changes: 1 addition & 1 deletion DiscordBot/Modules/Mod/EmbedModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ await ReplyAsync(Context.User.Mention + ", you have entered an invalid value. Yo
}
catch (Exception e)
{
ConsoleHandler.PrintExceptionToLog("EmbedModule", e);
await new LogMessage(LogSeverity.Warning, "EmbedModule", e.Message).PrintToConsole();
await ReplyAsync("An unexpected error has happened. Please ensure that you have passed through a byte value! (A number between 0 and 255)");
return;
}
Expand Down
1 change: 1 addition & 0 deletions DiscordBot/Modules/Mod/ModeratorModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using DiscordBot.Common;
using DiscordBot.Exceptions;
using DiscordBot.Extensions;
using DiscordBot.Handlers;
using DiscordBot.Logging;

namespace DiscordBot.Modules.Mod
Expand Down
2 changes: 1 addition & 1 deletion DiscordBot/Modules/Mod/ShowConfigModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task ShowGuildConfig()
{
await ReplyAsync(
"It appears that your Guild Configuration has not been set-up completely. Please complete all the steps before using this command.");
ConsoleHandler.PrintExceptionToLog("ShowConfigModule", e);
await new LogMessage(LogSeverity.Warning, "ShowConfigModule", e.Message).PrintToConsole();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DiscordBot/Modules/Public/ProfileModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ await ReplyAsync(Context.User.Mention + ", you have entered an invalid value. Yo
}
catch (Exception e)
{
ConsoleHandler.PrintExceptionToLog("ProfileModule/CustomRGB", e);
await new LogMessage(LogSeverity.Warning, "ProfileModule", e.Message).PrintToConsole();
await ReplyAsync("An unexpected error has happened. Please ensure that you have passed through a byte value! (A number between 0 and 255)");
return;
}
Expand Down

0 comments on commit be448e4

Please sign in to comment.