Exemple #1
0
        private static void CheckToDeleteVoice(object sender, ElapsedEventArgs e)
        {
            var allUserAccounts = UserAccounts.GetOrAddUserAccountsForGuild(0);

            foreach (var t in allUserAccounts)
            {
                try
                {
                    var globalAccount = Global.Client.GetUser(t.Id);
                    var account       = UserAccounts.GetAccount(globalAccount, 0);
                    if (account.VoiceChannelList.Count <= 0)
                    {
                        continue;
                    }

                    var difference = DateTime.UtcNow - account.VoiceChannelList[0].LastTimeLeftChannel;

                    if (difference.Minutes > 10)
                    {
                        var voiceChan = Global.Client.GetGuild(account.VoiceChannelList[0].GuildId)
                                        .GetVoiceChannel(account.VoiceChannelList[0].VoiceChannelId);

                        account.VoiceChannelList = new List <AccountSettings.CreateVoiceChannel>();
                        UserAccounts.SaveAccounts(0);

                        if (voiceChan.Users.Count <= 0)
                        {
                            voiceChan.DeleteAsync();
                        }
                        else if (voiceChan.Users.Count >= 1)
                        {
                            var usersList = voiceChan.Users.ToList();
                            var newHolder = UserAccounts.GetAccount(usersList[0], 0);

                            var newVoice = new AccountSettings.CreateVoiceChannel(DateTime.UtcNow.AddHours(10),
                                                                                  voiceChan.Id, voiceChan.Guild.Id);
                            newHolder.VoiceChannelList.Add(newVoice);
                            UserAccounts.SaveAccounts(0);
                            var guildUser = Global.Client.GetGuild(newHolder.VoiceChannelList[0].GuildId)
                                            .GetUser(newHolder.Id);
                            var k = voiceChan.AddPermissionOverwriteAsync(guildUser,
                                                                          OverwritePermissions.AllowAll(voiceChan),
                                                                          RequestOptions.Default);
                            var kk = voiceChan.RemovePermissionOverwriteAsync(globalAccount, RequestOptions.Default);
                        }
                    }
                }
                catch
                {
                    //
                }
            }
        }
