Exemplo n.º 1
0
        public async Task PrefixAsync(string newPrefix)
        {
            var guildConfiguration = await _dbStorage.FindOne <HamburgerGuildConfiguration>(x => x.DiscordGuildId == Context.Guild.Id,
                                                                                            Context.Guild.Id.ToString());

            var oldPrefix = guildConfiguration.CommandPrefix;

            guildConfiguration.CommandPrefix = newPrefix;

            await _dbStorage.UpdateOne(guildConfiguration, x => x.DiscordGuildId == Context.Guild.Id,
                                       Context.Guild.Id.ToString());

            var embed = new EmbedBuilder()
                        .WithTitle("Command prefix changed")
                        .WithDescription($"The command prefix was changed from `{oldPrefix}` to `{newPrefix}`")
                        .Build();

            await Context.Channel.SendMessageAsync("", false, embed);
        }
        public async Task <HamburgerUser> GetOrCreateUserAsync(ulong userId, ulong guildId)
        {
            var user = await _db.FindOne <HamburgerUser>(x => x.DiscordUserId == userId, guildId.ToString());

            return(EnsureUserExists(user, userId, guildId));
        }
Exemplo n.º 3
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;

            if (message is null)
            {
                return;
            }

            var channel = arg.Channel as SocketGuildChannel;
            var guildid = channel.Guild.Id;

            var currentGuild =
                await _dbStorage.FindOne <HamburgerGuildConfiguration>(x => x.DiscordGuildId == guildid, guildid.ToString());

            int argPos = 0;

            if (!(message.HasStringPrefix(currentGuild.CommandPrefix, ref argPos) ||
                  message.HasMentionPrefix(_client.Client.CurrentUser, ref argPos) ||
                  message.Content == _client.Client.CurrentUser.Mention) ||
                message.Author.IsBot)
            {
                return;
            }

            var context = new ShardedCommandContext(_client.Client, message);

            if (message.Content == _client.Client.CurrentUser.Mention)
            {
                var embed = new EmbedBuilder()
                            .WithTitle("Hello!")
                            .WithDescription($"My prefix is `{currentGuild.CommandPrefix}`, you can also mention me with any command \n(Ex: `@Hamburger prefix ?`)")
                            .Build();

                await context.Channel.SendMessageAsync("", false, embed);

                return;
            }

            _logger.Log($"Executed command in server [{context.Guild.Name}]({context.Channel.Id}) and channel [{context.Channel.Name}]({context.Channel.Id.ToString()}) by user [{context.User.Username}#{context.User.Discriminator}]({context.User.Id.ToString()})",
                        LogSeverity.SEVERITY_MESSAGE);

            var result = await _commandService.ExecuteAsync(
                context : context,
                argPos : argPos,
                services : _services
                );

            if (result is null)
            {
                return;
            }

            if (!result.IsSuccess)
            {
                var builder = new EmbedBuilder()
                              .WithTitle("Error")
                              .WithDescription(result.ErrorReason)
                              .Build();

                await context.Channel.SendMessageAsync("", false, builder);
            }
        }