<commit_before>﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;

namespace Siotrix.Discord.Statistics
{
    [Name("Information")]
    [Summary("General information command with detailed reporting.")]
    public class InfoModule : ModuleBase<SocketCommandContext>
    {
        private Process _process;

        protected override void BeforeExecute(CommandInfo info)
        {
            _process = Process.GetCurrentProcess();
        }


        private async Task<string> GetGuildIconUrl(int id)
        {
            string iconurl;

            if (id == 2)
            {
                var val = await Context.GetGuildIconUrlAsync();
                iconurl = val.Avatar;
            }
            else
            {
                var val = await SiotrixEmbedAuthorExtensions.GetSiotrixAuthorAsync();
                iconurl = val.AuthorIcon;
            }
            return iconurl;
        }

        private async Task<string> GetGuildName(int id)
        {
            string name;

            if (id == 2)
            {
                var val = await SiotrixEmbedAuthorExtensions.GetSiotrixAuthorAsync();
                name = val.AuthorName;
            }
            else
            {
                var val = await Context.GetGuildNameAsync();
                name = val.GuildName;
            }

            return name;
        }

        private async Task<string> GetGuildUrl(int id)
        {
            string url = null;

            if (id == 2)
            {
                var val = await SiotrixEmbedAuthorExtensions.GetSiotrixAuthorAsync();
                url = val.AuthorUrl;
            }
            else
            {
                var val = await Context.GetGuildUrlAsync();
                url = val.SiteUrl;
            }
            return url;
        }

        private async Task<string> GetGuildDescription(int id)
        {
            string description = null;

            if (id == 2)
            {
                var val = await SiotrixEmbedInfoExtensions.GetSiotrixInfoAsync();
                description = val.BotInfo;
            }
            else
            {
                var val = await Context.GetGuildDescriptionAsync();
                description = val.Description;
            }
            return description;
        }

        private async Task<string> GetGuildFooterIcon(int id)
        {
            string footerIcon;

            if (id == 2)
            {
                var val = await SiotrixEmbedFooterExtensions.GetSiotrixFooterAsync();
                footerIcon = val.FooterIcon;
            }
            else
            {
                var val = await Context.GetGuildFooterAsync();
                footerIcon = val.FooterIcon;
            }
            return footerIcon;
        }

        private async Task<string> GetGuildFooterText(int id)
        {
            string footerText;

            if (id == 2)
            {
                var val = await SiotrixEmbedFooterExtensions.GetSiotrixFooterAsync();
                footerText = val.FooterText;
            }
            else
            {
                var val = await Context.GetGuildFooterAsync();
                footerText = val.FooterText;
            }
            return footerText;
        }

        private bool CheckBot(SocketUser user)
        {
            if (user.IsBot)
                return true;
            return false;
        }

        private string GetUptime()
        {
            var uptime = DateTime.Now - _process.StartTime;
            string dayname = null;
            if (uptime.Days == 1)
                dayname = "day";
            else
                dayname = "days";
            return $"{uptime.Days} {dayname} {uptime.Hours} hr {uptime.Minutes} min {uptime.Seconds} sec";
        }

