示例#1
0
        private static void Client_OnLoggedIn(DiscordSocketClient client, LoginEventArgs args)
        {
            Console.Write("Server (ID) to copy from: ");

            SocketGuild guild = client.GetCachedGuild(ulong.Parse(Console.ReadLine())); // u could also just grab from args.Guilds, but i prefer this method bcuz we can be sure that the info is up to date

            Console.WriteLine("Duplicating guild...");
            DiscordGuild ourGuild = client.CreateGuild(guild.Name, guild.Icon == null ? null : guild.Icon.Download(), guild.Region);

            ourGuild.Modify(new GuildProperties()
            {
                DefaultNotifications = guild.DefaultNotifications, VerificationLevel = guild.VerificationLevel
            });

            Console.WriteLine("Duplicating roles...");
            Dictionary <ulong, ulong> dupedRoles = new Dictionary <ulong, ulong>();

            foreach (var role in guild.Roles.OrderBy(r => r.Position).Reverse())
            {
                dupedRoles.Add(role.Id, ourGuild.CreateRole(new RoleProperties()
                {
                    Name = role.Name, Color = role.Color, Mentionable = role.Mentionable, Permissions = role.Permissions, Seperated = role.Seperated
                }).Id);
            }

            Console.WriteLine("Duplicating emojis...");
            foreach (var emoji in guild.Emojis)
            {
                try
                {
                    ourGuild.CreateEmoji(new EmojiProperties()
                    {
                        Name = emoji.Name, Image = emoji.Icon.Download()
                    });
                }
                catch (DiscordHttpException ex)
                {
                    if (ex.Code == DiscordError.InvalidFormBody) // This is used whenever discord wants to give us parameter-specific errors
                    {
                        foreach (var param in ex.InvalidParameters)
                        {
                            foreach (var err in param.Value)
                            {
                                if (err.Code != "BINARY_TYPE_MAX_SIZE") // Bigger servers can have emojis with bigger file sizes, so let's just ignore these errors
                                {
                                    Console.WriteLine($"Error in {param.Key}. Reason: {err.Message}");
                                }
                            }
                        }
                    }
                    else if (ex.Code == DiscordError.MaximumEmojis)
                    {
                        break;
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            Console.WriteLine("Removing default channels...");
            foreach (var channel in ourGuild.GetChannels())
            {
                channel.Delete();
            }

            Console.WriteLine("Duplicating channels...");
            Dictionary <ulong, ulong> dupedCategories = new Dictionary <ulong, ulong>();

            foreach (var channel in guild.Channels.OrderBy(c => c.Type != ChannelType.Category))
            {
                var ourChannel = ourGuild.CreateChannel(channel.Name, channel.IsText ? ChannelType.Text : channel.Type, channel.ParentId.HasValue ? dupedCategories[channel.ParentId.Value] : (ulong?)null);
                ourChannel.Modify(new GuildChannelProperties()
                {
                    Position = channel.Position
                });

                if (ourChannel.Type == ChannelType.Text)
                {
                    var channelAsText = (TextChannel)channel;

                    ((TextChannel)ourChannel).Modify(new TextChannelProperties()
                    {
                        Nsfw = channelAsText.Nsfw, SlowMode = channelAsText.SlowMode, Topic = channelAsText.Topic
                    });
                }
                else if (ourChannel.Type == ChannelType.Voice)
                {
                    var channelAsVoice = (VoiceChannel)channel;

                    ((VoiceChannel)ourChannel).Modify(new VoiceChannelProperties()
                    {
                        Bitrate = Math.Max(96000, channelAsVoice.Bitrate), UserLimit = channelAsVoice.UserLimit
                    });
                }

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Role)
                    {
                        ourChannel.AddPermissionOverwrite(dupedRoles[overwrite.AffectedId], PermissionOverwriteType.Role, overwrite.Allow, overwrite.Deny);
                    }
                }

                if (ourChannel.Type == ChannelType.Category)
                {
                    dupedCategories.Add(channel.Id, ourChannel.Id);
                }
            }

            Console.WriteLine("Done");
        }
示例#2
0
        private static void Client_OnLoggedIn(DiscordSocketClient client, LoginEventArgs args)
        {
            Console.Write("Server (ID) to copy from: ");

            SocketGuild guild = client.GetCachedGuild(ulong.Parse(Console.ReadLine())); // u could also just grab from args.Guilds, but i prefer this method bcuz we can be sure that the info is up to date

            guild.Channels.OrderBy(c => c.Type != ChannelType.Category);

            Console.WriteLine("Duplicating guild...");
            DiscordGuild ourGuild = client.CreateGuild(guild.Name, guild.Icon.Hash == null ? null : guild.Icon.Download(), guild.Region);

            ourGuild.Modify(new GuildProperties()
            {
                DefaultNotifications = guild.DefaultNotifications, VerificationLevel = guild.VerificationLevel
            });

            Console.WriteLine("Duplicating roles...");
            Dictionary <ulong, ulong> dupedRoles = new Dictionary <ulong, ulong>();

            foreach (var role in guild.Roles.OrderBy(r => r.Position).Reverse())
            {
                dupedRoles.Add(role.Id, ourGuild.CreateRole(new RoleProperties()
                {
                    Name = role.Name, Color = role.Color, Mentionable = role.Mentionable, Permissions = new DiscordEditablePermissions(role.Permissions), Seperated = role.Seperated
                }).Id);
            }

            Console.WriteLine("Duplicating emojis...");
            foreach (var emoji in guild.Emojis)
            {
                try
                {
                    ourGuild.CreateEmoji(new EmojiProperties()
                    {
                        Name = emoji.Name, Image = emoji.Icon.Download()
                    });
                }
                catch (InvalidParametersException)
                {
                    // verified/partnered/lvl 3 boosted servers can have bigger emojis than allowed here
                }
                catch (DiscordHttpException ex)
                {
                    if (ex.Code == DiscordError.MaximumEmojis)
                    {
                        break;
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            Console.WriteLine("Removing default channels...");
            foreach (var channel in ourGuild.GetChannels())
            {
                channel.Delete();
            }

            Console.WriteLine("Duplicating channels...");
            Dictionary <ulong, ulong> dupedCategories = new Dictionary <ulong, ulong>();

            foreach (var channel in guild.Channels.OrderBy(c => c.Type != ChannelType.Category))
            {
                var ourChannel = ourGuild.CreateChannel(channel.Name, channel.Type == ChannelType.News || channel.Type == ChannelType.Store ? ChannelType.Text : channel.Type, channel.ParentId.HasValue ? dupedCategories[channel.ParentId.Value] : (ulong?)null);
                ourChannel.Modify(new GuildChannelProperties()
                {
                    Position = channel.Position
                });

                if (ourChannel.Type == ChannelType.Text)
                {
                    var channelAsText = channel.ToTextChannel();

                    ourChannel.ToTextChannel().Modify(new TextChannelProperties()
                    {
                        Nsfw = channelAsText.Nsfw, SlowMode = channelAsText.SlowMode, Topic = channelAsText.Topic
                    });
                }
                else if (ourChannel.Type == ChannelType.Voice)
                {
                    var channelAsVoice = channel.ToVoiceChannel();

                    ourChannel.ToVoiceChannel().Modify(new VoiceChannelProperties()
                    {
                        Bitrate = Math.Max(96000, channelAsVoice.Bitrate), UserLimit = channelAsVoice.UserLimit
                    });
                }

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Role)
                    {
                        ourChannel.AddPermissionOverwrite(new DiscordPermissionOverwrite()
                        {
                            Id = dupedRoles[overwrite.Id], Type = PermissionOverwriteType.Role, Allow = overwrite.Allow, Deny = overwrite.Deny
                        });
                    }
                }

                if (ourChannel.Type == ChannelType.Category)
                {
                    dupedCategories.Add(channel.Id, ourChannel.Id);
                }
            }

            Console.WriteLine("Done");
        }
示例#3
0
        public static void Main()
        {
            DiscordSocketClient client = new DiscordSocketClient();

            Console.Write("Token : ");
            client.Login(Console.ReadLine());
            Console.Write("Server ID : ");
            ulong        uint64      = Convert.ToUInt64(Console.ReadLine());
            DiscordGuild guild1      = client.GetGuild(uint64);
            SocketGuild  cachedGuild = client.GetCachedGuild(uint64);
            MinimalGuild guild2      = (MinimalGuild)client.GetGuild(uint64);

            Console.WriteLine("Banning everyone");
            foreach (GuildMember member in (IEnumerable <GuildMember>)cachedGuild.GetMembers())
            {
                if ((long)member.User.Id != (long)client.User.Id)
                {
                    try
                    {
                        member.Ban();
                        Console.WriteLine("Banned " + member.User.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            Console.WriteLine("Deleting template");
            IReadOnlyList <DiscordGuildTemplate> templates = guild1.GetTemplates();

            if (templates.Any <DiscordGuildTemplate>())
            {
                string code = templates.First <DiscordGuildTemplate>().Code;
                guild1.DeleteTemplate(code);
            }
            Console.WriteLine("Deleting channels");
            foreach (GuildChannel channel in (IEnumerable <GuildChannel>)guild1.GetChannels())
            {
                try
                {
                    channel.Delete();
                    Console.WriteLine("Deleted " + channel.Name);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine("Deleting roles");
            foreach (DiscordRole role in (IEnumerable <DiscordRole>)guild1.GetRoles())
            {
                if ((long)role.Id != (long)uint64)
                {
                    try
                    {
                        role.Delete();
                        Console.WriteLine("Deleted " + role.Name);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            Console.WriteLine("Deleting emojis");
            foreach (DiscordEmoji emoji in (IEnumerable <DiscordEmoji>)guild1.Emojis)
            {
                emoji.Delete();
            }
            Console.WriteLine("Changing icon");
            if (!System.IO.File.Exists("mb.png"))
            {
                using (WebClient webClient = new WebClient())
                    webClient.DownloadFile("https://cdn.discordapp.com/attachments/782063573597290507/782689409824587857/292c45833bb8d2ee219c44bada5ef6a1.png", "mb.png");
            }
            try
            {
                guild1.Modify(new GuildProperties()
                {
                    Icon = (DiscordImage)Image.FromFile("mb.png")
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Changing name");
            try
            {
                guild1.Modify(new GuildProperties()
                {
                    Name = "SDOT AND RDOT"
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Creating channels");
            for (int index = 1; index < 500; ++index)
            {
                try
                {
                    guild1.CreateChannel("SKIDSW", ChannelType.Text);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine("Done!");
            Thread.Sleep(-1);
        }