Ejemplo n.º 1
0
        public async Task ArchiveChannel([Remainder] IGuildChannel channel)
        {
            //First we need to move channel
            var cat = await Context.Guild.GetCategoriesAsync();

            ICategoryChannel category = cat.Where(x => x.Id == 548238743476240405).FirstOrDefault();

            if (category == null)
            {
                return;
            }

            //Move it now
            await channel.ModifyAsync(x => x.CategoryId = category.Id);

            //Get role overwrites
            var everyoneOverwrite = category.GetPermissionOverwrite(Context.Guild.EveryoneRole);
            var adminOverwrite    = category.GetPermissionOverwrite(Context.Guild.GetRole(217696310168518657));

            //First remove all perms
            var curPerms = channel.PermissionOverwrites;

            foreach (Overwrite ow in curPerms)
            {
                if (ow.TargetType == PermissionTarget.Role)
                {
                    await channel.RemovePermissionOverwriteAsync(Context.Guild.GetRole(ow.TargetId));
                }
                else
                {
                    await channel.RemovePermissionOverwriteAsync(await Context.Guild.GetUserAsync(ow.TargetId));
                }
            }

            //Okay now we set perms
            await channel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, everyoneOverwrite.Value);

            await channel.AddPermissionOverwriteAsync(Context.Guild.GetRole(217696310168518657), adminOverwrite.Value);

            //Will add an output
            await Context.Channel.SendSuccessAsync($"The channel {channel.Name} has been archived.");
        }
Ejemplo n.º 2
0
        public async Task ArchiveProject()
        {
            ICategoryChannel ProjectsCategory = CommandHelper.FindCategory(Context.Guild.CategoryChannels, Strings.ProjectCategoryName);
            ICategoryChannel ArchiveCategory  = CommandHelper.FindCategory(Context.Guild.CategoryChannels, Strings.ArchiveCategoryName);

            if (((ITextChannel)Context.Channel).CategoryId != ProjectsCategory.Id)
            {
                await ReplyAsync("This channel is not a project channel!");

                return;
            }

            if (ArchiveCategory is null) //Create the category
            {
                ArchiveCategory = await Context.Guild.CreateCategoryChannelAsync(Strings.ArchiveCategoryName);

                await ArchiveCategory.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new OverwritePermissions(sendMessages : PermValue.Deny));
            }

            await((IGuildChannel)Context.Channel).ModifyAsync(delegate(GuildChannelProperties ac) { ac.CategoryId = ArchiveCategory.Id; });

            List <ITextChannel> channels = new List <ITextChannel>(Context.Guild.TextChannels);

            channels.RemoveAll(x => x.CategoryId != ArchiveCategory.Id);
            channels.Add((ITextChannel)Context.Channel);

            await CommandHelper.OrderChannels(channels, ArchiveCategory.Id);

            IRole ProjectRole        = CommandHelper.FindRole(Context.Guild.Roles, Context.Channel.Name);
            IRole ProjectManagerRole = CommandHelper.FindRole(Context.Guild.Roles, $"{Context.Channel.Name}-Manager");

            await Context.Guild.GetRole(ProjectRole.Id).DeleteAsync();

            await Context.Guild.GetRole(ProjectManagerRole.Id).DeleteAsync();

            await ReplyAsync("Archived project and cleared role!");

            await((IGuildChannel)Context.Channel).AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, (OverwritePermissions)ArchiveCategory.GetPermissionOverwrite(Context.Guild.EveryoneRole));
        }