コード例 #1
0
ファイル: BadRequestResult.cs プロジェクト: fossabot/Abyss
        public override async Task <ResultCompletionData> ExecuteResultAsync(AbyssRequestContext context)
        {
            var message = await context.Channel.SendMessageAsync(null, false, new EmbedBuilder()
                                                                 .WithTitle("You've been telling me lies, hun.")
                                                                 .WithDescription(Reason)
                                                                 .WithColor(ErrorColor)
                                                                 .WithTimestamp(DateTimeOffset.Now)
                                                                 .WithFooter($"Requested by: {context.Invoker.Format()}", context.Invoker.GetEffectiveAvatarUrl())
                                                                 .Build());

            return(new ResultCompletionData(message));
        }
コード例 #2
0
ファイル: OkResult.cs プロジェクト: fossabot/Abyss
        public override async Task <ResultCompletionData> ExecuteResultAsync(AbyssRequestContext context)
        {
            if (!context.BotUser.GetPermissions(context.Channel).SendMessages)
            {
                return(new ResultCompletionData());
            }
            if (Attachments.Length > 0 && !context.BotUser.GetPermissions(context.Channel).AttachFiles)
            {
                return(new ResultCompletionData());
            }

            var messages = new List <RestUserMessage>();

            if (Attachments.Length == 1)
            {
                var attach0 = Attachments.First();
                messages.Add(await context.Channel.SendFileAsync(attach0.Stream, attach0.Filename, Message, false, Embed?.Build()));
            }
            else if (Attachments.Length > 0)
            {
                foreach (var attach in Attachments)
                {
                    messages.Add(await context.Channel.SendFileAsync(attach.Stream, attach.Filename, null));
                }

                if (Message != null || Embed != null)
                {
                    messages.Add(await context.Channel.SendMessageAsync(Message, false, Embed?.Build()));
                }
            }
            else
            {
                messages.Add(await context.Channel.SendMessageAsync(Message, false, Embed?.Build()));
            }
            return(new ResultCompletionData(messages.ToArray()));
        }
コード例 #3
0
 public override Task <ResultCompletionData> ExecuteResultAsync(AbyssRequestContext context)
 {
     return(Task.FromResult(new ResultCompletionData()));
 }
コード例 #4
0
 public abstract Task <ResultCompletionData> ExecuteResultAsync(AbyssRequestContext context);
コード例 #5
0
 public EvaluationHelper(AbyssRequestContext context)
 {
     Context = context;
 }
コード例 #6
0
ファイル: EmbedExtensions.cs プロジェクト: fossabot/Abyss
 public static EmbedBuilder WithRequesterFooter(this EmbedBuilder builder, AbyssRequestContext context)
 {
     return(builder.WithFooter($"Requested by {context.Invoker.Format()}",
                               context.Invoker.GetEffectiveAvatarUrl()));
 }
コード例 #7
0
 public string GetDescription(AbyssRequestContext ctx) => $"{ctx.Services.GetRequiredService<AbyssConfig>().Emotes.StaffEmote} You have to be my current owner.";
コード例 #8
0
ファイル: ReactSuccessResult.cs プロジェクト: fossabot/Abyss
        public override async Task <ResultCompletionData> ExecuteResultAsync(AbyssRequestContext context)
        {
            var message = await context.ReplyAsync(":ok_hand:");

            return(new ResultCompletionData(message));
        }
コード例 #9
0
 public string GetDescription(AbyssRequestContext requestContext) => ChannelPermissions.Count > 0
     ? $"You need these channel-level permissions: {string.Join(", ", ChannelPermissions.Select(a => a.Humanize()))}."
     : $"You need these server-level permissions: {string.Join(", ", GuildPermissions.Select(a => a.Humanize()))}.";
コード例 #10
0
 public string GetDescription(AbyssRequestContext requestContext) => "The provided user can't be you.";
コード例 #11
0
 public string GetDescription(AbyssRequestContext requestContext) => "We must be in one of the following servers: " + string.Join(", ", Ids) + ".";
コード例 #12
0
 public string GetDescription(AbyssRequestContext context) => "We must be in an NSFW channel.";
コード例 #13
0
        public async Task ReceiveMessageAsync(SocketMessage incomingMessage)
        {
            if (!(incomingMessage is SocketUserMessage message) || message.Author is SocketWebhookUser ||
                message.Author.IsBot)
            {
                return;
            }

            if (!(message.Channel is SocketGuildChannel))
            {
                await message.Channel.TrySendMessageAsync(
                    "Sorry, but I can only respond to commands in servers. Please try using your command in any of the servers that I share with you!")
                .ConfigureAwait(false);

                _failedCommandsTracking.LogError(LoggingEventIds.UserDirectMessaged, $"Received direct message from {message.Author}, ignoring.");
                return;
            }

            var argPos = 0;

            if (!message.HasStringPrefix(_config.CommandPrefix, ref argPos) &&
                !message.HasMentionPrefix(_discordClient.CurrentUser, ref argPos))
            {
                return;
            }

            var context = new AbyssRequestContext(message, _services);

            var requestString = message.Content.Substring(argPos);

            try
            {
                var result =
                    await _commandService.ExecuteAsync(requestString, context, context.Services).ConfigureAwait(false);

                if (result.IsSuccessful)
                {
                    if (!(result is SuccessfulResult))
                    {
                        CommandSuccesses++;                                // SuccessfulResult indicates a RunMode.Async
                    }
                    return;
                }

                switch (result)
                {
                case CommandResult _:
                    return;

                case CommandNotFoundResult cnfr:
                    _failedCommandsTracking.LogWarning(LoggingEventIds.UnknownCommand, $"No command found matching {requestString} (message {message.Id} - channel {message.Channel.Name}/{message.Channel.Id} - guild {context.Guild.Name}/{context.Guild.Id})");
                    await context.Message.AddReactionAsync(UnknownCommandReaction).ConfigureAwait(false);

                    return;

                case ExecutionFailedResult _:
                    return;

                case ChecksFailedResult cfr:
                    _failedCommandsTracking.LogWarning(LoggingEventIds.ChecksFailed, $"{cfr.FailedChecks.Count} checks ({string.Join(", ", cfr.FailedChecks.Select(c => c.Check.GetType().Name))}) " +
                                                       $"failed for command {cfr.Command.Name} (message {message.Id} - channel {message.Channel.Name}/{message.Channel.Id} - guild {context.Guild.Name}/{context.Guild.Id})");


                    if (cfr.FailedChecks.Count == 1 && cfr.FailedChecks.FirstOrDefault().Check.GetType()
                        .CustomAttributes.Any(a => a.AttributeType == typeof(SilentCheckAttribute)))
                    {
                        break;
                    }

                    await context.Channel.SendMessageAsync(embed : new EmbedBuilder()
                                                           .WithTitle(
                                                               $"No can do.")
                                                           .WithDescription("Can't do that, because: \n" + string.Join("\n",
                                                                                                                       cfr.FailedChecks.Where(a => a.Check.GetType().CustomAttributes.All(b => b.AttributeType != typeof(SilentCheckAttribute)))
                                                                                                                       .Select(a => $"- {a.Result.Reason}")))
                                                           .WithColor(Color.Red)
                                                           .WithFooter(
                                                               $"{(cfr.Command == null ? $"Module {cfr.Module.Name}" : $"Command {cfr.Command.Name} in module {cfr.Command.Module.Name}")}, " +
                                                               $"executed by {context.Invoker.Format()}")
                                                           .WithCurrentTimestamp()
                                                           .Build()).ConfigureAwait(false);

                    break;