public Updater(bool force = false) { InitializeComponent(); string lastVersion, downloadURL; using (var client = new System.Net.WebClient()) { client.Headers.Add("User-Agent", "TwitchBot"); client.Encoding = Encoding.UTF8; string git_ingo = client.DownloadString("https://api.github.com/repos/ScriptedEngineer/AutoUpdater/releases"); lastVersion = Extentions.RegexMatch(git_ingo, @"""tag_name"":""([^""]*)"""); downloadURL = Extentions.RegexMatch(git_ingo, @"""browser_download_url"":""([^""]*)"""); } bool updaterNeedUpdate = true; if (File.Exists(UpdaterPath)) { var versionInfo = FileVersionInfo.GetVersionInfo(UpdaterPath); updaterNeedUpdate = Extentions.CheckVersion(lastVersion, versionInfo.ProductVersion); } if (updaterNeedUpdate) { Status.Content = "Загрузка..."; WebClient web = new WebClient(); web.DownloadFileAsync(new Uri(downloadURL), UpdaterPath); web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); web.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); } else { DownloadFileCompleted(this, null); } }
private void WSock_OnMessage(object sender, MessageEventArgs e) { Match RGX = Regex.Match(e.Data, @"\""authRequired\""\:\s(\w*),"); if (RGX.Success) { bool.TryParse(RGX.Groups[1]?.Value, out bool xds); if (xds) { string challenge = Regex.Match(e.Data, @"\""challenge\""\:\s\""([^""]*)\""").Groups[1]?.Value; string salt = Regex.Match(e.Data, @"\""salt\""\:\s\""([^""]*)\""").Groups[1]?.Value; using (SHA256Managed sha = new SHA256Managed()) { string saltedhashedpass = Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(MySave.Current.OBSWSPass + salt))); string finaly = Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(saltedhashedpass + challenge))); MSGID++; WSock.Send(@"{""request-type"":""Authenticate"",""auth"":""" + finaly + @""",""message-id"":""-1""}"); } } MSGID++; WSock.Send(@"{""request-type"":""SetHeartbeat"",""enable"":false,""message-id"":""" + MSGID + @"""}"); //Console.WriteLine(xds.ToString()); } else { Match sdgk = Regex.Match(e.Data, @"\""error\""\:\s\""([^""]*)\"""); if (sdgk.Success) { string msghf = sdgk.Groups[1]?.Value; if (!msghf.Contains("already")) { Extentions.AsyncWorker(() => MainWindow.CurrentW.OBSRstatus.Content = "Проблема с OBS(" + msghf + ")"); } } else { Match sdgk2 = Regex.Match(e.Data, @"\""message-id\""\:\s\""([^""]*)\"""); Match sdgk1 = Regex.Match(e.Data, @"\""status\""\:\s\""([^""]*)\"""); if (sdgk2.Groups[1]?.Value == "-1" && sdgk1.Groups[1]?.Value == "ok") { Extentions.AsyncWorker(() => MainWindow.CurrentW.OBSRstatus.Content = "OBS Подключен"); } } } /*else * { * Match HBT = Regex.Match(e.Data, @"\""update-type\""\:\s\""([^""]*)\"""); * if (HBT.Success && HBT.Groups[1]?.Value == "Heartbeat") * { * CurrentScene = Regex.Match(e.Data, @"\""current-scene\""\:\s\""([^""]*)\""").Groups[1]?.Value; * } * } * Console.WriteLine(e.Data);*/ }
private void WSock_OnClose(object sender, CloseEventArgs e) { Extentions.AsyncWorker(() => { if (MainWindow.CurrentW.OBSRstatus.Content.ToString() == "OBS Подключен") { MainWindow.CurrentW.OBSRstatus.Content = "Соединение с OBS было разорвано"; } else { MainWindow.CurrentW.OBSRstatus.Content = "Не удалось подключится к OBS"; } }); Thread.Sleep(1000); Extentions.AsyncWorker(() => { MainWindow.CurrentW.OBSRstatus.Content = "Переподключение через 3..."; }); Thread.Sleep(1000); Extentions.AsyncWorker(() => { MainWindow.CurrentW.OBSRstatus.Content = "Переподключение через 2..."; }); Thread.Sleep(1000); Extentions.AsyncWorker(() => { MainWindow.CurrentW.OBSRstatus.Content = "Переподключение через 1..."; }); Thread.Sleep(1000); Extentions.AsyncWorker(() => { MainWindow.CurrentW.OBSRstatus.Content = "Подключение..."; }); while (!(WSock != null && WSock.IsAlive)) { WSock = new WebSocket($"ws://localhost:{MySave.Current.OBSWSPort}/"); WSock.OnMessage += WSock_OnMessage; WSock.OnClose += WSock_OnClose; WSock.OnOpen += WSock_OnOpen; WSock.Connect(); Thread.Sleep(1000); } }
public static int RunCommand(string command, int index = 0, string[] script = null)//, int max { try { string[] param = command.Split(' '); if (param.Count() < 1) { return(index); } switch (param[0]) { case "Mouse": switch (param[1]) { case "Down": UserInput.MouseButton ClickR; Enum.TryParse(param[2], out ClickR); UserInput.MouseButtonEvent(ClickR, UserInput.ButtonEvents.Down); break; case "Click": UserInput.MouseButton Click; Enum.TryParse(param[2], out Click); UserInput.MouseClick(Click); break; case "Up": UserInput.MouseButton ClickN; Enum.TryParse(param[2], out ClickN); UserInput.MouseButtonEvent(ClickN, UserInput.ButtonEvents.Up); break; case "Scroll": if (!int.TryParse(param[2], out int Yg)) { return(index); } WinApi.MouseEvent(WinApi.MouseEventFlags.Wheel, Yg); break; case "Move": if (!int.TryParse(param[2], out int X)) { return(index); } if (!int.TryParse(param[3], out int Y)) { return(index); } UserInput.MouseMove(X, Y); break; case "Set": if (!int.TryParse(param[2], out int Xa)) { return(index); } if (!int.TryParse(param[3], out int Ya)) { return(index); } UserInput.SetMouse(Xa, Ya); break; } break; case "Button": switch (param[1]) { case "Down": { WinApi.Vk X = 0; if (int.TryParse(param[2], out int Kb)) { X = (WinApi.Vk)Kb; } else { Enum.TryParse("VK_" + param[3], out X); } UserInput.ButtonEvent(X, UserInput.ButtonEvents.Down); } break; case "Click": { WinApi.Vk X = 0; if (int.TryParse(param[2], out int Kb)) { X = (WinApi.Vk)Kb; } else { Enum.TryParse("VK_" + param[2], out X); } UserInput.ButtonEvent(X, UserInput.ButtonEvents.Down); UserInput.ButtonEvent(X, UserInput.ButtonEvents.Up); } break; case "Up": { WinApi.Vk X = 0; if (byte.TryParse(param[2], out byte Kb)) { X = (WinApi.Vk)Kb; } else { Enum.TryParse("VK_" + param[3], out X); } UserInput.ButtonEvent(X, UserInput.ButtonEvents.Up); } break; } break; case "ChangeLayout": UserInput.ButtonEvent(WinApi.Vk.VK_LMENU, UserInput.ButtonEvents.Down); UserInput.ButtonEvent(WinApi.Vk.VK_LSHIFT, UserInput.ButtonEvents.Down); UserInput.ButtonEvent(WinApi.Vk.VK_LSHIFT, UserInput.ButtonEvents.Up); UserInput.ButtonEvent(WinApi.Vk.VK_LMENU, UserInput.ButtonEvents.Up); break; case "Screen": switch (param[1]) { case "On": WinApi.SetEnableScreen(true); break; case "Off": WinApi.SetEnableScreen(false); break; } break; case "Rights": { string nick = param[2].ToLower().Trim(); string right = param[3].ToLower().Trim(); switch (param[1]) { case "Add": if (!MySave.UsersRights.ContainsKey(nick)) { MySave.UsersRights.Add(nick, (UserRights)Enum.Parse(typeof(UserRights), right)); } else { MySave.UsersRights[nick] |= (UserRights)Enum.Parse(typeof(UserRights), right); } break; case "Del": if (!MySave.UsersRights.ContainsKey(nick)) { MySave.UsersRights.Add(nick, UserRights.Зритель); } else { MySave.UsersRights[nick] &= ~(UserRights)Enum.Parse(typeof(UserRights), right); } break; } } break; case "TmpRights": { string nick = param[2].ToLower().Trim(); string right = param[3].ToLower().Trim(); switch (param[1]) { case "Add": if (!MySave.TmpUsersRights.ContainsKey(nick)) { MySave.TmpUsersRights.Add(nick, (UserRights)Enum.Parse(typeof(UserRights), right)); } else { MySave.TmpUsersRights[nick] |= (UserRights)Enum.Parse(typeof(UserRights), right); } break; case "Del": if (!MySave.TmpUsersRights.ContainsKey(nick)) { MySave.TmpUsersRights.Add(nick, UserRights.Зритель); } else { MySave.TmpUsersRights[nick] &= ~(UserRights)Enum.Parse(typeof(UserRights), right); } break; } } break; case "Speech": lock (Extentions.SpeechSynth) { Extentions.TextToSpeech(Regex.Replace(command, "^Speech ", " ").Trim()); while (Extentions.SpeechSynth.State == SynthesizerState.Speaking) { Thread.Sleep(100); } } break; case "TTS": lock (Extentions.SpeechSynth) { string Text = Regex.Replace(command, "^TTS ", " ").Trim(); Extentions.GetTrueTTSReady(Text, MySave.Current.YPV.ToString()); Extentions.TrueTTS(Text); } break; case "CMD": { RunConsole(Regex.Replace(command, "^CMD ", "").Trim()); } break; case "Play": lock (Extentions.SpeechSynth) { Extentions.AsyncWorker(() => { Extentions.Player.Open(new Uri(Regex.Replace(command, "^Play ", " ").Trim(), UriKind.Absolute)); Extentions.Player.Play(); }); Thread.Sleep(1200); Thread.Sleep(MainWindow.CurrentW.MediaDurationMs); } break; case "OBS": switch (param[1]) { case "Source": switch (param[2]) { case "On": OBSWebSock.SetSourceEnabled(Regex.Replace(command, "^OBS Source On ", "").Trim(), true); break; case "Off": OBSWebSock.SetSourceEnabled(Regex.Replace(command, "^OBS Source Off ", "").Trim(), false); break; case "Rotation": { string[] rc = Regex.Replace(command, "^OBS Source Rotation ", "").Trim().Split('.'); if (rc.Length >= 2) { OBSWebSock.SetSourceRotation(rc[0].Trim(), rc[1].Trim()); } } break; case "Position": { string[] rc = Regex.Replace(command, "^OBS Source Position ", "").Trim().Split('.'); if (rc.Length >= 3) { OBSWebSock.SetSourcePosition(rc[0].Trim(), rc[1].Trim(), rc[2].Trim()); } } break; case "Scale": { string[] rc = Regex.Replace(command, "^OBS Source Scale ", "").Trim().Split('.'); if (rc.Length >= 3) { OBSWebSock.SetSourceScale(rc[0].Trim(), rc[1].Trim(), rc[2].Trim()); } } break; } break; case "Audio": switch (param[2]) { case "On": OBSWebSock.SetSourceMute(Regex.Replace(command, "^OBS Audio On ", "").Trim(), true); break; case "Off": OBSWebSock.SetSourceMute(Regex.Replace(command, "^OBS Audio Off ", "").Trim(), false); break; } break; case "Scene": { OBSWebSock.SetScene(Regex.Replace(command, "^OBS Scene ", "").Trim()); } break; case "Transition": { OBSWebSock.SendTransition(); } break; } break; case "Send": MainWindow.Client.SendMessage(Regex.Replace(command, "^Send ", " ").Trim()); break; case "Wait": { if (int.TryParse(param[1], out int Kb)) { Thread.Sleep(Kb); } } break; //Многострочные команды case "Timer": string[] heh = command.Trim().Split(new char[] { ' ' }, 3); if (heh.Length > 2) { Match mtch = Regex.Match(heh[2], @"\s(\d+)$"); string count = mtch.Groups.Count > 1 ? mtch.Groups[1].Value:"0"; heh[2] = heh[2].ToLower().Replace(count, "").Trim(); WebSockServ.SendAll("timer.Add", heh[1], heh[2]); if (script != null) { int.TryParse(count, out int kek); string SubScript = ""; for (int i = 0; i < kek; i++) { index++; if (index < script.Length) { SubScript += script[index] + "\n"; } } if (!TimersEnds.ContainsKey(heh[2])) { TimersEnds.Add(heh[2], SubScript); } else { TimersEnds[heh[2]] = SubScript; } } } break; case "Random": if (int.TryParse(param[1], out int rnd) && script != null) { int random = Extentions.TrueRandom(1, rnd) + index; RunCommand(script[random]); index += rnd; } break; } } catch //(Exception e) { //Console.WriteLine(e.Message); } return(index); }
public static string WebRequestу(HttpListenerRequest request) { switch (request.RawUrl.Split('?').First().Trim('/')) { case "alert": return("<script>location.replace('http://wsxz.ru/twitchbot/alerts');</script>"); case "timer": return("<script>location.replace('https://wsxz.ru/twitchbot/timers');</script>"); case "control": return("NO"); case "twitchcode": return("<script>location.replace('http://*****:*****@"""access_token"":""([^""]*)"".*""refresh_token"":""([^""]*)"""); try { MyEncription.SaveCryptoFile("donation_alerts_token.encoded", Rgex.Groups[1].Value, Rgex.Groups[2].Value); new Task(() => { Thread.Sleep(500); Extentions.AsyncWorker(() => { Process.Start(Extentions.AppFile); Application.Current.Shutdown(); }); }).Start(); } catch { } } catch (WebException e) { WebResponse response = e.Response; Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); //Console.WriteLine(readStream.ReadToEnd()); } // }).Start(); return("<script>location.replace('https://wsxz.ru/closetab');</script>"); default: return("Not found"); } }
static public int RunCommand(string command, int index, int max) { try { string[] param = command.Split(' '); if (param.Count() < 1) { return(index); } switch (param[0]) { case "Mouse": switch (param[1]) { case "Down": UserInput.MouseButton ClickR; Enum.TryParse(param[2], out ClickR); UserInput.MouseButtonEvent(ClickR, UserInput.ButtonEvents.Down); break; case "Click": UserInput.MouseButton Click; Enum.TryParse(param[2], out Click); UserInput.MouseClick(Click); break; case "Up": UserInput.MouseButton ClickN; Enum.TryParse(param[2], out ClickN); UserInput.MouseButtonEvent(ClickN, UserInput.ButtonEvents.Up); break; case "Scroll": if (!int.TryParse(param[2], out int Yg)) { return(index); } WinApi.MouseEvent(WinApi.MouseEventFlags.Wheel, Yg); break; case "Move": if (!int.TryParse(param[2], out int X)) { return(index); } if (!int.TryParse(param[3], out int Y)) { return(index); } UserInput.MouseMove(X, Y); break; case "Set": if (!int.TryParse(param[2], out int Xa)) { return(index); } if (!int.TryParse(param[3], out int Ya)) { return(index); } UserInput.SetMouse(Xa, Ya); break; } break; case "Button": switch (param[1]) { case "Down": { WinApi.Vk X = 0; if (int.TryParse(param[2], out int Kb)) { X = (WinApi.Vk)Kb; } else { Enum.TryParse("VK_" + param[3], out X); } UserInput.ButtonEvent(X, UserInput.ButtonEvents.Down); } break; case "Click": { WinApi.Vk X = 0; if (int.TryParse(param[2], out int Kb)) { X = (WinApi.Vk)Kb; } else { Enum.TryParse("VK_" + param[2], out X); } UserInput.ButtonEvent(X, UserInput.ButtonEvents.Down); UserInput.ButtonEvent(X, UserInput.ButtonEvents.Up); } break; case "Up": { WinApi.Vk X = 0; if (byte.TryParse(param[2], out byte Kb)) { X = (WinApi.Vk)Kb; } else { Enum.TryParse("VK_" + param[3], out X); } UserInput.ButtonEvent(X, UserInput.ButtonEvents.Up); } break; } break; case "ChangeLayout": UserInput.ButtonEvent(WinApi.Vk.VK_LMENU, UserInput.ButtonEvents.Down); UserInput.ButtonEvent(WinApi.Vk.VK_LSHIFT, UserInput.ButtonEvents.Down); UserInput.ButtonEvent(WinApi.Vk.VK_LSHIFT, UserInput.ButtonEvents.Up); UserInput.ButtonEvent(WinApi.Vk.VK_LMENU, UserInput.ButtonEvents.Up); break; case "Screen": switch (param[1]) { case "On": WinApi.SetEnableScreen(true); break; case "Off": WinApi.SetEnableScreen(false); break; } break; case "Rights": { string nick = param[2].ToLower().Trim(); string right = param[3].ToLower().Trim(); switch (param[1]) { case "Add": if (!MySave.UsersRights.ContainsKey(nick)) { MySave.UsersRights.Add(nick, (UserRights)Enum.Parse(typeof(UserRights), right)); } else { MySave.UsersRights[nick] |= (UserRights)Enum.Parse(typeof(UserRights), right); } break; case "Del": if (!MySave.UsersRights.ContainsKey(nick)) { MySave.UsersRights.Add(nick, UserRights.Зритель); } else { MySave.UsersRights[nick] &= ~(UserRights)Enum.Parse(typeof(UserRights), right); } break; } } break; case "TmpRights": { string nick = param[2].ToLower().Trim(); string right = param[3].ToLower().Trim(); switch (param[1]) { case "Add": if (!MySave.TmpUsersRights.ContainsKey(nick)) { MySave.TmpUsersRights.Add(nick, (UserRights)Enum.Parse(typeof(UserRights), right)); } else { MySave.TmpUsersRights[nick] |= (UserRights)Enum.Parse(typeof(UserRights), right); } break; case "Del": if (!MySave.TmpUsersRights.ContainsKey(nick)) { MySave.TmpUsersRights.Add(nick, UserRights.Зритель); } else { MySave.TmpUsersRights[nick] &= ~(UserRights)Enum.Parse(typeof(UserRights), right); } break; } } break; case "Speech": lock (Extentions.SpeechSynth) { Extentions.TextToSpeech(Regex.Replace(command, "^Speech ", " ").Trim()); while (Extentions.SpeechSynth.State == SynthesizerState.Speaking) { Thread.Sleep(100); } } break; case "TTS": lock (Extentions.SpeechSynth) { string Text = Regex.Replace(command, "^TTS ", " ").Trim(); Extentions.GetTrueTTSReady(Text, MySave.Current.YPV.ToString()); Extentions.TrueTTS(Text); } break; case "CMD": { RunConsole(Regex.Replace(command, "^CMD ", "").Trim()); } break; case "Play": lock (Extentions.SpeechSynth) { Extentions.AsyncWorker(() => { Extentions.Player.Open(new Uri(Regex.Replace(command, "^Play ", " ").Trim(), UriKind.Absolute)); Extentions.Player.Play(); }); Thread.Sleep(1200); Thread.Sleep(MainWindow.CurrentW.MediaDurationMs); } break; case "OBS": switch (param[1]) { case "Source": switch (param[2]) { case "On": OBSWebSock.SetSourceEnabled(Regex.Replace(command, "^OBS Source On ", "").Trim(), true); break; case "Off": OBSWebSock.SetSourceEnabled(Regex.Replace(command, "^OBS Source Off ", "").Trim(), false); break; case "Rotation": { string[] rc = Regex.Replace(command, "^OBS Source Rotation ", "").Trim().Split('.'); if (rc.Length >= 2) { OBSWebSock.SetSourceRotation(rc[0].Trim(), rc[1].Trim()); } } break; case "Position": { string[] rc = Regex.Replace(command, "^OBS Source Position ", "").Trim().Split('.'); if (rc.Length >= 3) { OBSWebSock.SetSourcePosition(rc[0].Trim(), rc[1].Trim(), rc[2].Trim()); } } break; } break; case "Scene": { OBSWebSock.SetScene(Regex.Replace(command, "^OBS Scene ", "").Trim()); } break; } break; case "Send": MainWindow.Client.SendMessage(Regex.Replace(command, "^Send ", " ").Trim()); break; case "Wait": { if (int.TryParse(param[1], out int Kb)) { Thread.Sleep(Kb); } } break; } } catch (Exception e) { Console.WriteLine(e.Message); } return(index); }