/// <summary> /// Executes the command /// </summary> /// <param name="msg"></param> /// <param name="context"></param> /// <param name="server"></param> /// <returns>Returns false if it isn't a command with a prefix</returns> private bool HandleCommand(IUserMessage msg, SocketCommandContext context, ServerList server) { int argPos = 0; if (!msg.HasStringPrefix(Global.BotPrefix, ref argPos) && !msg.HasMentionPrefix(Global.BotUser, ref argPos)) { return(false); } //Check user's permission to use command if (!CheckUserPermission(context, server, argPos)) { context.Channel.SendMessageAsync( "You do not have permission to use that command on this guild!").GetAwaiter().GetResult(); return(true); } //Execute the command and handle the result IResult result = commands.ExecuteAsync(context, argPos, services).GetAwaiter().GetResult(); HandleCommandResult(context, msg, result).GetAwaiter().GetResult(); return(true); }
public async Task HandleCommandAsync(IUserMessage message, bool parsePrefix) { if (message == null) { m_logger.LogCritical("Received a message that wasn't a SocketUserMessage"); return; } if (!IsIntentionalCommand(message !.Content)) { m_logger.LogInfo("Probably unintentional command, ignoring"); return; } int argPos = 0; if (parsePrefix) { if (!(message.HasStringPrefix(m_config.Configuration.Prefix, ref argPos, StringComparison.OrdinalIgnoreCase) || message.HasMentionPrefix(m_client?.CurrentUser, ref argPos)) || message !.Author.IsBot) { return; } } BelfastCommandContext context = new BelfastCommandContext(m_client, message); Task <IResult> task = m_command.ExecuteAsync( context: context, argPos: argPos, services: m_services); IResult?result = null; if ((await Task.WhenAny(task, Task.Delay(TimeSpan.FromSeconds(10)))) == task) { result = task.Result; } if (result == null) { await context.Channel.SendMessageAsync( $"{Emotes.BelfastPout} Sorry For My Misbehaviour Commander!\n" + $"Command timed out" ); } else if (!result.IsSuccess) { await context.Channel.SendMessageAsync( $"{Emotes.BelfastShock} Sorry For My Misbehaviour Commander!\n" + $"{result.ErrorReason}\n" + $"try **{m_config.Configuration.Prefix}help** for lists of commands" ); } else { m_logger.LogInfo("Successfully handled command"); } }
private async Task TryExecute(IUserMessage message, SocketCommandContext context) { var prefix = _configuration["Discord:Prefix"]; var argPos = 0; if (message.HasStringPrefix(prefix, ref argPos)) { await _commandService.ExecuteAsync(context, argPos, _serviceProvider); } }
private bool MessageIsValid(IUserMessage message, ref int argPos) { return((message.HasStringPrefix("giv ", ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos)) && !(message.Channel is SocketDMChannel)); }
private static bool ParseTriggers(IUserMessage message, ref int argPos) => message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(_config.Prefix, ref argPos);
private bool ParseTriggers(IUserMessage message, ref int argPos) => message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(_config["Prefixes:Main"] + " ", ref argPos);