Beispiel #1
0
        public async Task GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            // Get guilds configs stored in the database
            var result = _guildManager.GetGuildsConfigs();

            // Add them to a static dictionary <ulong guildid, GuildConfig guildconfig>
            for (int i = 0; i < result.Rows.Count; i++)
            {
                var guildId     = Convert.ToUInt64(result.Rows[i].ItemArray.GetValue(0));
                var guildConfig =
                    JsonConvert.DeserializeObject <GuildConfig>(result.Rows[i].ItemArray.GetValue(1).ToString());

                GuildConfig.Guilds.Add(guildId, guildConfig);

                // Delete guild config if the bot isn't on the server in case if the bot is off
                if (!sender.Guilds.Keys.Contains(guildId))
                {
                    _guildManager.DeleteGuildConfig(guildId);
                }
            }

            // Add guild config if the guild config isn't in the database in case if the bot is off
            foreach (var guild in sender.Guilds)
            {
                if (!GuildConfig.Guilds.ContainsKey(guild.Key))
                {
                    _guildManager.AddGuildConfig(guild.Value);
                }
            }

            Console.WriteLine($"Config rows count: {GuildConfig.Guilds.Count}");
        }
        public async Task AddUsers(GuildDownloadCompletedEventArgs e)
        {
            foreach (var guild in e.Guilds)
            {
                var guildId = GetGuildIdByUid(guild.Value.Id);
                foreach (var user in guild.Value.Members)
                {
                    try
                    {
                        await connection.OpenAsync();

                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection  = connection;
                        cmd.CommandText = $"INSERT INTO `guilds.users` (discordId, discordName, guildId, notes) "
                                          + $" values (?, ?, ?, 'auto add') "
                                          + $" ON DUPLICATE KEY UPDATE discordId=discordId";
                        cmd.Parameters.Add("discordId", MySqlDbType.VarChar).Value   = Convert.ToString(user.Id);
                        cmd.Parameters.Add("discordName", MySqlDbType.VarChar).Value = Convert.ToString(user.Username);
                        cmd.Parameters.Add("guildId", MySqlDbType.Int16).Value       = guildId;
                        await cmd.ExecuteNonQueryAsync();

                        await connection.CloseAsync();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
            Console.WriteLine("UserAdd done!");
        }
Beispiel #3
0
 private async Task GuildDone(GuildDownloadCompletedEventArgs e)
 {
     timer = new System.Threading.Timer(
         async e => await Check(), null, TimeSpan.Zero, TimeSpan.FromMinutes(10)
         );
     Console.WriteLine("[Timer] Created.");
 }
Beispiel #4
0
        private async Task Client_GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            sender.Logger.LogInformation($"Guild download completed.");

            // Run managers.
            await _voiceManager.Init();
        }
Beispiel #5
0
 private async Task Client_Ready(DiscordClient sender, GuildDownloadCompletedEventArgs e)
 {
     await Client.UpdateStatusAsync(new DiscordActivity(
                                        $"over {e.Guilds.Values.First(x => x.Name.Contains("Coins")).MemberCount} members",
                                        ActivityType.Watching),
                                    UserStatus.Online);
 }
        private Task Discord_GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            this.Services.GetRequiredService <FeedTimerService>().Start();

            sender.Logger.LogInformation(LogEvent, "All guilds are now available", DateTime.Now);
            return(Task.CompletedTask);
        }
Beispiel #7
0
        private async Task Client_GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            sender.Logger.LogInformation("Guild download completed");

            // Run managers' init processes.
            await _voiceManager.DeleteAllUnusedVoiceChannelsAsync();
        }