        private string[] GetLifeTimeMessages(SocketUser user)
        {
            var cnt = 0;
            var arr = new string[2];
            var today = DateTime.Now;
            using (var db = new LogDatabase())
            {
                try
                {
                    cnt = db.Messages.Where(p => !p.IsBot && p.AuthorId == user.Id.ToLong()).ToList().Count;
                    var lifeTime = (today - db.Messages.Where(p => p.AuthorId.Equals(user.Id.ToLong()) && !p.IsBot)
                                        .Min(m => m.CreatedAt)).TotalHours;
                    arr[0] = cnt.ToString();
                    arr[1] = Math.Round(cnt / lifeTime, 2).ToString();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return arr;
        }

        private async Task<string> GetLastMessageTime(SocketUser target)
        {
            var last = "-";
            using (var db = new LogDatabase())
            {
                try
                {
                    if (db.Messages.Where(p => !p.IsBot && p.AuthorId == target.Id.ToLong()).ToList().Count > 0)
                    {
                        /*  var date = db.Messages.Where(p => !p.IsBot && p.AuthorId == target.Id.ToLong()).Last()
                              .CreatedAt; */
                        var date = await db.Messages.Where(p => !p.IsBot && p.AuthorId == target.Id.ToLong()).OrderByDescending(x => x.CreatedAt).FirstOrDefaultAsync();
                        last = string.Format("{0:dddd, MMMM d, yyyy}", date);
                    }
                    else
                    {
                        last = "No recorded message from user in this guild.";
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return last;
        }

        private string GetActiveGuildName()<commit_msg>info last seen fix<commit_after>﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;

namespace Siotrix.Discord.Statistics
{
    [Name("Information")]
    [Summary("General information command with detailed reporting.")]
    public class InfoModule : ModuleBase<SocketCommandContext>
    {
        private Process _process;

        protected override void BeforeExecute(CommandInfo info)
        {
            _process = Process.GetCurrentProcess();
        }


        private async Task<string> GetGuildIconUrl(int id)
        {
            string iconurl;

            if (id == 2)
            {
                var val = await Context.GetGuildIconUrlAsync();
                iconurl = val.Avatar;
            }
            else
            {
                var val = await SiotrixEmbedAuthorExtensions.GetSiotrixAuthorAsync();
                iconurl = val.AuthorIcon;
            }
            return iconurl;
        }

        private async Task<string> GetGuildName(int id)
        {
            string name;

            if (id == 2)
            {
                var val = await SiotrixEmbedAuthorExtensions.GetSiotrixAuthorAsync();
                name = val.AuthorName;
            }
            else
            {
                var val = await Context.GetGuildNameAsync();
                name = val.GuildName;
            }

            return name;
        }

        private async Task<string> GetGuildUrl(int id)
        {
            string url = null;

            if (id == 2)
            {
                var val = await SiotrixEmbedAuthorExtensions.GetSiotrixAuthorAsync();
                url = val.AuthorUrl;
            }
            else
            {
                var val = await Context.GetGuildUrlAsync();
                url = val.SiteUrl;
            }
            return url;
        }

        private async Task<string> GetGuildDescription(int id)
        {
            string description = null;

            if (id == 2)
            {
                var val = await SiotrixEmbedInfoExtensions.GetSiotrixInfoAsync();
                description = val.BotInfo;
            }
            else
            {
                var val = await Context.GetGuildDescriptionAsync();
                description = val.Description;
            }
            return description;
        }

        private async Task<string> GetGuildFooterIcon(int id)
        {
            string footerIcon;

            if (id == 2)
            {
                var val = await SiotrixEmbedFooterExtensions.GetSiotrixFooterAsync();
                footerIcon = val.FooterIcon;
            }
            else
            {
                var val = await Context.GetGuildFooterAsync();
                footerIcon = val.FooterIcon;
            }
            return footerIcon;
        }

        private async Task<string> GetGuildFooterText(int id)
        {
            string footerText;

            if (id == 2)
            {
                var val = await SiotrixEmbedFooterExtensions.GetSiotrixFooterAsync();
                footerText = val.FooterText;
            }
            else
            {
                var val = await Context.GetGuildFooterAsync();
                footerText = val.FooterText;
            }
            return footerText;
        }

        private bool CheckBot(SocketUser user)
        {
            if (user.IsBot)
                return true;
            return false;
        }

        private string GetUptime()
        {
            var uptime = DateTime.Now - _process.StartTime;
            string dayname = null;
            if (uptime.Days == 1)
                dayname = "day";
            else
                dayname = "days";
            return $"{uptime.Days} {dayname} {uptime.Hours} hr {uptime.Minutes} min {uptime.Seconds} sec";
        }

        private string[] GetLifeTimeMessages(SocketUser user)
        {
            var cnt = 0;
            var arr = new string[2];
            var today = DateTime.Now;
            using (var db = new LogDatabase())
            {
                try
                {
                    cnt = db.Messages.Where(p => !p.IsBot && p.AuthorId == user.Id.ToLong()).ToList().Count;
                    var lifeTime = (today - db.Messages.Where(p => p.AuthorId.Equals(user.Id.ToLong()) && !p.IsBot)
                                        .Min(m => m.CreatedAt)).TotalHours;
                    arr[0] = cnt.ToString();
                    arr[1] = Math.Round(cnt / lifeTime, 2).ToString();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return arr;
        }

        private async Task<string> GetLastMessageTime(SocketUser target)
        {
            var last = "-";
            using (var db = new LogDatabase())
            {
                try
                {
                    if (db.Messages.Where(p => !p.IsBot && p.AuthorId == target.Id.ToLong()).ToList().Count > 0)
                    {
                        /*  var date = db.Messages.Where(p => !p.IsBot && p.AuthorId == target.Id.ToLong()).Last()
                              .CreatedAt; */
                        var date = await db.Messages.Where(p => !p.IsBot && p.AuthorId == target.Id.ToLong()).OrderByDescending(x => x.CreatedAt).FirstOrDefaultAsync();
                        last = string.Format("{0:dddd, MMMM d, yyyy}", date.CreatedAt);
                    }
                    else
                    {
                        last = "No recorded message from user in this guild.";
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return last;
        }

        private string GetActiveGuildName()
{'fraction_non_alphanumeric': 0.08902102001507411, 'fraction_numerical': 0.0023448622393434384, 'mean_word_length': 1.181187214611872, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1456666', 'n_tokens_mistral': 3127, 'n_tokens_neox': 2930, 'n_words': 666}