Exemple #2
0
        public async Task ServerStats(ulong guildId = 0)
        {
            try
            {
                SocketGuild guild;

                if (guildId == 0)
                {
                    guild = Context.Guild;
                }
                else
                {
                    guild = Global.Client.GetGuild(guildId);
                }

                var userAccounts      = UserAccounts.GetOrAddUserAccountsForGuild(guild.Id);
                var orderedByLvlUsers = userAccounts.OrderByDescending(acc => acc.Lvl).ToList();

                var guildAccount      = ServerAccounts.GetServerAccount(guild);
                var orderedByChannels =
                    guildAccount.MessagesReceivedStatisctic.OrderByDescending(chan => chan.Value).ToList();


                var aliveUserCount  = 0;
                var activeUserCount = 0;
                foreach (var t in userAccounts)
                {
                    if (t.Lvl > 2)
                    {
                        aliveUserCount++;
                    }
                    if (t.Lvl > 20)
                    {
                        activeUserCount++;
                    }
                }

                var adminCount = 0;
                var moderCount = 0;
                foreach (var t in userAccounts)
                {
                    var acc = guild.GetUser(t.Id);
                    if (acc == null)
                    {
                        continue;
                    }
                    if (acc.GuildPermissions.Administrator && !acc.IsBot)
                    {
                        adminCount++;
                    }
                    if (acc.GuildPermissions.DeafenMembers && acc.GuildPermissions.ManageMessages &&
                        acc.GuildPermissions.ManageChannels && !acc.IsBot)
                    {
                        moderCount++;
                    }
                }

                var rolesList       = guild.Roles.ToList();
                var orderedRoleList = rolesList.OrderByDescending(rl => rl.Members.Count()).ToList();

                var embed = new EmbedBuilder();
                embed.WithColor(Color.Blue);
                embed.WithAuthor(Context.User);
                embed.AddField($"{guild.Name} Statistic", $"**Created:** {Context.Guild.CreatedAt}\n" +
                               $"**Owner:** {Context.Guild.Owner}\n" +
                               $"**Verification Level:** {Context.Guild?.VerificationLevel}\n" +
                               $"**Users:** {Context.Guild.MemberCount}\n" +
                               $"**Alive Users:** {aliveUserCount}\n" +
                               $"**Active Users:** {activeUserCount}\n" +
                               $"**Admins:** {adminCount}\n" +
                               $"**Moderators:** {moderCount}\n");
                if (orderedByLvlUsers.Count >= 3 && orderedByChannels.Count >= 4 && orderedRoleList.Count >= 5)
                {
                    embed.AddField("**______**", "**Top 3 Active users:**\n" +
                                   $"{Context.Guild.GetUser(orderedByLvlUsers[0].Id).Mention} - {Math.Round(orderedByLvlUsers[0].Lvl, 2)} LVL\n" +
                                   $"{Context.Guild.GetUser(orderedByLvlUsers[1].Id).Mention} - {Math.Round(orderedByLvlUsers[1].Lvl, 2)} LVL\n" +
                                   $"{Context.Guild.GetUser(orderedByLvlUsers[2].Id).Mention} - {Math.Round(orderedByLvlUsers[2].Lvl, 2)} LVL\n" +
                                   "(to see all - say `top`)\n" +
                                   "(to see a user statistic say `stats @user`\n\n" +
                                   "**Top 4 Channels:**\n" +
                                   $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[0].Key)).Mention} - {orderedByChannels[0].Value} Messages\n" +
                                   $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[1].Key)).Mention} Messages\n" +
                                   $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[2].Key)).Mention} Messages\n" +
                                   $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[3].Key)).Mention} Messages\n" +
                                   $"All Messages: {guildAccount.MessagesReceivedAll}\n" +
                                   "(to see all - say `topChan`)\n\n" +
                                   "**Top 4 Roles:**\n" +
                                   $"{orderedRoleList[1]?.Mention} - {orderedRoleList[1]?.Members.Count()} Members\n" +
                                   $"{orderedRoleList[2]?.Mention} - {orderedRoleList[2]?.Members.Count()} Members\n" +
                                   $"{orderedRoleList[3]?.Mention} - {orderedRoleList[3]?.Members.Count()} Members\n" +
                                   $"{orderedRoleList[4]?.Mention} - {orderedRoleList[4]?.Members.Count()} Members\n" +
                                   "(to see all - say `topRoles`");
                }
                else
                {
                    await ReplyAsync("**ERROR**\n" +
                                     "Not everything is displayed:\n" +
                                     "You need to have at least 3 users, 4 channels with messages and 4 roles to be able to use this command correctly");
                }
                embed.AddField("**______**", $"**Text Channels Count:** {Context.Guild?.TextChannels.Count}\n" +
                               $"**Voice Channels Count:** {Context.Guild?.VoiceChannels.Count}\n" +
                               $"**All Channels and Category Count:** {Context.Guild?.Channels.Count}\n" +
                               $"**Roles Count:** {Context.Guild.Roles?.Count}\n" +
                               $"**AFK Channel:** {Context.Guild?.AFKChannel} ({Context.Guild?.AFKTimeout} Timeout)\n");
                embed.WithThumbnailUrl(guild.IconUrl);
                embed.WithCurrentTimestamp();


                await CommandHandeling.ReplyAsync(Context, embed);
            }
            catch
            {
                //   Console.WriteLine(e.Message);
            }
        }
        public static async void CheckAllBirthdays(object sender, ElapsedEventArgs e)
        {
            try
            {
                var allServersWithBirthdayRole = ServerAccounts.GetFilteredServerAccounts(s => s.BirthdayRoleId != 0);
                var timeUtcNow      = DateTime.UtcNow;
                var removeLaterList = new List <ServerSettings.BirthdayRoleActive>();

                foreach (var server in allServersWithBirthdayRole)
                {
                    var allUserAccounts = UserAccounts.GetOrAddUserAccountsForGuild(server.ServerId);

                    foreach (var t in allUserAccounts)
                    {
                        if (t.Birthday.ToString(CultureInfo.InvariantCulture) == "0001-01-01T00:00:00")
                        {
                            continue;
                        }

                        if (Global.Client.Guilds.All(x => x.Id != server.ServerId))
                        {
                            continue;
                        }

                        var globalAccount = Global.Client.GetUser(t.Id);

                        if (globalAccount == null)
                        {
                            continue;
                        }

                        var account  = UserAccounts.GetAccount(globalAccount, server.ServerId);
                        var timezone = account.TimeZone ?? "UTC";

                        try
                        {
                            var fftz = TimeZoneInfo.FindSystemTimeZoneById($"{timezone}");
                        }
                        catch
                        {
                            account.TimeZone = "UTC";
                            UserAccounts.SaveAccounts(server.ServerId);
                            Console.WriteLine($"{account.UserName} TimeZone changed to UTC");
                            continue;
                        }

                        var tz = TimeZoneInfo.FindSystemTimeZoneById($"{timezone}");

                        var timeWhenIsBirthdayByUtc = TimeZoneInfo.ConvertTimeToUtc(account.Birthday, tz);
                        var roleToGive = Global.Client.GetGuild(server.ServerId).GetRole(server.BirthdayRoleId);


                        if (roleToGive == null)
                        {
                            server.BirthdayRoleId = 0;
                            ServerAccounts.SaveServerAccounts();
                            Console.WriteLine($"Birthday Role == NULL ({server.ServerName} - {server.ServerId})");
                            return;
                        }

                        /*
                         * if(account.Id == 181514288278536193)
                         * Console.WriteLine($"account == {account.UserName}\n" +
                         *                $"timeUtcNow.Month == {timeUtcNow.Month}\n" +
                         *                $"timeWhenIsBirthdayByUtc == {timeWhenIsBirthdayByUtc.Month}\n" +
                         *                $"timeUtcNow.Day == {timeUtcNow.Day}\n" +
                         *                $"timeWhenIsBirthdayByUtc.Day == {timeWhenIsBirthdayByUtc.Day}\n" +
                         *                $"{server.BirthdayRoleList.Any(x => x.UserId != account.Id).ToString()}");
                         */

                        var check = 0;
                        foreach (var l in server.BirthdayRoleList)
                        {
                            if (l.UserId == account.Id)
                            {
                                check = 1;
                            }
                        }

                        if (timeUtcNow.Month == timeWhenIsBirthdayByUtc.Month &&
                            timeUtcNow.Day == timeWhenIsBirthdayByUtc.Day &&
                            check == 0)
                        {
                            Console.WriteLine("here");
                            await Global.Client.GetGuild(server.ServerId).GetUser(account.Id)
                            .AddRoleAsync(roleToGive);

                            var newBirthday = new ServerSettings.BirthdayRoleActive(timeUtcNow +
                                                                                    TimeSpan.ParseExact("1d",
                                                                                                        ReminderFormat.Formats,
                                                                                                        CultureInfo
                                                                                                        .CurrentCulture),
                                                                                    account.Id, account.UserName);

                            server.BirthdayRoleList.Add(newBirthday);
                            ServerAccounts.SaveServerAccounts();
                        }


                        if (server.BirthdayRoleList.Any(x => x.UserId == account.Id))
                        {
                            foreach (var v in server.BirthdayRoleList)
                            {
                                if (timeUtcNow > v.DateToRemoveRole)
                                {
                                    Console.WriteLine("removed");
                                    await Global.Client.GetGuild(server.ServerId).GetUser(v.UserId)
                                    .RemoveRoleAsync(roleToGive);

                                    removeLaterList.Add(v);
                                }
                            }
                        }
                    }
                    if (removeLaterList.Any())
                    {
                        removeLaterList.ForEach(item => server.BirthdayRoleList.Remove(item));
                        ServerAccounts.SaveServerAccounts();
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("ERROR!!! Birthday Role(Big try) Does not work: '{0}'", error);
            }
        }
        public static async void CheckPulls(object sender, ElapsedEventArgs e)
        {
            try
            {
                ulong zeroGuildId     = 0;
                var   allUserAccounts = UserAccounts.GetOrAddUserAccountsForGuild(zeroGuildId);

                foreach (var t in allUserAccounts)
                {
                    if (Global.Client.GetUser(t.Id) != null)
                    {
                        var globalAccount = Global.Client.GetUser(t.Id);
                        var account       = UserAccounts.GetAccount(globalAccount, zeroGuildId);
                        var difference    = DateTime.UtcNow - account.LastDailyPull;


                        if (difference.TotalHours > 39 && account.DailyPullPoints >= 1)
                        {
                            try
                            {
                                var dmChannel = await globalAccount.GetOrCreateDMChannelAsync();

                                var embed = new EmbedBuilder();
                                embed.WithFooter("lil octo notebook");
                                embed.WithTitle("OctoNotification");
                                embed.WithDescription("You have lost all the ponts ;c");
                                await dmChannel.SendMessageAsync("", false, embed.Build());

                                account.DailyPullPoints = 0;
                                UserAccounts.SaveAccounts(zeroGuildId);
                            }
                            catch
                            {
                                Console.WriteLine($"ERROR DM SENING {account.UserName} Closed DM");
                                account.DailyPullPoints = 0;
                                UserAccounts.SaveAccounts(zeroGuildId);
                                return;
                            }
                        }

                        if (account.DailyPullPoints >= 28)
                        {
                            var mylorikGlobal = Global.Client.GetUser(181514288278536193);
                            var mylorik       = UserAccounts.GetAccount(mylorikGlobal, zeroGuildId);

                            if (mylorik.KeyPullName != null)
                            {
                                var fullKeysNameList =
                                    mylorik.KeyPullName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                                var fullKeysKeyList =
                                    mylorik.KeyPullKey.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);


                                if (fullKeysNameList.Length == 1)
                                {
                                    Array.Resize(ref fullKeysNameList, fullKeysNameList.Length + 2);
                                    Array.Resize(ref fullKeysKeyList, fullKeysKeyList.Length + 2);

                                    fullKeysNameList[fullKeysNameList.Length - 2] = "Nothing";
                                    fullKeysNameList[fullKeysNameList.Length - 1] = "Nothing";


                                    fullKeysKeyList[fullKeysKeyList.Length - 2] = "boole?";
                                    fullKeysKeyList[fullKeysKeyList.Length - 1] = "boole?";
                                }
                                else if (fullKeysNameList.Length == 2)
                                {
                                    Array.Resize(ref fullKeysNameList, fullKeysNameList.Length + 1);
                                    Array.Resize(ref fullKeysKeyList, fullKeysKeyList.Length + 1);

                                    fullKeysNameList[fullKeysNameList.Length - 1] = "Nothing";
                                    fullKeysKeyList[fullKeysKeyList.Length - 1]   = "boole?";
                                }

                                int randonKey1;
                                int randonKey2;
                                int randonKey3;

                                do
                                {
                                    randonKey1 = SecureRandomStatic.Random(0, fullKeysNameList.Length);
                                    randonKey2 = SecureRandomStatic.Random(0, fullKeysNameList.Length);
                                    randonKey3 = SecureRandomStatic.Random(0, fullKeysNameList.Length);
                                } while (randonKey1 == randonKey2 || randonKey2 == randonKey3 ||
                                         randonKey1 == randonKey3);


                                UserAccounts.SaveAccounts(zeroGuildId);


                                var dmChannel = await globalAccount.GetOrCreateDMChannelAsync();

                                var embed = new EmbedBuilder();

                                var text =
                                    "**IMPORTANT, pelase read BEFORE cKey command:**\nIf you are NOT going to PLAY this game - please say `cKey 0`, and we will use this key to the one who WILL play the game.\n\n" +
                                    $"Choose one or zero:\nSay `cKey number`\n\n**1. {fullKeysNameList[randonKey1]}**\n**2. {fullKeysNameList[randonKey2]}**\n**3. {fullKeysNameList[randonKey3]}**\n\n**0. Nothing**\n\n" +
                                    $"Boole.\n{new Emoji("<:octo_hi:465374417644552192>")}";
                                embed.WithFooter("lil octo notebook");
                                embed.WithColor(Color.Green);
                                embed.WithTitle("You can choose a game now!");
                                embed.WithDescription(text);
                                await dmChannel.SendMessageAsync("", false, embed.Build());

                                account.PullToChoose  = null;
                                account.PullToChoose += $"{randonKey1}%%";
                                account.PullToChoose += $"{randonKey2}%%";
                                account.PullToChoose += $"{randonKey3}%%";

                                account.DailyPullPoints = 0;
                                UserAccounts.SaveAccounts(zeroGuildId);
                            }
                            else
                            {
                                var dmChannel = await globalAccount.GetOrCreateDMChannelAsync();

                                var embed = new EmbedBuilder();
                                embed.WithFooter("lil octo notebook");
                                embed.WithColor(Color.Green);
                                embed.WithTitle("OctoNotification");
                                embed.WithDescription("Booole... There is no more keys.... ;c");
                                await dmChannel.SendMessageAsync("", false, embed.Build());
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("Failed To ReadFile(CheckPulls). Will ty in 5 sec.");
            }
        }
Exemple #5
0
        public static async void ChekAllMutes(object sender, ElapsedEventArgs e)

        {
            return;

            try
            {
                var allUserAccounts = UserAccounts.GetOrAddUserAccountsForGuild(0);
                var now             = DateTime.UtcNow;

                foreach (var t in allUserAccounts)
                {
                    if (Global.Client.GetUser(t.Id) == null)
                    {
                        continue;
                    }

                    var globalAccount = Global.Client.GetUser(t.Id);
                    var account       = UserAccounts.GetAccount(globalAccount, 0);

                    if (account.MuteTimer <= now && account.MuteTimer != Convert.ToDateTime("0001-01-01T00:00:00"))
                    {
                        var roleToGive = Global.Client.GetGuild(338355570669256705).Roles
                                         .SingleOrDefault(x => x.Name.ToString() == "Muted");
                        var wtf = Global.Client.GetGuild(338355570669256705).GetUser(account.Id);
                        await wtf.RemoveRoleAsync(roleToGive);

                        await wtf.ModifyAsync(u => u.Mute = false);

                        account.MuteTimer = Convert.ToDateTime("0001-01-01T00:00:00");
                        UserAccounts.SaveAccounts(0);

                        try
                        {
                            var dmChannel = await globalAccount.GetOrCreateDMChannelAsync();

                            var embed = new EmbedBuilder();
                            embed.WithFooter("lil octo notebook");
                            embed.WithColor(Color.Red);
                            embed.WithImageUrl("https://i.imgur.com/puNz7pu.jpg");
                            embed.WithDescription($"бу-бу-бу!\nБольше так не делай, тебя размутили.");

                            await dmChannel.SendMessageAsync("", false, embed.Build());
                        }
                        catch
                        {
                            var embed = new EmbedBuilder();
                            embed.WithFooter("lil octo notebook");
                            embed.WithColor(Color.Red);
                            embed.WithImageUrl("https://i.imgur.com/puNz7pu.jpg");
                            embed.WithDescription($"бу-бу-бу!\nБольше так не делай, тебя размутили.");

                            await Global.Client.GetGuild(338355570669256705).GetTextChannel(374914059679694848)
                            .SendMessageAsync("", false, embed.Build());
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("ERROR!!! ChekAllMutes(Big try) Does not work: '{0}'", error);
            }
        }
        public static async void CheckForBirthdayRole(object sender, ElapsedEventArgs e)
        {
            try
            {
                var allUserAccounts = UserAccounts.GetOrAddUserAccountsForGuild(0);
                var now             = DateTime.UtcNow;

                foreach (var t in allUserAccounts)
                {
                    if (Global.Client.GetUser(t.Id) == null)
                    {
                        continue;
                    }


                    var globalAccount = Global.Client.GetUser(t.Id);
                    var account       = UserAccounts.GetAccount(globalAccount, 0);

                    var removeLaterList = new List <AccountSettings.CreateReminder>();

                    for (var j = 0; j < account.ReminderList?.Count; j++)
                    {
                        if (account.ReminderList[j].DateToPost > now || removeLaterList.Any(x => x.ReminderMessage == account.ReminderList[j].ReminderMessage))
                        {
                            continue;
                        }

                        try
                        {
                            var dmChannel = await globalAccount.GetOrCreateDMChannelAsync();

                            var embed = new EmbedBuilder();
                            embed.WithFooter("lil octo notebook");
                            embed.WithColor(Color.Teal);
                            embed.WithTitle("Pink turtle remindinds you:");
                            embed.WithDescription($"\n{account.ReminderList[j].ReminderMessage}");

                            await dmChannel.SendMessageAsync("", false, embed.Build());

                            removeLaterList.Add(account.ReminderList[j]);
                        }
                        catch (Exception closedDm)
                        {
                            try
                            {
                                ConsoleLogger.Log(
                                    $" [REMINDER] ({account.UserName}) - {account.ReminderList[j].ReminderMessage}",
                                    ConsoleColor.DarkBlue);
                                if (!closedDm.Message.Contains("404") || !closedDm.Message.Contains("403"))
                                {
                                    continue;
                                }
                                Console.WriteLine(
                                    $"ERROR DM SENING (TRY-CATCH DELETE) {account.UserName} Closed DM: '{0}'",
                                    closedDm);
                                account.ReminderList = new List <AccountSettings.CreateReminder>();
                                UserAccounts.SaveAccounts(0);
                                return;
                            }
                            catch
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine($"ERROR REMINDER (Catch-catch) ?????? {account.UserName}");
                                Console.ResetColor();
                            }
                        }
                    }

                    if (removeLaterList.Any())
                    {
                        removeLaterList.ForEach(item => account.ReminderList.Remove(item));
                        UserAccounts.SaveAccounts(0);
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("ERROR!!! REMINDER(Big try) Does not work: '{0}'", error);
            }
        }