public async Task ConfigureAsyc()
        {
            Assembly a = Assembly.GetExecutingAssembly();
            await _commands.AddModulesAsync(a);

            await _updater.UpdateObservers("ConfigureAsyc run");
        }
Exemple #2
0
        private async Task Client_Ready()
        {
            await Client.SetGameAsync("scrubs like you");

            await Console.UpdateObservers("Bot connected");

            await Console.UpdateObservers("can connect to");

            using (var db = new BotDbContext())
            {
                if (GuildUpdate != null)
                {
                    foreach (var guild in Client.Guilds)
                    {
                        try
                        {
                            var dbguild = db.Guilds.SingleOrDefault(g => g.GuildId == (long)guild.Id);
                            if (dbguild == null)
                            {
                                dbguild = new Guild()
                                {
                                    GuildId   = (long)guild.Id,
                                    GuildName = guild.Name
                                };
                                dbguild = db.Guilds.Add(dbguild);
                                await Console.UpdateObservers($"Added guild: {dbguild.GuildName} to db");
                            }
                            else
                            {
                                dbguild.GuildName = guild.Name;
                            };
                            foreach (SocketTextChannel channel in guild.TextChannels)
                            {
                                var dbchannel = dbguild.GuildChannels.SingleOrDefault(c => c.ChannelId == (long)channel.Id);
                                if (dbchannel == null)
                                {
                                    dbchannel = new Channel
                                    {
                                        ChannelId = (long)channel.Id,
                                        Name      = channel.Name
                                    };
                                    dbguild.GuildChannels.Add(dbchannel);
                                    await Console.UpdateObservers($"Added channel: {dbchannel.Name} to db");
                                }
                                else
                                {
                                    dbchannel.Name = channel.Name;
                                }
                                await Console.UpdateObservers($"Added {dbguild.GuildName} > {dbchannel.Name} has {dbchannel.ChannelCommands.Count} commands");
                            }
                            await db.SaveChangesAsync();

                            await GuildUpdate.UpdateObservers(db.Guilds.ToList());
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e);
                        }
                    }
                }
            }
            //var data = await (new FileData("Config/GuildConfig.json")).GetObjectFromJson<BotConfig>();
            // console.UpdateObservers($"{guild.Name} channel count {guild.Channels.Count} id {guild.Id}");
        }