<commit_before>﻿using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Serilog;
using Modix.Services.AutoCodePaste;
using Modix.Services.GuildInfo;
using System;
using Microsoft.Extensions.DependencyInjection;
using Modix.Services.CommandHelp;

namespace Modix
{
    public class ModixBotHooks
    {
        public IServiceProvider ServiceProvider { get; set; }
        public ulong CurrentBotId { get; set; }

        public Task HandleLog(LogMessage message)
        {
            switch (message.Severity)
            {
                case LogSeverity.Critical:
                    Log.Error(message.Exception, message.Message ?? "An exception bubbled up: ");
                    break;
                case LogSeverity.Debug:
                    Log.Debug(message.ToString());
                    break;
                case LogSeverity.Warning:
                    Log.Warning(message.ToString());
                    break;
                case LogSeverity.Error:
                    Log.Error(message.Exception, message.Message ?? "An exception bubbled up: ");
                    break;
                case LogSeverity.Info:
                    Log.Information(message.ToString());
                    break;
                case LogSeverity.Verbose:
                    Log.Verbose(message.ToString());
                    break;
            }
            return Task.CompletedTask;
        }

        public async Task HandleAddReaction(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                //var codePaste = scope.ServiceProvider.GetRequiredService<CodePasteHandler>();
                var errorHelper = scope.ServiceProvider.GetRequiredService<CommandErrorHandler>();

                //await codePaste.ReactionAdded(message, channel, reaction);
                await errorHelper.ReactionAdded(message, channel, reaction);
            }
        }

        public async Task HandleRemoveReaction(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var codePaste = scope.ServiceProvider.GetRequiredService<CodePasteHandler>();
                var errorHelper = scope.ServiceProvider.GetRequiredService<CommandErrorHandler>();

                await codePaste.ReactionRemoved(message, channel, reaction);
                await errorHelper.ReactionRemoved(message, channel, reaction);
            }
        }

        public Task HandleUserJoined(SocketGuildUser user)
        {<commit_msg>Refactor ModixBotHooks to use a logger with more context<commit_after>﻿using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Modix.Services.AutoCodePaste;
using Modix.Services.GuildInfo;
using System;
using Microsoft.Extensions.DependencyInjection;
using Modix.Services.CommandHelp;
using Microsoft.Extensions.Logging;

namespace Modix
{
    public class ModixBotHooks
    {
        private readonly ILogger<ModixBotHooks> _log;

        public ModixBotHooks(IServiceProvider serviceProvider)
        {
            ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            _log = ServiceProvider.GetRequiredService<ILogger<ModixBotHooks>>();
        }

        public IServiceProvider ServiceProvider { get; private set; }

        public Task HandleLog(LogMessage message)
        {
            switch (message.Severity)
            {
                case LogSeverity.Critical:
                    _log.LogError(message.Exception, message.Message ?? "An exception bubbled up: ");
                    break;
                case LogSeverity.Debug:
                    _log.LogDebug(message.ToString());
                    break;
                case LogSeverity.Warning:
                    _log.LogWarning(message.ToString());
                    break;
                case LogSeverity.Error:
                    _log.LogError(message.Exception, message.Message ?? "An exception bubbled up: ");
                    break;
                case LogSeverity.Info:
                    _log.LogInformation(message.ToString());
                    break;
                case LogSeverity.Verbose:
                    _log.LogTrace(message.ToString());
                    break;
            }
            return Task.CompletedTask;
        }

        public async Task HandleAddReaction(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                //var codePaste = scope.ServiceProvider.GetRequiredService<CodePasteHandler>();
                var errorHelper = scope.ServiceProvider.GetRequiredService<CommandErrorHandler>();

                //await codePaste.ReactionAdded(message, channel, reaction);
                await errorHelper.ReactionAdded(message, channel, reaction);
            }
        }

        public async Task HandleRemoveReaction(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var codePaste = scope.ServiceProvider.GetRequiredService<CodePasteHandler>();
                var errorHelper = scope.ServiceProvider.GetRequiredService<CommandErrorHandler>();

                await codePaste.ReactionRemoved(message, channel, reaction);
                await errorHelper.ReactionRemoved(message, channel, reaction);
            }
        }

        public Task HandleUserJoined(SocketGuildUser user)
        {
{'fraction_non_alphanumeric': 0.07696289905090595, 'fraction_numerical': 0.0, 'mean_word_length': 2.036144578313253, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5293429', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1360, 'n_words': 288}