public void GetPrefixAsync() { var mock = new Mock <IGuildData>(MockBehavior.Strict); mock.Setup(x => x.GetGuildConfigAsync(0)).Returns(Task.FromResult(testConfig)); var guildService = new GuildService(mock.Object); var actual = guildService.GetPrefixAsync(0); var expected = Task.FromResult('-'); Assert.Equal(expected.Result, actual.Result); }
public async Task Help() { var builder = new EmbedBuilder() { Color = new Color(150, 0, 0), Description = $"The prefix for this community is { await _guildService.GetPrefixAsync(Context.Guild.Id)}" }; foreach (var command in _commandExtentions.GetAllCommands()) { builder.AddField($"{command.Module.Group} {command.Name}", command.Summary, false); } await ReplyAsync("", false, builder.Build()); }
/// <summary> /// Asynchronously handles commands to the bot, which are SocketMessages. /// </summary> /// <param name="messageParam">The SocketMessage</param> /// <returns>Is an async Task.</returns> private async Task HandleCommandAsync(SocketMessage messageParam) { // Don't process the command if it was a system message var message = messageParam as SocketUserMessage; if (message == null) { return; } if (message.Author.IsBot) { return; } // Create a WebSocket-based command context based on the message var context = new SocketCommandContext(_client, message); // Create a number to track where the prefix ends and the command begins int argPos = 0; // Determine if the message is a command based on the prefix and make sure no bots trigger commands if (message.HasCharPrefix(await _guildService.GetPrefixAsync(context.Guild.Id), ref argPos)) { // Execute the command with the command context we just // created, along with the service provider for precondition checks. await _commands.ExecuteAsync( context : context, argPos : argPos, services : _services); } else if (await _guildService.GetMessageLogAsync(context.Guild.Id)) { await _messageService.AddMessageAsync( context.Guild.Id, context.Channel.Id, context.User.Id, message.Content, message.Attachments.Select(x => x.ProxyUrl).ToArray(), message.Timestamp.UtcDateTime); } }