public async Task HandleCommandAsync(SocketUserMessage msg, int argPos) { var context = new MayaCommandContext(client, MainHandler, msg); var result = await commands.ExecuteAsync(context, argPos, services); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { if (result.ErrorReason != "null") { await msg.Channel.SendMessageAsync(result.ErrorReason); } } }
public async override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider map) { if (!(context is MayaCommandContext)) { return(PreconditionResult.FromError("null")); } MayaCommandContext con = context as MayaCommandContext; if (await con.MainHandler.PermissionHandler.IsAtLeastAsync(context.User, _level)) { return(PreconditionResult.FromSuccess()); } return(PreconditionResult.FromError($"You must have at least **{ToFriendlyString(_level)}** rights to use this command.")); }
public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider map) { if (!(context is MayaCommandContext)) { return(Task.FromResult(PreconditionResult.FromError(SearchResult.FromError(CommandError.UnknownCommand, "Unknown command.")))); } MayaCommandContext con = context as MayaCommandContext; if (!con.MainHandler.GuildConfigHandler(context.Guild).GetSwearJar().IsEnabled) { return(Task.FromResult(PreconditionResult.FromError(SearchResult.FromError(CommandError.UnknownCommand, "Unknown command.")))); } return(Task.FromResult(PreconditionResult.FromSuccess())); }
public async override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider map) //TODO: Remover connect aqui { if (!(context.Channel is ITextChannel)) { return(PreconditionResult.FromError("null")); } if (!(context is MayaCommandContext)) { return(PreconditionResult.FromError("null")); } MayaCommandContext con = context as MayaCommandContext; if (!con.MainHandler.GuildConfigHandler(con.Guild).GetMusic().IsEnabled) { return(PreconditionResult.FromError("Music system disabled.")); } if (!con.MainHandler.GuildMusicHandler(con.Guild).IsReady()) { return(PreconditionResult.FromError("Music system not ready.")); } MusicResult mr = con.MainHandler.GuildMusicHandler(con.Guild).CanUserUseMusicCommands(new MusicContext(context)); if (!mr.IsSuccessful) { return(PreconditionResult.FromError(mr.Error)); } IVoiceChannel vc = con.MainHandler.GuildMusicHandler(con.Guild).GetVoiceChannel(); IVoiceChannel channel = (con.Guild as SocketGuild)?.FindVoiceChannel(con.MainHandler.GuildConfigHandler(con.Guild).GetMusic().VoiceChannel); if (channel == null) { return(PreconditionResult.FromError($"Missing voice channel ({con.MainHandler.GuildConfigHandler(con.Guild).GetMusic().VoiceChannel}).")); } else if (vc == null) { await con.MainHandler.GuildMusicHandler(con.Guild).JoinVoiceChannelAsync(channel); } else if (vc != channel && !con.MainHandler.GuildMusicHandler(con.Guild).ShouldDownload()) //!download = doing nothing { await con.MainHandler.GuildMusicHandler(con.Guild).JoinVoiceChannelAsync(channel); } return(PreconditionResult.FromSuccess()); }
public override Task <PreconditionResult> CheckPermissions(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider map) { if (!(context is MayaCommandContext)) { return(Task.FromResult(PreconditionResult.FromSuccess())); } if (value != null && !(value is object[]) || (value is object[] && (value as object[]).Count() != 0)) { return(Task.FromResult(PreconditionResult.FromSuccess())); } MayaCommandContext con = context as MayaCommandContext; string cmdline; if (Text == null) { cmdline = $"**Usage**: {con.MainHandler.GetCommandPrefix(con.Channel)}{parameter.Command.Aliases.First()} [{String.Join("] [", parameter.Command.Parameters.Select(x => x.Name))}]"; } else { cmdline = $"**Usage**: {con.MainHandler.GetCommandPrefix(con.Channel)}{parameter.Command.Aliases.First()} [{Text}]"; } return(Task.FromResult(PreconditionResult.FromError(cmdline))); }