예제 #1
0
파일: Program.cs 프로젝트: Zod-/UDHBot
        private async Task UserJoined(SocketGuildUser user)
        {
            ulong general           = _settings.GeneralChannel.Id;
            var   socketTextChannel = _client.GetChannel(general) as SocketTextChannel;

            _databaseService.AddNewUser(user);

            //Check for existing mute
            if (_userService._mutedUsers.HasUser(user.Id))
            {
                await user.AddRoleAsync(socketTextChannel?.Guild.GetRole(_settings.MutedRoleId));

                await _loggingService.LogAction(
                    $"Currently muted user rejoined - {user.Mention} - `{user.Username}#{user.DiscriminatorValue}` - ID : `{user.Id}`");

                await socketTextChannel.SendMessageAsync(
                    $"{user.Mention} tried to rejoin the server to avoid their mute. Mute time increased by 72 hours.");

                _userService._mutedUsers.AddCooldown(user.Id, hours: 72);
                return;
            }


            await _loggingService.LogAction(
                $"User Joined - {user.Mention} - `{user.Username}#{user.DiscriminatorValue}` - ID : `{user.Id}`");

            Embed em = _userService.WelcomeMessage(user.GetAvatarUrl(), user.Username, user.DiscriminatorValue);

            if (socketTextChannel != null)
            {
                await socketTextChannel.SendMessageAsync(string.Empty, false, em);
            }

            string     globalRules = _rules.Channel.First(x => x.Id == 0).Content;
            IDMChannel dm          = await user.GetOrCreateDMChannelAsync();

            await dm.SendMessageAsync(
                "Hello and welcome to Unity Developer Hub !\nHope you enjoy your stay.\nHere are some rules to respect to keep the community friendly, please read them carefully.\n" +
                "Please also read the additional informations in the **#welcome** channel." +
                "You can get all the available commands on the server by typing !help in the **#bot-commands** channel.");

            await dm.SendMessageAsync(globalRules);

            //TODO: add users when bot was offline
        }
예제 #2
0
 async Task DbSync(IUser user)
 {
     _database.AddNewUser((SocketGuildUser)user);
 }
예제 #3
0
        public async Task UpdateXp(SocketMessage messageParam)
        {
            if (messageParam.Author.IsBot)
            {
                return;
            }

            if (_noXpChannels.Contains(messageParam.Channel.Id))
            {
                return;
            }

            ulong userId   = messageParam.Author.Id;
            int   waitTime = rand.Next(_xpMinCooldown, _xpMaxCooldown);
            float baseXp   = rand.Next(_xpMinPerMessage, _xpMaxPerMessage);
            float bonusXp  = 0;

            if (_xpCooldown.HasUser(userId))
            {
                return;
            }

            int karma = _databaseService.GetUserKarma(userId);

            if (messageParam.Author.Game != null)
            {
                if (Regex.Match(messageParam.Author.Game.Value.ToString(), "(Unity.+)").Length > 0)
                {
                    bonusXp += baseXp / 4;
                }
            }

            bonusXp += baseXp * (1f + (karma / 100f));

            //Reduce XP for members with no role
            if (((IGuildUser)messageParam.Author).RoleIds.Count < 2)
            {
                baseXp *= .9f;
            }

            //Lower xp for difference between level and karma
            uint  level    = _databaseService.GetUserLevel(userId);
            float reduceXp = 1f;

            if (karma < level)
            {
                reduceXp = 1 - Math.Min(.9f, (level - karma) * .05f);
            }

            int xpGain = (int)Math.Round((baseXp + bonusXp) * reduceXp);

            //Console.WriteLine($"basexp {baseXp} karma {karma}  bonus {bonusXp}");
            _xpCooldown.AddCooldown(userId, waitTime);
            //Console.WriteLine($"{_xpCooldown[id].Minute}  {_xpCooldown[id].Second}");

            if (!await _databaseService.UserExists(userId))
            {
                _databaseService.AddNewUser((SocketGuildUser)messageParam.Author);
            }

            _databaseService.AddUserXp(userId, xpGain);
            _databaseService.AddUserUdc(userId, (int)Math.Round(xpGain * .15f));

            await _loggingService.LogXp(messageParam.Channel.Name, messageParam.Author.Username, baseXp, bonusXp, reduceXp, xpGain);

            await LevelUp(messageParam, userId);

            //TODO: add xp gain on website
        }