<commit_before>﻿using System;
using System.Dynamic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.ComTypes;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.Net;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using SoraBot_v2.Data;
using SoraBot_v2.Services;

namespace SoraBot_v2
{
    public class CommandHandler
    {
        public static double MessagesReceived;
        public static int CommandsExecuted;

        private IServiceProvider _services;
        private readonly DiscordSocketClient _client;
        private readonly CommandService _commands;
        private readonly AfkService _afkService;
        private StarboardService _starboardService;
        private readonly RatelimitingService _ratelimitingService;
        private SelfAssignableRolesService _selfAssignableRolesService;
        private AnnouncementService _announcementService;
        private ModService _modService;
        private readonly GuildCountUpdaterService _guildCount;

        private async Task ClientOnJoinedGuild(SocketGuild socketGuild)
        {
            //Notify discordbots that we joined a new guild :P
            try
            {
                await _guildCount.UpdateCount(_client.Guilds.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            using (var soraContext = new SoraContext())
            {
                var guild = Utility.GetOrCreateGuild(socketGuild.Id, soraContext);

                //AUTO CREATE SORA ADMIN ROLE
                //var created = await Utility.CreateSoraRoleOnJoinAsync(socketGuild, _client, soraContext).ConfigureAwait(false);
                /*
                if (created)
                {
                    guild.RestrictTags = socketGuild.MemberCount > 100;
                }*/
                await soraContext.SaveChangesAsync();
                try
                {
                    string prefix = Utility.GetGuildPrefix(socketGuild, soraContext);
                    await (await socketGuild.Owner.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback(Utility.BlueInfoEmbed, Utility.SuccessLevelEmoji[3], $"Hello there (≧∇≦)/")
                        .WithDescription($"I'm glad you invited me over :)\n" +
                                         $"You can find the [list of commands and help here](http://git.argus.moe/serenity/SoraBot-v2/wikis/home)\n" +
                                         $"To restrict tag creation and Sora's mod functions you must create\n" +
                                         $"a {Utility.SORA_ADMIN_ROLE_NAME} Role so that only the ones carrying it can create\n" +
                                         $"tags or use Sora's mod functionality. You can make him create one with: " +
                                         $"`{prefix}createAdmin`\n" +
                                         $"You can leave tag creation unrestricted if you want but its not\n" +
                                         $"recommended on larger servers as it will be spammed.\n" +
                                         $"PS: Standard Prefix is `$` but you can change it with:\n" +
                                         $"`@Sora prefix yourPrefix`\n").WithThumbnailUrl(socketGuild.IconUrl ?? Utility.StandardDiscordAvatar).AddField("Support", $"You can find the [support guild here]({Utility.DISCORD_INVITE})"));

                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            //inform me of joining
            await SentryService.SendMessage($"**JOINED GUILD**\nName: {socketGuild.Name}\nID: {socketGuild.Id}\nUsers: {socketGuild.MemberCount}\nOwner: {Utility.GiveUsernameDiscrimComb(socketGuild.Owner)}");
            //TODO WELCOME MESSAGE
        }

        public CommandHandler(IServiceProvider provider, DiscordSocketClient client, CommandService commandService,
            AfkService afkService, RatelimitingService ratelimitingService, StarboardService starboardService, SelfAssignableRolesService selfService, AnnouncementService announcementService,
            ModService modService, GuildCountUpdaterService guildUpdate, ExpService expService)
        {
            _client = client;
            _commands = commandService;
            _afkService = afkService;
            _services = provider;
            _ratelimitingService = ratelimitingService;
            _starboardService = starboardService;
            _selfAssignableRolesService = selfService;
            _announcementService = announcementService;
            _modService = modService;<commit_msg>Edited welcome message to include dashboard bcs otherwise no one will ever fucking know<commit_after>﻿using System;
using System.Dynamic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.ComTypes;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.Net;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using SoraBot_v2.Data;
using SoraBot_v2.Services;

namespace SoraBot_v2
{
    public class CommandHandler
    {
        public static double MessagesReceived;
        public static int CommandsExecuted;

        private IServiceProvider _services;
        private readonly DiscordSocketClient _client;
        private readonly CommandService _commands;
        private readonly AfkService _afkService;
        private StarboardService _starboardService;
        private readonly RatelimitingService _ratelimitingService;
        private SelfAssignableRolesService _selfAssignableRolesService;
        private AnnouncementService _announcementService;
        private ModService _modService;
        private readonly GuildCountUpdaterService _guildCount;

        private async Task ClientOnJoinedGuild(SocketGuild socketGuild)
        {
            //Notify discordbots that we joined a new guild :P
            try
            {
                await _guildCount.UpdateCount(_client.Guilds.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            using (var soraContext = new SoraContext())
            {
                var guild = Utility.GetOrCreateGuild(socketGuild.Id, soraContext);

                //AUTO CREATE SORA ADMIN ROLE
                //var created = await Utility.CreateSoraRoleOnJoinAsync(socketGuild, _client, soraContext).ConfigureAwait(false);
                /*
                if (created)
                {
                    guild.RestrictTags = socketGuild.MemberCount > 100;
                }*/
                await soraContext.SaveChangesAsync();
                try
                {
                    string prefix = Utility.GetGuildPrefix(socketGuild, soraContext);
                    await (await socketGuild.Owner.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback(Utility.BlueInfoEmbed, Utility.SuccessLevelEmoji[3], $"Hello there (≧∇≦)/")
                        .WithDescription($"I'm glad you invited me over :)\n" +
                                         $"You can find the [list of commands and help here](http://git.argus.moe/serenity/SoraBot-v2/wikis/home)\n" +
                                         $"To restrict tag creation and Sora's mod functions you must create\n" +
                                         $"a {Utility.SORA_ADMIN_ROLE_NAME} Role so that only the ones carrying it can create\n" +
                                         $"tags or use Sora's mod functionality. You can make him create one with: " +
                                         $"`{prefix}createAdmin`\n" +
                                         $"You can leave tag creation unrestricted if you want but its not\n" +
                                         $"recommended on larger servers as it will be spammed.\n" +
                                         $"**Sora now has a Dashboard**\n" +
                                         $"You can [find the dashboard here](http://argonaut.pw/Sora/) by clicking the login\n"+
                                         $"button in the top right. It's still in pre-alpha but allows you to\n"+
                                         $"customize levels and level rewards as well as other settings. It is required\n" + 
                                         $"for proper setup of leveling.\n"+
                                         $"PS: Standard Prefix is `$` but you can change it with:\n" +
                                         $"`@Sora prefix yourPrefix`\n").WithThumbnailUrl(socketGuild.IconUrl ?? Utility.StandardDiscordAvatar).AddField("Support", $"You can find the [support guild here]({Utility.DISCORD_INVITE})"));

                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            //inform me of joining
            await SentryService.SendMessage($"**JOINED GUILD**\nName: {socketGuild.Name}\nID: {socketGuild.Id}\nUsers: {socketGuild.MemberCount}\nOwner: {Utility.GiveUsernameDiscrimComb(socketGuild.Owner)}");
            //TODO WELCOME MESSAGE
        }

        public CommandHandler(IServiceProvider provider, DiscordSocketClient client, CommandService commandService,
            AfkService afkService, RatelimitingService ratelimitingService, StarboardService starboardService, SelfAssignableRolesService selfService, AnnouncementService announcementService,
            ModService modService, GuildCountUpdaterService guildUpdate, ExpService expService)
        {
            _client = client;
            _commands = commandService;
            _afkService = afkService;
            _services = provider;
            _ratelimitingService = ratelimitingService;
            _starboardService = starboardService;
            _selfAssignableRolesService = selfService;
            _announcementService = announcementService;
            _modService = modService;
{'fraction_non_alphanumeric': 0.07186678352322524, 'fraction_numerical': 0.0021423702405297495, 'mean_word_length': 1.9613610149942329, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7574737', 'n_tokens_mistral': 2566, 'n_tokens_neox': 2464, 'n_words': 644}