예제 #1
0
 private async Task OnCommandExecuted(Discord.Optional <CommandInfo> command, ICommandContext context, IResult result)
 {
     if (command.IsSpecified && !result.IsSuccess)
     {
         await context.Channel.SendMessageAsync($"Error: {result}");
     }
 }
예제 #2
0
        public async Task CommandExecuted(Discord.Optional <CommandInfo> commandInfo, ICommandContext context, IResult result)
        {
            // If the command failed, notify the user
            if (!result.IsSuccess && !result.ErrorReason.Equals("") && !context.Guild.Id.Equals(264445053596991498) &&
                !context.Message.Content.Contains("help", StringComparison.InvariantCultureIgnoreCase) && !context.Message.Content.StartsWith("?"))
            {
                Task.Run(async() =>
                {
                    //Wait for exception to reach log
                    await Task.Delay(100);
                    var embed = await CreateErrorEmbedAsync(commandInfo.Value, context as SocketCommandContext, result);
                    if (mostRecentException != null && !string.IsNullOrEmpty(Program.Config["ExceptionLogChannel"]))
                    {
                        using (var writer = File.CreateText("mopsdata//Exception.txt"))
                            writer.WriteLine(mostRecentException.ToString());
                        await(Program.Client.GetChannel(ulong.Parse(Program.Config["ExceptionLogChannel"])) as ITextChannel).SendFileAsync("mopsdata//Exception.txt", "", embed: embed);
                        File.Delete("mopsdata//Exception.txt");
                        mostRecentException = null;
                    }
                    else
                    {
                        await(Program.Client.GetChannel(ulong.Parse(Program.Config["ExceptionLogChannel"])) as ITextChannel).SendMessageAsync("", embed: embed);
                    }
                });

                if (!context.Message.Content.Contains("help", StringComparison.InvariantCultureIgnoreCase) && !context.Message.Content.StartsWith("?"))
                {
                    if (result.ErrorReason.Contains("The input text has too many parameters"))
                    {
                        await context.Channel.SendMessageAsync($"**Error:** {result.ErrorReason}\nIf your parameter contains spaces, please wrap it around quotation marks like this: `\"A Parameter\"`.");
                    }
                    else if (!result.ErrorReason.Contains("Command not found"))
                    {
                        await context.Channel.SendMessageAsync($"**Error:** {result.ErrorReason}");
                    }
                }
            }

            else if (result.IsSuccess && !string.IsNullOrEmpty(Program.Config["CommandLogChannel"]))
            {
                var cmdEmbed = new EmbedBuilder().AddField("Guild", $"{context.Guild.Name} ({context.Guild.Id})", true).AddField("Channel", $"{context.Channel.Name} ({context.Channel.Id})").AddField("User", $"{context.User} ({context.User.Id})").AddField("Command", context.Message.Content);
                await(Program.Client.GetChannel(ulong.Parse(Program.Config["CommandLogChannel"])) as ITextChannel).SendMessageAsync(embed: cmdEmbed.Build());
            }

            if (result.IsSuccess && context.Message.Content.Contains("track", StringComparison.InvariantCultureIgnoreCase))
            {
                if ((await MopsBot.Data.Entities.User.GetUserAsync(context.User.Id)).IsTaCDue())
                {
                    await context.Channel.SendMessageAsync($"Weekly reminder:\nBy using Mops' tracking services, you agree to our terms and conditions as well as our privacy policy: http://37.221.195.236/Terms_And_Conditions\nhttp://37.221.195.236/Privacy_Policy");

                    await MopsBot.Data.Entities.User.ModifyUserAsync(context.User.Id, x => x.LastTaCReminder = DateTime.UtcNow);
                }
            }
        }
예제 #3
0
        public async Task CommandExecuted(Discord.Optional <CommandInfo> commandInfo, ICommandContext context, IResult result)
        {
            // If the command failed, notify the user
            if (!result.IsSuccess && !result.ErrorReason.Equals("") && !context.Guild.Id.Equals(264445053596991498))
            {
                Task.Run(async() =>
                {
                    //Wait for exception to reach log
                    await Task.Delay(100);
                    var embed = await CreateErrorEmbedAsync(commandInfo.Value, context as SocketCommandContext, result);
                    if (mostRecentException != null)
                    {
                        using (var writer = File.CreateText("mopsdata//Exception.txt"))
                            writer.WriteLine(mostRecentException.ToString());
                        await(Program.Client.GetChannel(583906837351366657) as ITextChannel).SendFileAsync("mopsdata//Exception.txt", "", embed: embed);
                        File.Delete("mopsdata//Exception.txt");
                        mostRecentException = null;
                    }
                    else
                    {
                        await(Program.Client.GetChannel(583906837351366657) as ITextChannel).SendMessageAsync("", embed: embed);
                    }
                });

                if (result.ErrorReason.Contains("The input text has too many parameters"))
                {
                    await context.Channel.SendMessageAsync($"**Error:** {result.ErrorReason}\nIf your parameter contains spaces, please wrap it around quotation marks like this: `\"A Parameter\"`.");
                }
                else if (!result.ErrorReason.Contains("Command not found"))
                {
                    await context.Channel.SendMessageAsync($"**Error:** {result.ErrorReason}");
                }
            }


            else if (result.IsSuccess && context.Message.Content.Contains("track", StringComparison.InvariantCultureIgnoreCase))
            {
                if ((await MopsBot.Data.Entities.User.GetUserAsync(context.User.Id)).IsTaCDue())
                {
                    await context.Channel.SendMessageAsync($"Weekly reminder:\nBy using Mops's tracking services, you agree to these terms and conditions: {Program.Config["ServerAddress"]}/Terms_And_Conditions");

                    await MopsBot.Data.Entities.User.ModifyUserAsync(context.User.Id, x => x.LastTaCReminder = DateTime.UtcNow);
                }
            }
        }
예제 #4
0
        public static async Task OnCommandExecuted(Discord.Optional <CommandInfo> command, ICommandContext context, IResult result)
        {
            if (!result.IsSuccess)
            {
                if (result.Error == CommandError.UnknownCommand)
                {
                    return;
                }

                var ctx = context as SocketCommandContext;

                EmbedBuilder emb = ctx.CreateEmbed(title: "오류 발생!", description: $"{result.Error}: {result.ErrorReason}\n");

                await ctx.MsgReplyEmbedAsync(emb.Build());
            }
            else
            {
                if (new Random().Next(0, 10) == 0 && await KoreanBots.IsVotedAsync(context.User.Id))
                {
                    await(context as SocketCommandContext).MsgReplyEmbedAsync("[KOREANBOTS](https://koreanbots.dev/bots/495209098929766400)에서 올리브토스트에게 하트를 추가해주세요!\n(하트는 12시간마다 한번씩 추가할 수 있어요)");
                }
            }
        }