Exemple #1
0
        private async Task HandleUserJoin(SocketGuildUser u)
        {
            await Logger.DetailedLog(u.Guild, "Event", "User Joined", "User", $"{u}", u.Id, new Color(12, 255, 129), false);

            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var muteRepo  = new MuteRepository(db);
                var user      = u as IGuildUser;
                var mutedRole = user.Guild.GetRole((await guildRepo.FetchGuildAsync(user.Guild.Id)).MutedRoleId);
                if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles &&
                    mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
                {
                    await RankHandler.Handle(u.Guild, u.Id);

                    if (await muteRepo.IsMutedAsync(user.Id, user.Guild.Id) && mutedRole != null && user != null)
                    {
                        await user.AddRoleAsync(mutedRole);
                    }
                }

                if (Config.BLACKLISTED_IDS.Any(x => x == u.Id))
                {
                    if (u.Guild.CurrentUser.GuildPermissions.BanMembers &&
                        u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position >
                        u.Roles.OrderByDescending(x => x.Position).First().Position&& u.Guild.OwnerId != u.Id)
                    {
                        await u.Guild.AddBanAsync(u);
                    }
                }
            }
        }
Exemple #2
0
        private Task HandleUserJoined(SocketGuildUser u)
        {
            return(Task.Run(async() =>
            {
                Logger.Log(LogSeverity.Debug, $"Event", "User Joined");
                if ((await _blacklistRepo.AllAsync()).Any(x => x.UserId == u.Id))
                {
                    try
                    {
                        await u.Guild.AddBanAsync(u);
                    }
                    catch
                    {
                        // Ignored.
                    }
                }

                var user = u as IGuildUser;
                var dbGuild = await _guildRepo.GetGuildAsync(user.Guild.Id);

                var mutedRole = user.Guild.GetRole((dbGuild.MutedRoleId));
                if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles &&
                    mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
                {
                    await _RankHandler.HandleAsync(user, dbGuild, await _userRepo.GetUserAsync(user));
                    if (await _muteRepo.IsMutedAsync(user.Id, user.Guild.Id) && mutedRole != null && user != null)
                    {
                        await user.AddRoleAsync(mutedRole);
                    }
                }

                if (!string.IsNullOrWhiteSpace(dbGuild.WelcomeMessage))
                {
                    var channel = _client.GetChannel(dbGuild.WelcomeChannelId);
                    if (channel != null)
                    {
                        try
                        {
                            await(channel as ITextChannel).SendAsync($"{u}, " + dbGuild.WelcomeMessage);
                        }
                        catch
                        {
                            // Ignored.
                        }
                    }
                    else
                    {
                        try
                        {
                            var dmChannel = await u.CreateDMChannelAsync();
                            await dmChannel.SendAsync(dbGuild.WelcomeMessage);
                        }
                        catch
                        {
                            // Ignored.
                        }
                    }
                }
            }));
        }
Exemple #3
0
        private async Task HandleUserJoin(SocketGuildUser u)
        {
            await Logger.DetailedLog(u.Guild, "Event", "User Joined", "User", $"{u}", u.Id, new Color(12, 255, 129), false);

            var user      = u as IGuildUser;
            var mutedRole = user.Guild.GetRole((ulong)((await GuildRepository.FetchGuildAsync(user.Guild.Id)).MutedRoleId));

            if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles &&
                mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
            {
                await RankHandler.Handle(u.Guild, u.Id);

                if (await MuteRepository.IsMutedAsync(user.Id, user.Guild.Id) && mutedRole != null && user != null)
                {
                    await user.AddRoleAsync(mutedRole);
                }
            }
        }