Beispiel #8
0
        private async Task Ready(GuildDownloadCompletedEventArgs e)
        {
            Console.WriteLine("[Bot Started]");
            var pairs  = Program.pairs;
            var client = e.Client;
            var Config = Program.Config;

            if (pairs.Count > 0)
            {
                Console.WriteLine("[Reading Previous Suggestions] Started");
                var guild = await client.GetGuildAsync(Config.MasterId);

                foreach (var pair in pairs)
                {
                    try
                    {
                        Console.WriteLine($"[Reading Previous Suggestions] {pair.Name}");
                        var ich = await client.GetChannelAsync(pair.InputPair);

                        var och = await client.GetChannelAsync(pair.OutputPair);

                        var hundred = await ich.GetMessagesAsync();

                        var list = hundred.ToList();
                        foreach (var msg in list)
                        {
                            if (!String.IsNullOrWhiteSpace(msg.Content))
                            {
                                Suggestion s = new Suggestion(msg);
                                if (s.Image.HasValue && s.Links.Count > 0 && msg.Reactions.Count > 0)
                                {
                                    var ppbusg3h = DiscordEmoji.FromName(e.Client, ":+1:");
                                    if (msg.Reactions.Any(z => z.Emoji == ppbusg3h))
                                    {
                                        List <DiscordUser> reacts = new List <DiscordUser>();
                                        reacts = (await(await ich.GetMessageAsync(msg.Id)).GetReactionsAsync(ppbusg3h)).ToList();

                                        if (reacts.Any(x => ((guild.GetMemberAsync(x.Id).Result).Roles.Any(y => y.Permissions.HasPermission(Permissions.ManageRoles)) && x != client.CurrentUser)))
                                        {
                                            await och.SendFileAsync(s.Image.Value, embed : EmbedBase.SuggestionEmbed(s));

                                            await msg.DeleteAsync();
                                        }
                                    }
                                }
                            }
                        }
                        Console.WriteLine($"[Reading Previous Suggestions] {pair.Name} <COMPLETED>");
                    }
                    catch (Exception ex)
                    {
                        StringBuilder data = new StringBuilder();
                        Console.WriteLine($"[EX <{ex.Message}> @ Sug.cs : Ready] \n\t{ex}");
                    }
                }
            }
        }
Beispiel #9
0
        private Task _discordClient_GuildsDownloaded(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            _ = Task.Run(async() =>
            {
                await HookToLastMessageAsync();
                await AddUnhandedReactionRolesAsync();
            });

            return(Task.CompletedTask);
        }
Beispiel #10
0
        internal static Task Client_GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs _1)
        {
            _ = Task.Run(async() =>
            {
                BaseService.InitAll(sender);

                int added           = 0;
                UserRepository repo = new UserRepository(ReadConfig.Config.ConnectionString);

                bool result = repo.GetAll(out List <User> list);
                if (!result)
                {
                    _ = DiscordObjectService.Instance.ErrorLogChannel.SendMessageAsync("Error getting all users in database.");
                    return;
                }
                IReadOnlyCollection <DiscordMember> allMembers = await DiscordObjectService.Instance.Lathland.GetAllMembersAsync();
                IEnumerable <DiscordMember> toAdd = allMembers.Where(x => !list.Any(y => y.DcID == x.Id));
                foreach (var item in toAdd)
                {
                    User entity = new User {
                        DcID = item.Id
                    };
                    DiscordMember mem = await DiscordObjectService.Instance.Lathland.GetMemberAsync(item.Id);
                    result            = repo.Create(ref entity);
                    if (!result)
                    {
                        _ = DiscordObjectService.Instance.ErrorLogChannel.SendMessageAsync($"Error adding user {item.DisplayName}#{item.Discriminator} ({item.Id}) to the database");
                        continue;
                    }
                    _ = DiscordObjectService.Instance.TimerChannel.SendMessageAsync($"Added user {mem.DisplayName}#{mem.Discriminator} ({mem.Id}) on startup");
                    added++;
                }
                bool res = repo.CountAll(out int allInDb);
                string strAllInDb;
                if (!res)
                {
                    await DiscordObjectService.Instance.ErrorLogChannel.SendMessageAsync("Error counting all users in database");
                    strAllInDb = "unknown";
                }
                else
                {
                    strAllInDb = allInDb.ToString();
                }
                await DiscordObjectService.Instance.TimerChannel.SendMessageAsync(
                    added > 0 ?
                    $"Added {added} Users, {strAllInDb} entries in database, {DiscordObjectService.Instance.Lathland.MemberCount} members in guild." :
#if DEBUG
                    "Test configuration startup completed");
#else
                    "Startup completed");
#endif
            });
            return(Task.CompletedTask);
        }
Beispiel #11
0
 private static Task Discord_GuilddownloadCompleted(GuildDownloadCompletedEventArgs e)
 {
     //var guild = e.Client.Guilds.First().Value;
     //var channels = guild.Channels.Where(x => x.Value.Type == ChannelType.Voice);
     //var vnext = DiscordClient.GetVoiceNext();
     //var vnc = vnext.GetConnection(guild);
     //var chn = channels.First().Value;
     ////var chn = await DiscordClient.GetDefaultVoiceChannelAsync();
     //vnext.ConnectAsync(chn);
     return(Task.CompletedTask);
 }
Beispiel #12
0
        private Task _discordClient_GuildsDownloaded(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            var channel = _discordClient.FindChannel(_config.MessageHistoryChannel);

            if (channel.Type == ChannelType.Text)
            {
                _textChannel = channel;
            }

            return(Task.CompletedTask);
        }
