public override Task <CheckResult> CheckAsync(ICommandContext context0, IServiceProvider provider) { var context = context0.Cast <LittleBigBotExecutionContext>(); if (context.BotMember != null) { var cperms = context.BotMember.GetPermissions(context.GuildChannel); foreach (var gperm in _guildPermissions) { if (!context.BotMember.GuildPermissions.Has(gperm)) { return(Task.FromResult(new CheckResult( $"This command requires me to have the \"{gperm.Humanize()}\" server-level permission, but I do not have it!"))); } } foreach (var cperm in _channelPermissions) { if (!cperms.Has(cperm)) { return(Task.FromResult(new CheckResult( $"This command requires me to have the \"{cperm.Humanize()}\" channel-level permission, but I do not have it!"))); } } } return(Task.FromResult(CheckResult.Successful)); }
public override Task <CheckResult> CheckAsync(ICommandContext context0, IServiceProvider provider) { var context = context0.Cast <LittleBigBotExecutionContext>(); return(_type.HasFlag(context.Type) ? Task.FromResult(CheckResult.Successful) : Task.FromResult(new CheckResult( $"This command can only be used in a {_type:G}, but we're currently in a {context.Type:G}"))); }
public override Task <CheckResult> CheckAsync(ICommandContext context0, IServiceProvider provider) { var context = context0.Cast <LittleBigBotExecutionContext>(); if (context.GuildChannel == null || !context.GuildChannel.IsNsfw) { return(Task.FromResult(new CheckResult("This command can only be used in an NSFW channel."))); } return(Task.FromResult(CheckResult.Successful)); }
public override async Task <CheckResult> CheckAsync(ICommandContext context0, IServiceProvider provider) { var context = context0.Cast <LittleBigBotExecutionContext>(); var owner = (await context.Client.GetApplicationInfoAsync()).Owner; var invokerId = context.Invoker.Id; return(owner.Id == invokerId ? CheckResult.Successful : new CheckResult($"This command can only be executed by my owner, `{owner}`!")); }
public override async Task <CheckResult> CheckAsync(ICommandContext context, IServiceProvider provider) { var ctx = context.Cast <DepressedBotContext>(); if (ctx.User.Id == Config.Owner) { return(CheckResult.Successful); } await ctx.ReactFailureAsync(); return(CheckResult.Unsuccessful("Insufficient permission.")); }
public override async Task <CheckResult> CheckAsync(ICommandContext context, IServiceProvider provider) { var ctx = context.Cast <DepressedBotContext>(); if (ctx.User.RoleIds.Any(x => x == 385903172176183298)) { return(CheckResult.Successful); } await ctx.ReactFailureAsync(); return(CheckResult.Unsuccessful("Insufficient permission.")); }
public async Task OnCommandAsync(Command c, IResult res, ICommandContext context, Stopwatch sw) { var ctx = context.Cast <DepressedBotContext>(); var commandName = ctx.Message.Content.Split(" ")[0]; var args = ctx.Message.Content.Replace($"{commandName}", ""); if (string.IsNullOrEmpty(args)) { args = "None"; } if (res is FailedResult failedRes) { await OnCommandFailureAsync(c, failedRes, ctx, args, sw); return; } if (Config.LogAllCommands) { await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -Command from user: {ctx.User.Username}#{ctx.User.Discriminator} ({ctx.User.Id})"); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -Command Issued: {c.Name}"); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -Args Passed: {args.Trim()}"); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -In Guild: {ctx.Guild.Name} ({ctx.Guild.Id})"); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -In Channel: #{ctx.Channel.Name} ({ctx.Channel.Id})"); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -Time Issued: {DateTime.Now}"); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -Executed: {res.IsSuccessful} "); await _logger.Log(LogSeverity.Info, LogSource.Module, $"| -After: {sw.Elapsed.Humanize()}"); await _logger.Log(LogSeverity.Info, LogSource.Module, "-------------------------------------------------"); } }
public object GenerateBucketKey(object bucketType, ICommandContext context0, IServiceProvider provider) { var type = bucketType.Cast <CooldownType>(); var context = context0.Cast <LittleBigBotExecutionContext>(); switch (type) { case CooldownType.Server: return(context.Guild?.Id ?? context.Invoker.Id); case CooldownType.Channel: return(context.Channel.Id); case CooldownType.User: return(context.Invoker.Id); default: throw new ArgumentOutOfRangeException(); } }
private async Task HandleCommandErrorAsync(ExecutionFailedResult result, ICommandContext context0, IServiceProvider provider) { if (result.IsSuccessful) { return; // Theoretically shouldn't ever happen? } var context = context0.Cast <LittleBigBotExecutionContext>(); var command = result.Command; var exception = result.Exception; var embed = new EmbedBuilder { Color = Color.Red, Title = $"Command '{command.Name}' failed to run.", Description = result.Reason, ThumbnailUrl = context.Bot.GetEffectiveAvatarUrl(), Fields = new List <EmbedFieldBuilder> { new EmbedFieldBuilder { Name = "Message", Value = exception.Message, IsInline = true } }, Footer = new EmbedFooterBuilder { Text = $"If you believe this error is not because of your input, please contact {(await _client.GetApplicationInfoAsync()).Owner}!" } }; _commandsTracking.LogError(exception, context.FormatString(command) + " == DETAILS WILL FOLLOW =="); LogCommandGeneralFailure(context, command, result); await context.Channel.SendMessageAsync(string.Empty, false, embed.Build()); }
public Task HandleCommandExecutedAsync(Command command, CommandResult result, ICommandContext context, IServiceProvider arg4) { return(HandleCommandFinishedGlobalAsync(command, result, context.Cast <LittleBigBotExecutionContext>())); }
public override async Task <TypeParserResult <T> > ParseAsync(string value, ICommandContext context0, IServiceProvider provider) { var context = context0.Cast <LittleBigBotExecutionContext>(); var results = new Dictionary <ulong, UserParseResolveResult <T> >(); var channelUsers = context.Channel.GetUsersAsync(CacheMode.CacheOnly).Flatten(); IReadOnlyCollection <IGuildUser> guildUsers = ImmutableArray.Create <IGuildUser>(); if (context.Guild != null) { guildUsers = await((IGuild)context.Guild).GetUsersAsync(CacheMode.CacheOnly).ConfigureAwait(false); } //By Mention (1.0) if (MentionUtils.TryParseUser(value, out var id)) { if (context.Guild != null) { AddResult(results, await((IGuild)context.Guild).GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 1.00f); } else { AddResult(results, await context.Channel.GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 1.00f); } } //By Id (0.9) if (ulong.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out id)) { if (context.Guild != null) { AddResult(results, await((IGuild)context.Guild).GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 0.90f); } else { AddResult(results, await context.Channel.GetUserAsync(id, CacheMode.CacheOnly).ConfigureAwait(false) as T, 0.90f); } } var index = value.LastIndexOf('#'); if (index >= 0) { var username = value.Substring(0, index); if (ushort.TryParse(value.Substring(index + 1), out var discriminator)) { var channelUser = await channelUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator && string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase)) .ConfigureAwait(false); AddResult(results, channelUser as T, channelUser?.Username == username ? 0.85f : 0.75f); var guildUser = guildUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator && string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase)); AddResult(results, guildUser as T, guildUser?.Username == username ? 0.80f : 0.70f); } } { await channelUsers .Where(x => string.Equals(value, x.Username, StringComparison.OrdinalIgnoreCase)) .ForEachAsync(channelUser => AddResult(results, channelUser as T, channelUser.Username == value ? 0.65f : 0.55f)) .ConfigureAwait(false); foreach (var guildUser in guildUsers.Where(x => string.Equals(value, x.Username, StringComparison.OrdinalIgnoreCase))) { AddResult(results, guildUser as T, guildUser.Username == value ? 0.60f : 0.50f); } } { await channelUsers .Where(x => string.Equals(value, (x as IGuildUser)?.Nickname, StringComparison.OrdinalIgnoreCase)) .ForEachAsync(channelUser => AddResult(results, channelUser as T, (channelUser as IGuildUser)?.Nickname == value ? 0.65f : 0.55f)) .ConfigureAwait(false); foreach (var guildUser in guildUsers.Where(x => string.Equals(value, x.Nickname, StringComparison.OrdinalIgnoreCase))) { AddResult(results, guildUser as T, guildUser.Nickname == value ? 0.60f : 0.50f); } } return(results.Count > 0 ? new TypeParserResult <T>(results.Values.OrderByDescending(a => a.Value).First().Value) : new TypeParserResult <T>("User not found.")); }