<commit_before>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Newtonsoft.Json;

namespace Modix.Modules
{
    public class Result
    {
        public object ReturnValue { get; set; }
        public string Exception { get; set; }
        public string Code { get; set; }
        public string ExceptionType { get; set; }
        public TimeSpan ExecutionTime { get; set; }
    }

    public class ReplModule : ModuleBase
    {
        private const string ReplRemoteUrl =
            "http://csharpdiscordfn.azurewebsites.net/api/EvalTrigger?code=MGx5t5RZ6mmmy1jhVZ1amrWr8S3nPyCzG6bTR1mYbwULdhfuq86Ckg==";

        [Command("exec", RunMode = RunMode.Async), Summary("Executes code!")]
        public async Task ReplInvoke([Remainder] string code)
        {
            string cleanCode = code.Replace("```csharp", "").Replace("```", "");

            var client = new HttpClient();
            var res = await client.PostAsync(ReplRemoteUrl, new StringContent(cleanCode));

            if (res.StatusCode == HttpStatusCode.Forbidden)
            {
                await ReplyAsync("Exec failed: You used a forbidden class. <@144084036036329472>");
                return;
            }

            if (!res.IsSuccessStatusCode & res.StatusCode != HttpStatusCode.BadRequest)
            {
                await ReplyAsync("Exec failed: " + res.StatusCode);
                return;
            }

            var parsedResult = JsonConvert.DeserializeObject<Result>(await res.Content.ReadAsStringAsync());

            var embed = new EmbedBuilder()
               .WithTitle("Eval Result")
               .WithDescription(string.IsNullOrEmpty(parsedResult.Exception) ? "Successful" : $"Failed: {parsedResult.ExceptionType} - {parsedResult.Exception}")
               .WithColor(string.IsNullOrEmpty(parsedResult.Exception) ? new Color(0, 255, 0) : new Color(255, 0, 0))
               .WithAuthor(a => a.WithIconUrl(Context.Client.CurrentUser.GetAvatarUrl()).WithName(Context.Client.CurrentUser.Username))
               .WithFooter(a => a.WithText($"{parsedResult.ExecutionTime.Milliseconds} ms"));

            embed.AddField(a => a.WithName("Code").WithValue(Format.Code(code, "cs")));
            embed.AddField(a => a.WithName($"Result: {parsedResult.ReturnValue?.GetType()?.Name ?? "null"}")
                                 .WithValue(Format.Code($"{parsedResult.ReturnValue?.ToString().Replace("\r\n", "") ?? " "}", "txt")));

            await Context.Channel.SendMessageAsync(string.Empty, embed: embed).ConfigureAwait(false);
        }<commit_msg>Adds an alias to exec -- eval -- because i'm tired of getting it wrong! also strip ```cs since it's a valid alias for csharp<commit_after>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Newtonsoft.Json;

namespace Modix.Modules
{
    public class Result
    {
        public object ReturnValue { get; set; }
        public string Exception { get; set; }
        public string Code { get; set; }
        public string ExceptionType { get; set; }
        public TimeSpan ExecutionTime { get; set; }
    }

    public class ReplModule : ModuleBase
    {
        private const string ReplRemoteUrl =
            "http://csharpdiscordfn.azurewebsites.net/api/EvalTrigger?code=MGx5t5RZ6mmmy1jhVZ1amrWr8S3nPyCzG6bTR1mYbwULdhfuq86Ckg==";

        [Command("exec", RunMode = RunMode.Async), Alias("eval"), Summary("Executes code!")]
        public async Task ReplInvoke([Remainder] string code)
        {
            string cleanCode = code.Replace("```csharp", "").Replace("```cs", "").Replace("```", "");

            var client = new HttpClient();
            var res = await client.PostAsync(ReplRemoteUrl, new StringContent(cleanCode));

            if (res.StatusCode == HttpStatusCode.Forbidden)
            {
                await ReplyAsync("Exec failed: You used a forbidden class. <@144084036036329472>");
                return;
            }

            if (!res.IsSuccessStatusCode & res.StatusCode != HttpStatusCode.BadRequest)
            {
                await ReplyAsync("Exec failed: " + res.StatusCode);
                return;
            }

            var parsedResult = JsonConvert.DeserializeObject<Result>(await res.Content.ReadAsStringAsync());

            var embed = new EmbedBuilder()
               .WithTitle("Eval Result")
               .WithDescription(string.IsNullOrEmpty(parsedResult.Exception) ? "Successful" : $"Failed: {parsedResult.ExceptionType} - {parsedResult.Exception}")
               .WithColor(string.IsNullOrEmpty(parsedResult.Exception) ? new Color(0, 255, 0) : new Color(255, 0, 0))
               .WithAuthor(a => a.WithIconUrl(Context.Client.CurrentUser.GetAvatarUrl()).WithName(Context.Client.CurrentUser.Username))
               .WithFooter(a => a.WithText($"{parsedResult.ExecutionTime.Milliseconds} ms"));

            embed.AddField(a => a.WithName("Code").WithValue(Format.Code(cleanCode, "cs")));
            embed.AddField(a => a.WithName($"Result: {parsedResult.ReturnValue?.GetType()?.Name ?? "null"}")
                                 .WithValue(Format.Code($"{parsedResult.ReturnValue?.ToString().Replace("\r\n", "") ?? " "}", "txt")));

            await Context.Channel.SendMessageAsync(string.Empty, embed: embed).ConfigureAwait(false);
        }
{'fraction_non_alphanumeric': 0.1284796573875803, 'fraction_numerical': 0.013918629550321198, 'mean_word_length': 2.736666666666667, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4981512', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1595, 'n_words': 320}