<commit_before>﻿using Discord;
using OrbisBot.Permission;
using OrbisBot.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrbisBot
{
    class Context
    {

        public DiscordClient Client { get; private set; }
        public Dictionary<string, TaskAbstract> Tasks { get; private set; }
        public ChannelPermissionsWrapper ChannelPermission { get; private set; }

        private static Context _context;

        public static Context Instance
        {
            get
            {
                //theoretically, it should not be called in this program since
                //we have initialize to do this
                if (_context == null)
                {
                    _context = new Context();
                    _context.Initalize();
                }
                return _context;
            }
        }

        private Context()
        {

        }

        private void Initalize()
        {
            Client = new DiscordClient();
            Tasks = new Dictionary<string, TaskAbstract>();
            ChannelPermission = new ChannelPermissionsWrapper();
            PopulateTaskDictionary();
            SetUpDiscordClient();
        }

        private void PopulateTaskDictionary()
        {
            Tasks.Add("!Wolfram", new WolframAlphaTask());
        }

        private void SetUpDiscordClient()
        {
            Client = new DiscordClient();

            //Display all log messages in the console
            Client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");

#pragma warning disable CS1998
            Client.MessageReceived += async (s, e) =>
#pragma warning restore CS1998
            {
                if (!e.Message.IsAuthor)
                {
                    try
                    {
                        var commandSplitted = e.Message.Text.Split(' ');
                        var command = e.Message.Text;
                        if (Context.Instance.Tasks.ContainsKey(commandSplitted[0]))
                        {
                            var task = Context.Instance.Tasks[commandSplitted[0]];
                            var args = CommandParser.ParseCommand(e.Message.Text);
                            task.RunTask(args, e);
                        }
                    }
                    catch (Exception ex)
                    {
                        await Client.SendMessage(e.Channel, string.Format("Error occurred, Exception: {0}; Message Received {1}", ex.Message, e.Message.Text));
                    }
                }
            };

            //Convert our sync method to an async one and block the Main function until the bot disconnects
            Client.Run(async () =>
            {
                //Connect to the Discord server using our email and password
                await Client.Connect("<EMAIL>", "<PASSWORD>");
            });
        }<commit_msg>fixed somethings<commit_after>﻿using Discord;
using OrbisBot.Permission;
using OrbisBot.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrbisBot
{
    class Context
    {

        public DiscordClient Client { get; private set; }
        public Dictionary<string, TaskAbstract> Tasks { get; private set; }
        public ChannelPermissionsWrapper ChannelPermission { get; private set; }

        private static Context _context;

        public static Context Instance
        {
            get
            {
                //theoretically, it should not be called in this program since
                //we have initialize to do this
                if (_context == null)
                {
                    _context = new Context();
                    _context.Initalize();
                }
                return _context;
            }
        }

        private Context()
        {

        }

        private void Initalize()
        {
            Client = new DiscordClient();
            Tasks = new Dictionary<string, TaskAbstract>();
            ChannelPermission = new ChannelPermissionsWrapper();
            PopulateTaskDictionary();
            SetUpDiscordClient();
        }

        private void PopulateTaskDictionary()
        {
            Tasks.Add("!Wolfram", new WolframAlphaTask());
        }

        private void SetUpDiscordClient()
        {
            Client = new DiscordClient();

            //Display all log messages in the console
            Client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");

#pragma warning disable CS1998
            Client.MessageReceived += async (s, e) =>
#pragma warning restore CS1998
            {
                if (!e.Message.IsAuthor)
                {
                    try
                    {
                        var commandSplitted = e.Message.Text.Split(' ');
                        var command = e.Message.Text;
                        if (Context.Instance.Tasks.ContainsKey(commandSplitted[0]))
                        {
                            var task = Context.Instance.Tasks[commandSplitted[0]];
                            var args = CommandParser.ParseCommand(e.Message.Text);
                            task.RunTask(args, e);
                        }
                    }
                    catch (Exception ex)
                    {
                        await Client.SendMessage(e.Channel, string.Format("Error occurred, Exception: {0}; Message Received {1}", ex.Message, e.Message.Text));
                    }
                }
            };

            //Convert our sync method to an async one and block the Main function until the bot disconnects
            Client.Run(async () =>
            {
                //Connect to the Discord server using our email and password
                await Client.Connect("", "");
            });
        }
{'fraction_non_alphanumeric': 0.08689839572192513, 'fraction_numerical': 0.004010695187165776, 'mean_word_length': 1.382563694267516, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '6409925', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1351, 'n_words': 382}