Пример #1
0
        private bool HaveRole(SocketGuildUser user, ServerUserControl usercontrol)
        {
            if (usercontrol.Getcombobox() == "@everyone" || string.IsNullOrWhiteSpace(usercontrol.Getcombobox()))
            {
                return(true);
            }
            else
            {
                bool ok = false;
                foreach (SocketRole role in user.Roles)
                {
                    if (usercontrol.Getcombobox() == role.Name)
                    {
                        ok = true;
                    }
                }

                return(ok);
            }
        }
Пример #2
0
        private async Task _client_Connected()
        {
            Activate();
            Console.WriteLine("Connected");

            IReadOnlyCollection <SocketGuild> guilds = MainClass._client.Guilds;

            Console.WriteLine("Number of guilds " + guilds.Count);
            foreach (SocketGuild guild in guilds)
            {
                SocketGuild sok = MainClass._client.GetGuild(guild.Id);

                sok.DownloadUsersAsync().Wait(500);


                Console.WriteLine(sok.Name);
                ServerUserControl usercontrol = new ServerUserControl();
                if (!string.IsNullOrWhiteSpace(sok.IconUrl))
                {
                    using (WebClient wc = new WebClient())
                    {
                        byte[] imagebyte = wc.DownloadData(sok.IconUrl);
                        using (MemoryStream ms = new MemoryStream(imagebyte))
                        {
                            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                            usercontrol.SetImage(img);
                        }
                    }
                }

                usercontrol.SetComboBox("@everyone");
                usercontrol.SetRoles(sok.Roles);
                usercontrol.SetText(sok.Name);
                usercontrol.SetGuild(sok);

                AddToFlowLayout(usercontrol);
            }
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            List <ulong> discorduser = new List <ulong>();

            discorduser.Add(447041400995840000);
            foreach (UserControl us in flowLayoutPanel1.Controls)
            {
                ServerUserControl server = (ServerUserControl)us;
                if (server.Checkbox())
                {
                    SocketGuild socket = server.GetGuild();
                    IReadOnlyCollection <SocketGuildUser> users = socket.Users;
                    int    i     = 0;
                    int    count = users.Count;
                    Random rnd   = new Random();

                    if (server.Getcombobox() == "HALF-MEMBERS")
                    {
                        SocketGuildUser user = users.ElementAt(rnd.Next(0, count));

                        if (i < count / 2)
                        {
                            if (!discorduser.Contains(user.Id))
                            {
                                discorduser.Add(user.Id);
                                user.SendMessageAsync(textBox1.Text);
                                i++;
                            }
                        }
                    }
                    else
                    {
                        foreach (SocketGuildUser user in users)
                        {
                            if (server.Getcombobox() == "New-Members")
                            {
                                DateTimeOffset usertime       = (DateTimeOffset)user.JoinedAt;
                                DateTimeOffset currentime     = DateTime.Now;
                                double         differencedays = (currentime.DateTime - usertime.DateTime).TotalDays;
                                double         timeselected   = Convert.ToDouble(server.GetCombobox2());


                                if (!discorduser.Contains(user.Id))
                                {
                                    if (differencedays < timeselected)
                                    {
                                        discorduser.Add(user.Id);
                                        user.SendMessageAsync(textBox1.Text);
                                    }
                                }
                            }
                            else
                            {
                                if (!discorduser.Contains(user.Id) && HaveRole(user, server))
                                {
                                    Console.WriteLine(user.Id + " " + user.JoinedAt);
                                    discorduser.Add(user.Id);
                                    user.SendMessageAsync(textBox1.Text);
                                }
                            }
                        }
                    }
                }
                textBox1.Text = "";
            }
        }