Skip to content

Commit

Permalink
Remove lot of unnecessary logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiao921 committed Sep 25, 2020
1 parent eb86785 commit 333b302
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 30 deletions.
1 change: 0 additions & 1 deletion CHEF/CHEF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ private async Task MainAsync()

private async Task InitOnClientReady()
{
Logger.Init();
await Task.CompletedTask;
}

Expand Down
2 changes: 1 addition & 1 deletion CHEF/Components/Commands/Cooking/Cook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public override async Task SetupAsync()
using (var context = new RecipeContext())
{
await context.Database.MigrateAsync();
Logger.Log("Done migrating recipe table.");
}

Client.MessageReceived += RecipeShortcutAsync;
Expand Down Expand Up @@ -48,6 +47,7 @@ private Task RecipeShortcutAsync(SocketMessage msg)
var guild = (msg.Channel as SocketGuildChannel)?.Guild;
await msg.Channel.SendMessageAsync(
$"**Recipe: {recipe.Name} (Owner: {recipe.RealOwnerName(guild)})**{Environment.NewLine}{recipe.Text}");
Logger.Log($"[{DateTime.UtcNow}] Recipe {recipe.Name} was executed by {msg.Author}.");
}
}
Expand Down
2 changes: 0 additions & 2 deletions CHEF/Components/Commands/Cooking/CookModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ public async Task DeleteDuplicateRecipes()

foreach (var duplicate in duplicates)
{
Logger.Log("duplicate recipe : " + duplicate.Name);
nameOfRecipesToRemove.Add(duplicate.Name);
}

Expand Down Expand Up @@ -370,7 +369,6 @@ public async Task DeleteDuplicateRecipes()

foreach (var forbidden in forbiddens)
{
Logger.Log("forbidden recipe : " + forbidden.Name);
recipesToRemove.Add(forbidden);
}

Expand Down
5 changes: 3 additions & 2 deletions CHEF/Components/ComponentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ internal static class ComponentHandler

internal static async Task Init(DiscordSocketClient client)
{
LoadedComponents.Clear();

var componentTypes = Assembly.GetExecutingAssembly().GetTypes().Where(ComponentFilter).ToList();

foreach (var componentType in componentTypes)
{
try
{
Logger.Log($"Enabling Component: {componentType.Name}");

var compInstance = (Component)Activator.CreateInstance(componentType, client);
await compInstance.SetupAsync();
LoadedComponents.Add(compInstance);
}
catch (Exception e)
{
Expand Down
5 changes: 0 additions & 5 deletions CHEF/Components/Watcher/AutoPastebin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ msg.Channel is SocketTextChannel &&
$"Automatic pastebin for {msg.Author.Username} {attachment.Filename} file: {pasteResult.FullUrl}");
return botAnswer.ToString();
}
else
{
Logger.Log(
$"Failed to make pastebin for {msg.Author.Username} {attachment.Filename}, size: {attachment.Size}. HTTP Error code {pasteResult.StatusCode}");
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions CHEF/Components/Watcher/CommonIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ public static async Task<bool> CheckModsVersion(string text, StringBuilder answe
{
var modName = match.Groups[1].ToString();
var verFromText = match.Groups[2].ToString().Replace(" ", "");
//Logger.Log("modName : " + modName);
//Logger.Log("verFromText : " + verFromText);

// todo : re-enable me when we have consistency
// todo : re-enable me for all plugins when we have consistency
// across manifest version and the version from the plugin / log

var (latestVer, isDeprecated) = await IsThisLatestModVersion(modName, verFromText);
Expand Down
13 changes: 2 additions & 11 deletions CHEF/Components/Watcher/ImageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ msg.Channel is SocketTextChannel &&
var fileType = System.IO.Path.GetExtension(attachment.Url);
if (fileType == ".png")
{
Logger.Log("Preparing a query for Yandex.");

var botAnswer = new StringBuilder();
var queryResult = await QueryYandex(attachment.Url);

Logger.Log("Checking for common log errors.");
CommonIssues.CheckCommonLogError(queryResult.ImageText, botAnswer, msg.Author);

Logger.Log("Checking for outdated mods.");
var hasOutdatedMods = await CommonIssues.CheckModsVersion(queryResult.ImageText, botAnswer, msg.Author);
if (hasOutdatedMods)
{
Expand All @@ -63,7 +59,6 @@ msg.Channel is SocketTextChannel &&
queryResult.HasModLoadingText = true;
}

Logger.Log("Checking if its a version mismatch problem");
if (queryResult.ImageText.Contains("version mismatch", StringComparison.InvariantCultureIgnoreCase) ||
queryResult.ImageText.Contains("Yours=MOD", StringComparison.InvariantCultureIgnoreCase))
{
Expand All @@ -74,7 +69,6 @@ msg.Channel is SocketTextChannel &&
return botAnswer.ToString();
}

Logger.Log("Checking if its a console image");
if (queryResult.IsAConsole())
{
botAnswer.AppendLine($"{msg.Author.Mention}, looks like you just uploaded a screenshot of a BepinEx console / log file." +
Expand All @@ -95,7 +89,6 @@ msg.Channel is SocketTextChannel &&
return botAnswer.ToString();
}

Logger.Log("Checking if its a window explorer image");
if (queryResult.IsWindowExplorer() &&
(queryResult.ImageText.Contains("bepin", StringComparison.InvariantCultureIgnoreCase) ||
queryResult.ImageText.Contains("risk of rain", StringComparison.InvariantCultureIgnoreCase)))
Expand Down Expand Up @@ -130,16 +123,14 @@ private async Task<YandexImageQuery> QueryYandex(string imageUrl)
var document = (await web.LoadFromWebAsync($"{_postUrl}{imageUrl}&rpt=imageview")).DocumentNode;
var tags = document.SelectNodes("//*[@class=\"CbirItem CbirTags\"]//*[@class=\"Button2-Text\"]");
res.AddTags(tags);
Logger.Log("Got the image tags.");

// Catch any error in case the Cloud Vision Service is
// not correctly setup : An exception will be thrown
// If the project doesnt have billing info correctly filled
try
{
var img = Image.FromUri(imageUrl);
res.AddText(CloudVisionOcr.AnnotatorClient.DetectText(img));
Logger.Log("Got the image text : " + res.ImageText);
res.AddText(await CloudVisionOcr.AnnotatorClient.DetectTextAsync(img));
}
catch (Exception e)
{
Expand All @@ -149,7 +140,7 @@ private async Task<YandexImageQuery> QueryYandex(string imageUrl)
return res;
}

public class YandexImageQuery
private class YandexImageQuery
{
private readonly List<string> _imageTags;
public string ImageText { get; private set; }
Expand Down
5 changes: 0 additions & 5 deletions CHEF/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ internal static class Logger
{
private const string LogPrefix = "[CHEF]";

internal static void Init()
{
Log("Logger Init");
}

internal static void Log(string msg)
{
var log = $"{LogPrefix} {msg}";
Expand Down

0 comments on commit 333b302

Please sign in to comment.