Esempio n. 1
0
        private async Task ReactionAddedAsync(SocketReaction reaction)
        {
            if (!(reaction.Channel is SocketGuildChannel guildChannel))
            {
                return;
            }
            if (reaction.User.Value.IsBot)
            {
                return;
            }
            using (var unitOfWork = Unity.Resolve <IUnitOfWork>())
            {
                var user = await unitOfWork.Users.GetOrAddUserInfoAsync(guildChannel.Guild.Id, reaction.UserId, reaction.User.Value.Username).ConfigureAwait(false);

                if (!(DateTime.Now.Subtract(user.LastEmoteAdded).TotalSeconds > 15))
                {
                    return;
                }
                user.LastEmoteAdded = DateTime.Now;
                await _expService.GiveXp(1, user, guildChannel.Guild, reaction.User.Value, unitOfWork).ConfigureAwait(false);

                await unitOfWork.SaveAsync().ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        private async Task HandleCommandAsync(SocketUserMessage msg)
        {
            try
            {
                if (msg.Author.IsBot)
                {
                    return;
                }
                var context = new ShardedCommandContext(_client, msg);
                var argPos  = 0;
                if (context.Message.HasStringPrefix("?", ref argPos) ||
                    context.Message.HasMentionPrefix(_client.CurrentUser, ref argPos))
                {
                    using (var unitOfWork = Unity.Resolve <IUnitOfWork>())
                    {
                        var searchResult = _commandService.Search(context, argPos);
                        if (searchResult.Commands == null || searchResult.Commands.Count == 0)
                        {
                            return;
                        }
                        var result = await _commandService.ExecuteAsync(context, argPos, _services).ConfigureAwait(false);

                        var user = await unitOfWork.Users.GetOrAddUserInfoAsync(context.Guild.Id, context.User.Id, context.User.Username).ConfigureAwait(false);

                        if (!(DateTime.Now.Subtract(user.LastMessageSend).TotalSeconds > 4))
                        {
                            return;
                        }
                        await _expService.GiveXp(3, user, context.Guild, context.User, unitOfWork).ConfigureAwait(false);

                        user.LastMessageSend = DateTime.Now;
                        user.MessagesSend++;
                        await unitOfWork.SaveAsync().ConfigureAwait(false);

                        Console.WriteLine(result.ErrorReason);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }