Ejemplo n.º 1
0
        private async Task HandleMessageReceived(SocketMessage incoming)
        {
            var message = incoming as SocketUserMessage;

            if (message is null)
            {
                return;
            }

            int argPos      = 0;
            var borkContext = new DoggoCommandContext(borkClient, message);

            if (!message.HasStringPrefix(borkConfig.LoadedSecrets.BotPrefix, ref argPos) || message.HasMentionPrefix(borkClient.CurrentUser, ref argPos))
            {
                return;
            }

            if (borkConfig.BlockedUsers.ContainsKey(message.Author.Id))
            {
                string           ifBlockIsPerm = "";
                BlockedUserModel blockedUser   = borkConfig.BlockedUsers[message.Author.Id];

                if (blockedUser.Permanent)
                {
                    ifBlockIsPerm = $"Your block is permanent, please DM {(await borkClient.GetApplicationInfoAsync()).Owner} if you wish to appeal.";
                }
                else
                {
                    ifBlockIsPerm = $"Your block is not permanent, it will be repealed eventually.";
                }

                await borkContext.Channel.SendMessageAsync("", false, new EmbedBuilder()
                                                           .WithColor(new Color(0, 0, 0))
                                                           .WithDescription($"**Error: You have been blocked from using commands.**\n`Blocked On:` *{blockedUser.BlockedTime.Date:MM/dd/yyyy}*\n\n`Reason:` *{blockedUser.Reason}*")
                                                           .WithFooter(x => { x.Text = ifBlockIsPerm; }).Build()); return;
            }

            using (IDisposable enterTyping = borkContext.Channel.EnterTypingState())
            {
                var res = await borkCommands.ExecuteAsync(borkContext, argPos, borkServices);

                if (!res.IsSuccess)
                {
                    if (res.Error == CommandError.UnknownCommand)
                    {
                        await borkContext.Channel.SendMessageAsync("Sorry! I didn't understand that command, please try again! :triangular_flag_on_post:");
                    }
                    else if (res.Error == CommandError.BadArgCount)
                    {
                        await borkContext.Channel.SendMessageAsync("Oh no! You didn't put enough parameters, check help if you need to! :scales:");
                    }
                    else
                    {
                        await borkContext.Channel.SendMessageAsync(res.ErrorReason);
                    }
                }
                enterTyping.Dispose();
            }
        }
Ejemplo n.º 2
0
        public static async Task <string> EvalutateAsync(DoggoCommandContext context, string script)
        {
            ScriptOptions scriptOps = ScriptOptions.Default.AddReferences(obtainAssemblies()).AddReferences(EvalImports.Imports);
            EvalGlobals   scriptGlb = new EvalGlobals {
                Client = context.Client, Context = context
            };

            try { var finishedEval = await CSharpScript.EvaluateAsync(script, scriptOps, scriptGlb, typeof(EvalGlobals)); return(finishedEval.ToString()); }
            catch (Exception ex) { return($"```csharp\n[{ex.Source}] {ex.Message}\n\nStack Trace: {ex.StackTrace}```"); }
        }