Beispiel #13
0
        private Task _discordClient_GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            _ = Task.Run(async() =>
            {
                foreach (var(_, guild) in _discordClient.Guilds)
                {
                    await guild.RequestMembersAsync(presences: true, nonce: Environment.TickCount.ToString());
                }
            });

            return(Task.CompletedTask);
        }
Beispiel #14
0
        private Task Client_GuildDownloadComplete(DiscordClient c, GuildDownloadCompletedEventArgs e)
        {
            c.Logger.LogInformation($"Guild Download completed for shard {c.ShardId}");

            if (e.Guilds.ContainsKey(PbCfg !.HomeGuild))
            {
                c.Logger.LogInformation("Starting Guild Verification Service.");
                StartedVerify = true;
                _             = Task.Run(() => this._verify.Start());
            }

            return(Task.CompletedTask);
        }
Beispiel #15
0
        private Task _discordClient_GuildsDownloaded(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            _ = Task.Run(async() =>
            {
                _textChannel = await _discordClient.GetChannelAsync(_config.RolesChannelId);

                await LoadExistingRoleEmbedsAsync();
                await SendRoleEmbedsAsync();

                await VerifyCurrentUserRolesAsync();
            });

            return(Task.CompletedTask);
        }
Beispiel #16
0
        private Task _discordClient_GuildsDownloaded(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            _ = Task.Run(async() =>
            {
                UpdateTextChannel();

                // Enter and lock the semaphore, incase this occurs simultaneously with updating streams
                await semaphoreSlimLock.WaitAsync();
                var messages = (await _textChannel.GetMessagesAsync()).ToList();
                await TryParseExistingEmbedsAsync(messages);
                semaphoreSlimLock.Release();

                // When reconnects occur, this will stack update events
                // Therefore, dispose every time
                if (_intervalFunctionTimer != null)
                {
                    await _intervalFunctionTimer.DisposeAsync();
                }

                _intervalFunctionTimer = new Timer(UpdateCurrentStreamersAsync, null, TimeSpan.Zero, _updateInterval);
            });

            return(Task.CompletedTask);
        }
Beispiel #17
0
 private static Task DiscordClient_GuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
 {
     _ = Task.Run(() =>
     {
         var guildInfos   = e.Guilds.Select(async g => await GetGuildInfo(g.Value)).Select(t => t.Result);
         string guildInfo = string.Join("\n", guildInfos);
         _discordClient.Logger.LogInformation($"Guild Download Complete:\n{guildInfo}");
     });
     return(Task.CompletedTask);
 }
        /// <summary>
        /// Load voice channels from the database on start up.
        /// </summary>
        private async Task OnGuildDownloadCompleted(DiscordClient sender, GuildDownloadCompletedEventArgs e)
        {
            _client.GuildDownloadCompleted -= OnGuildDownloadCompleted;

            await CatchUpAsync();
        }
Beispiel #19
0
 private Task Client_GuildDownloadCompleted(GuildDownloadCompletedEventArgs e)
 => this._guildDownloadCompleted.InvokeAsync(e);
Beispiel #20
0
        public static Task GuildDownloadCompletedEventHandlerAsync(FreudShard shard, GuildDownloadCompletedEventArgs e)
        {
            shard.Log(LogLevel.Info, $"All guilds are now available.");

            return(Task.CompletedTask);
        }
Beispiel #21
0
 private async Task GuildDownloadCompleted(DiscordClient c, GuildDownloadCompletedEventArgs e)
 {
     this.logger.Information("Client downloaded all guilds successfully.");
 }
Beispiel #22
0
 async Task OnGuildDownloadComplete(DiscordClient sender, GuildDownloadCompletedEventArgs e)
 {
     await AttemptRebuildVoiceRegisteredGuildDataAsync(sender);
 }
Beispiel #23
0
 private Task Discord_GuildDownloadCompleted(GuildDownloadCompletedEventArgs e)
 {
     this.Discord.DebugLogger.LogMessage(LogLevel.Debug, "DPS Test", "All guilds are now downloaded.", DateTime.Now);
     return(Task.CompletedTask);
 }
