예제 #1
0
        public async Task TopByOctoPoints(int page = 1)
        {
            try
            {
                if (page < 1)
                {
                    await SendMessAsync(
                        "Boole! Try different page <_<");

                    return;
                }

                var currentGuildUsersId = Context.Guild.Users.Select(user => user.Id);
                var accounts            = _accounts.GetAllAccount();

                const int usersPerPage = 9;

                var lastPage = 1 + accounts.Count / (usersPerPage + 1);
                if (page > lastPage)
                {
                    await SendMessAsync(
                        $"Boole. Last Page is {lastPage}");

                    return;
                }

                var ordered = accounts.OrderByDescending(acc => acc.Points).ToList();

                var embB = new EmbedBuilder()
                           .WithTitle("Top By Octo Points:")
                           .WithFooter(
                    $"Page {page}/{lastPage} ● Say \"topp 2\" to see second page (you can edit previous message)");


                page--;
                for (var j = 0; j < ordered.Count; j++)
                {
                    if (ordered[j].Id == Context.User.Id)
                    {
                        embB.WithDescription(
                            $"**#{j + usersPerPage * page + 1} {Context.User.Username} {ordered[j].Points} OctoPoints**\n**______**");
                    }
                }

                for (var i = 1; i <= usersPerPage && i + usersPerPage * page <= ordered.Count; i++)
                {
                    var account = ordered[i - 1 + usersPerPage * page];
                    var user    = _global.Client.GetUser(account.Id);
                    embB.AddField($"#{i + usersPerPage * page} {user.Username}", $"{account.Points} OctoPoints", true);
                }

                await SendMessAsync(embB);
            }
            catch
            {
                //   await ReplyAsync(
                //       "boo... An error just appear >_< \nTry to use this command properly: **topp [page_number]**(Top By Activity)\nAlias: topo");
            }
        }
예제 #2
0
        private void CheckToDeleteVoice(object sender, ElapsedEventArgs e)
        {
            var allUserAccounts = _accounts.GetAllAccount();

            foreach (var t in allUserAccounts)
            {
                try
                {
                    var globalAccount = _global.Client.GetUser(t.DiscordId);
                    var account       = _accounts.GetAccount(globalAccount);
                    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>();


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

                            var newVoice = new AccountSettings.CreateVoiceChannel(DateTime.UtcNow.AddHours(10),
                                                                                  voiceChan.Id, voiceChan.Guild.Id);
                            newHolder.VoiceChannelList.Add(newVoice);

                            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
                {
                    //
                }
            }
        }
예제 #3
0
        public async void CheckForReminder(object sender, ElapsedEventArgs e)
        {
            try
            {
                var allUserAccounts = _accounts.GetAllAccount();
                var now             = DateTime.UtcNow;

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


                    var globalAccount = _global.Client.GetUser(t.DiscordId);
                    var account       = _accounts.GetAccount(globalAccount);

                    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
                            {
                                _log.Error(
                                    $" [REMINDER] ({account.UserName}) - {account.ReminderList[j].ReminderMessage}");
                                if (!closedDm.Message.Contains("404") || !closedDm.Message.Contains("403"))
                                {
                                    continue;
                                }
                                account.ReminderList = new List <AccountSettings.CreateReminder>();

                                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));
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("ERROR!!! REMINDER(Big try) Does not work: '{0}'", error);
            }
        }