Example #1
0
        public async Task UpdateAsync()
        {
            await Context.Message.DeleteAsync();

            var cats             = Context.Guild.GetCategoriesAsync().Result;
            ICategoryChannel cat = null;

            foreach (var category in cats)
            {
                if (category.Name.ToLower().Equals("globals"))
                {
                    cat = category;
                }
            }

            if (cat != null)
            {
                var dbCon = DBConnection.Instance();
                dbCon.DatabaseName = BotConfig.Load().DatabaseName;

                if (dbCon.IsConnect())
                {
                    for (int i = 0; i < ChannelData.Channels.Count; i++)
                    {
                        var chanId = ServerConfig.GetChannelId(Context.Guild.Id, ChannelData.Channels[i].IndexId, dbCon);
                        if (ServerConfig.GetChannelState(Context.Guild.Id, ChannelData.Channels[i].IndexToggle, dbCon) == false && chanId != 0)
                        {
                            var chan = await Context.Guild.GetChannelAsync(chanId);

                            if (chan != null)
                            {
                                await chan.DeleteAsync();

                                await ServerConfig.SetupChannel(Context.Guild.Id, 0, ChannelData.Channels[i].Id, dbCon);
                            }
                        }
                        else if (ServerConfig.GetChannelState(Context.Guild.Id, ChannelData.Channels[i].IndexToggle, dbCon) == true && chanId == 0)
                        {
                            var chan = await Context.Guild.CreateTextChannelAsync(ChannelData.Channels[i].Name);

                            await chan.ModifyAsync(x => x.CategoryId = cat.Id);

                            await ServerConfig.SetupChannel(Context.Guild.Id, chan.Id, ChannelData.Channels[i].Id, dbCon);
                        }
                    }

                    dbCon.Close();
                }

                var message = await Context.Channel.SendMessageAsync("Your global channels should now be updated. Please use the `!request` command in a global channel, if you have any issues.");

                await Delete.DeleteMessage(message);
            }
            else
            {
                var message = await Context.Channel.SendMessageAsync("We couldn't find the globals category in your server, I suggest deleting all the global channels and category. Then run the `!create` command.");

                await Delete.DeleteMessage(message, 25000);
            }
        }