Beispiel #24
0
        public async Task BotGuildsDownloaded(GuildDownloadCompletedEventArgs e)
        {
            try
            {
                foreach (var guild in e.Guilds)
                {
                    Console.WriteLine($"{guild.Value.Name} loading");
                    await connection.OpenAsync();

                    try
                    {
                        MySqlCommand guildcmd = new MySqlCommand
                        {
                            Connection  = connection,
                            CommandText = $"INSERT INTO `guilds` (`guildID`, `guildName`, `guildDefaultInvite`, `guildOwner`) VALUES (?, ?, NULL, ?) ON DUPLICATE KEY UPDATE guildOwner=guildOwner"
                        };
                        guildcmd.Parameters.Add("guildID", MySqlDbType.Int64).Value     = guild.Value.Id;
                        guildcmd.Parameters.Add("guildName", MySqlDbType.VarChar).Value = guild.Value.Name;
                        guildcmd.Parameters.Add("guildOwner", MySqlDbType.Int64).Value  = guild.Value.Owner.Id;
                        await guildcmd.ExecuteNonQueryAsync();

                        GuildsList.Add(guild.Value.Id, new Guilds
                        {
                            GuildName          = guild.Value.Name,
                            GuildDefaultInvite = null,
                            GuildOwner         = guild.Value.Owner.Id,
                            GuildMembers       = new Dictionary <ulong, Members>(),
                            ChannelConfig      = new ChannelConfig(),
                            ModuleConfig       = new ModuleConfig()
                        });
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    } //Guild Top
                    try
                    {
                        MySqlCommand guildcmd = new MySqlCommand
                        {
                            Connection  = connection,
                            CommandText = $"INSERT INTO `guilds.config` (`guildID`, `ruleChannelID`, `infoChannelID`, `cmdChannelID`, `logChannelID`, `roleID`, `customInfo`) VALUES (?, 0, 0, 0, 0, 0, ?) ON DUPLICATE KEY UPDATE ruleChannelID=ruleChannelID"
                        };
                        guildcmd.Parameters.Add("guildID", MySqlDbType.Int64).Value      = guild.Value.Id;
                        guildcmd.Parameters.Add("customInfo", MySqlDbType.VarChar).Value = "to be filled";
                        await guildcmd.ExecuteNonQueryAsync();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    } //Guild Chan Conf
                    await connection.CloseAsync();

                    await connection.OpenAsync();

                    try
                    {
                        MySqlCommand guildcmd = new MySqlCommand
                        {
                            Connection  = connection,
                            CommandText = $"SELECT * FROM `guilds.config` WHERE `guildID` = {guild.Value.Id}"
                        };
                        var reader = await guildcmd.ExecuteReaderAsync();

                        while (await reader.ReadAsync())
                        {
                            GuildsList[guild.Value.Id].ChannelConfig = (new ChannelConfig
                            {
                                RuleChannelID = Convert.ToUInt64(reader["ruleChannelId"]),
                                InfoChannelID = Convert.ToUInt64(reader["infoChannelId"]),
                                CmdChannelID = Convert.ToUInt64(reader["cmdChannelId"]),
                                LogChannelID = Convert.ToUInt64(reader["logChannelID"]),
                                RoleID = Convert.ToUInt64(reader["roleID"]),
                                CustomInfo = reader["customInfo"].ToString()
                            });
                        }
                        reader.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    } //Guild Channel Config Get
                    try
                    {
                        MySqlCommand guildcmd = new MySqlCommand
                        {
                            Connection  = connection,
                            CommandText = $"INSERT INTO `modules.config` (`guildID`, `adminModule`, `greetModule`, `birthdayModule`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE adminModule=adminModule"
                        };
                        guildcmd.Parameters.Add("guildID", MySqlDbType.Int64).Value        = guild.Value.Id;
                        guildcmd.Parameters.Add("adminModule", MySqlDbType.Int16).Value    = 0;
                        guildcmd.Parameters.Add("greetModule", MySqlDbType.Int16).Value    = 0;
                        guildcmd.Parameters.Add("birthdayModule", MySqlDbType.Int16).Value = 0;
                        await guildcmd.ExecuteNonQueryAsync();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    } //Module Conf
                    await connection.CloseAsync();

                    await connection.OpenAsync();

                    try
                    {
                        MySqlCommand guildcmd = new MySqlCommand
                        {
                            Connection  = connection,
                            CommandText = $"SELECT * FROM `modules.config` WHERE `guildID` = {guild.Value.Id}"
                        };
                        var reader = await guildcmd.ExecuteReaderAsync();

                        while (await reader.ReadAsync())
                        {
                            GuildsList[guild.Value.Id].ModuleConfig = new ModuleConfig
                            {
                                AdminModule    = Convert.ToBoolean(reader["adminModule"]),
                                GreetModule    = Convert.ToBoolean(reader["greetModule"]),
                                BirthdayModule = Convert.ToBoolean(reader["birthdayModule"])
                            };
                        }
                        reader.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    } //Guild Module Config Get
                    await connection.CloseAsync();

                    await connection.OpenAsync();

                    try
                    {
                        MySqlCommand guildcmd = new MySqlCommand
                        {
                            Connection  = connection,
                            CommandText = $"SELECT * FROM `modules.greet` WHERE `guildID` = {guild.Value.Id}"
                        };
                        var reader = await guildcmd.ExecuteReaderAsync();

                        while (await reader.ReadAsync())
                        {
                            GuildsList[guild.Value.Id].ModuleConfig.GreetMessages.Add(new GreetMessages
                            {
                                AnnounceString = reader["announceString"].ToString()
                            });
                        }
                        reader.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex);
                        Console.WriteLine(ex.StackTrace);
                    } //Get Annouce
                    foreach (var emoji in guild.Value.Emojis)
                    {
                        try
                        {
                            MySqlCommand cmd = new MySqlCommand
                            {
                                Connection  = connection,
                                CommandText = $"INSERT INTO `guilds.emotes` (`guildID`, `emoteID`, `emoteURL`, `emoteName`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE emoteName=emoteName"
                            };
                            cmd.Parameters.Add("guildID", MySqlDbType.Int64).Value     = guild.Value.Id;
                            cmd.Parameters.Add("emoteID", MySqlDbType.Int64).Value     = emoji.Id;
                            cmd.Parameters.Add("emoteURL", MySqlDbType.VarChar).Value  = emoji.Url;
                            cmd.Parameters.Add("emoteName", MySqlDbType.VarChar).Value = emoji.Name;
                            await cmd.ExecuteNonQueryAsync();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    foreach (var user in guild.Value.Members)
                    {
                        try
                        {
                            MySqlCommand cmd = new MySqlCommand
                            {
                                Connection  = connection,
                                CommandText = $"INSERT INTO `guilds.users` (`userID`, `userName`, `userDiscriminator`, `Birthdate`, `changeDate`) VALUES (?, ?, ?, NULL, CURRENT_TIMESTAMP) ON DUPLICATE KEY UPDATE userName=userName"
                            };
                            cmd.Parameters.Add("userID", MySqlDbType.Int64).Value              = user.Id;
                            cmd.Parameters.Add("userName", MySqlDbType.VarChar).Value          = user.Username;
                            cmd.Parameters.Add("userDiscriminator", MySqlDbType.VarChar).Value = user.Discriminator;
                            await cmd.ExecuteNonQueryAsync();

                            GuildsList[guild.Value.Id].GuildMembers.Add(user.Id, new Members
                            {
                                UserName          = user.Username,
                                UserDiscriminator = user.Discriminator,
                                BdaySent          = false
                            });
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    await connection.CloseAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            Console.WriteLine("UserAdd done!");

            DiscordActivity startActivity = new DiscordActivity
            {
                Name         = "Type $help for help pages and $author for author information",
                ActivityType = ActivityType.Playing
            };
            await Client.UpdateStatusAsync(activity : startActivity, userStatus : UserStatus.Online, idleSince : null);
        }
Beispiel #25
0
        private Task GuildDownloadCompleted(GuildDownloadCompletedEventArgs e)
        {
            _logger.Information("Client downloaded all guilds successfully.");

            return(Task.CompletedTask);
        }
 public static Task GuildDownloadCompletedEventHandlerAsync(TheGodfatherBot bot, GuildDownloadCompletedEventArgs e)
 {
     Log.Information("All guilds are now downloaded ({Count} total)", e.Guilds.Count);
     return(Task.CompletedTask);
 }
Beispiel #27
0
 private async Task Client_GuildDownloadCompleted(GuildDownloadCompletedEventArgs e)
 {
     await Update();
 }
Beispiel #28
0
 private Task Discord_GuildDownloadCompleted(GuildDownloadCompletedEventArgs e)
 {
     e.Client.DebugLogger.LogMessage(LogLevel.Info, LOG_TAG, "All guilds are now available", DateTime.Now);
     return(Task.CompletedTask);
 }
Beispiel #29
0
 private Task Discord_GuildDownloadCompleted(DiscordClient client, GuildDownloadCompletedEventArgs e)
 {
     client.Logger.LogDebug(TestBotEventId, "Guild download completed");
     return(Task.CompletedTask);
 }
Beispiel #30
0
 private Task Event_GuildDownloadCompleted(DiscordClient d, GuildDownloadCompletedEventArgs e)
 {
     d.Logger.LogDebug(BotEventId, "Event_GuildDownloadCompleted.");
     return(Task.CompletedTask);
 }