private async Task SendTagDoesntExist(string name, ShadeContext context) { var embed = CreateResponseEmbed(ResponseFormat.Error) .WithDescription($"No tag with name {Format.Code(name.Sanitize())} was found."); await context.AnswerAsync(embed : embed.Build()); }
public async Task HideAsync([Remainder] string command) { var context = new ShadeContext(Context.Me, Context.Message, Context.Client, Context.Services); context.SetAnswerType(AnswerType.None); var result = await CommandService.ExecuteAsync(context, command, Context.Services); _ = CommandHandlingService.HandleCommandResult(context, result); }
public async Task ExecuteAsync(IUser user, [Remainder] string command) { var fakeContext = new ShadeContext(Context.Me, Context.Message, Context.Client, Context.Services); fakeContext.OverrideUser(user); fakeContext.OverridePermissionsUser(Context.User as IGuildUser); var result = await CommandHandlingService.CommandService.ExecuteAsync(fakeContext, command, Services); await Context.Message.AddReactionAsync(new Emoji("\u2705")); _ = CommandHandlingService.HandleCommandResult(fakeContext, result); }
private Task HandleMessageReceived(IMessage m) { var guild = (m.Channel as ITextChannel).Guild; if (m is null || m is not IUserMessage msg || m.Author.IsBot) { return(Task.CompletedTask); } _ = Task.Run(async() => { // Default settings GuildSettings settings = new GuildSettings() { GuildId = guild.Id, Prefix = Environment.GetEnvironmentVariable("PREFIX") }; var contextFactory = _services.GetRequiredService <BotContextFactory>(); using (var botContext = contextFactory.CreateContext()) { var found = botContext.Find <GuildSettings>(guild.Id); if (found is null) { botContext.Add(settings); await botContext.SaveChangesAsync(); } else { settings = found; } } int argPos = 0; if (!msg.HasStringPrefix(settings.Prefix, ref argPos)) { return; } var me = await(m.Channel as IGuildChannel).Guild.GetCurrentUserAsync(); var context = new ShadeContext(me, msg, _client, _services); var result = await _commands.ExecuteAsync(context, argPos, _services); _ = HandleCommandResult(context, result); GC.Collect(); }); return(Task.CompletedTask); }
public async Task HandleCommandResult(ShadeContext context, IResult result) { if (result.IsSuccess) { return; } _logger.Error(result.ErrorReason); switch (result.Error) { case CommandError.UnknownCommand: { // Fail silently. } break; case CommandError.ParseFailed: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; case CommandError.BadArgCount: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; case CommandError.ObjectNotFound: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; case CommandError.MultipleMatches: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; case CommandError.UnmetPrecondition: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; case CommandError.Exception: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; default: case CommandError.Unsuccessful: { await EmbedUtilities.EmbedResponseAsync(context.Message, ResponseFormat.Error, description : result.ErrorReason); } break; } }