public static T FromUrl <T>(string url)
 {
     using var jsonReq = new JsonWebRequest <T>(url)
           {
               AllowRetryOnTimeout = true
           };
     jsonReq.AddHeader("user-agent", "osu!ude");
     jsonReq.AddHeader("referer", "https://zhzi233.cn");
     jsonReq.Perform();
     return(jsonReq.ResponseObject);
 }
Beispiel #2
0
        protected dynamic GetJsonFromApi(string request)
        {
            using var req = new JsonWebRequest <dynamic>($"{Program.ENDPOINT_CONFIGURATION.APIEndpointUrl}/api/v2/{request}");

            req.AddHeader(System.Net.HttpRequestHeader.Authorization.ToString(), $"Bearer {apiAccessToken}");
            req.Perform();

            return(req.ResponseObject);
        }
Beispiel #3
0
        private static void Main()
        {
            var currentDirectory  = new NativeStorage(".");
            var solutionDirectory = new NativeStorage("..");

            currentDirectory.DeleteDirectory("./staging");

            if (!Directory.Exists("releases"))
            {
                Directory.CreateDirectory("releases");
            }

            var stagingDirectory = currentDirectory.GetStorageForDirectory("staging");
            var currentDate      = DateTime.Now.ToString("yyyy.Mdd.");

            currentDate += currentDirectory.GetDirectories("releases").Count(s => s.Contains(currentDate));

            var releaseDirectory = currentDirectory.GetStorageForDirectory($"./releases/App-{currentDate}");

            Console.WriteLine($"Package: Qsor");
            Console.WriteLine($"Release Version: {currentDate}");
            Console.WriteLine($"Release Directory: {releaseDirectory.GetFullPath(".")}");
            Console.WriteLine($"Changelog: \n{ChangelogGenerator.GenerateChangelog()}");

            var logo = solutionDirectory.GetFullPath("Qsor.Game/Resources/Textures/Logo-256x256.png");
            var icon = solutionDirectory.GetFullPath("Qsor.Desktop/icon.ico");

            RunCommand("dotnet", $"publish -f netcoreapp3.1 Qsor.Desktop --configuration Release --runtime win-x64 -p:Version={currentDate} -o {stagingDirectory.GetFullPath(".")}",
                       solutionDirectory.GetFullPath("."));

            RunCommand("./tools/rcedit-x64.exe", $"\"{stagingDirectory.GetFullPath(".")}\\Qsor.exe\" --set-icon \"{icon}\"");

            RunCommand(NugetPath, $"pack Qsor.Desktop/qsor.nuspec -Version {currentDate} -Properties Configuration=Release -OutputDirectory {stagingDirectory.GetFullPath(".")} -BasePath {stagingDirectory.GetFullPath(".")}",
                       solutionDirectory.GetFullPath("."));

            RunCommand(SquirrelPath, $"--releasify {stagingDirectory.GetFullPath($"./Qsor.{currentDate}.nupkg")} --releaseDir {releaseDirectory.GetFullPath(".")} --no-msi --icon {icon} --setupIcon {icon} --loadingGif {logo}",
                       stagingDirectory.GetFullPath("."));

            RunCommand("git", $"tag {currentDate}");
            RunCommand("git", $"push origin {currentDate}");

            File.Move(releaseDirectory.GetFullPath("Setup.exe"), releaseDirectory.GetFullPath("install.exe"));

            stagingDirectory.DeleteDirectory(".");

            var req = new JsonWebRequest <GitHubRelease>($"https://api.github.com/repos/Mempler/Qsor/releases")
            {
                Method = HttpMethod.Post,
            };

            Console.WriteLine($"Creating release {currentDate}...");

            req.AddRaw(JsonConvert.SerializeObject(new GitHubRelease
            {
                Name  = currentDate,
                Draft = true,
                Body  = ChangelogGenerator.GenerateChangelog()
            }));

            req.AddHeader("Authorization", $"token {GithubAccessToken}");
            req.Perform();

            var targetRelease = req.ResponseObject;

            var assetUploadUrl = targetRelease.UploadUrl.Replace("{?name,label}", "?name={0}");

            foreach (var a in Directory.GetFiles(releaseDirectory.GetFullPath(".")).Reverse())
            {
                if (Path.GetFileName(a).StartsWith('.'))
                {
                    continue;
                }

                Console.WriteLine($"- Pushing asset {a}...");
                var upload = new WebRequest(assetUploadUrl, Path.GetFileName(a))
                {
                    Method      = HttpMethod.Post,
                    Timeout     = 240000,
                    ContentType = "application/octet-stream",
                };

                upload.AddRaw(File.ReadAllBytes(a));
                upload.AddHeader("Authorization", $"token {GithubAccessToken}");
                upload.Perform();
            }
        }
Beispiel #4
0
        public DialogWindow()
        {
            InitializeComponent();

            messageTextBox.PreviewKeyDown += MessageTextBox_PreviewKeyDown;
            chatListBox.DoubleClick       += ChatListBox_DoubleClick;


            singleton = this;

            channelTextBox.Text = BotEntry.Channel;

            UsernameTextBox.Text = BotEntry.Config.Get <string>(Config.BotSetting.Username);
            Token = OAuthToken.Parse(BotEntry.Config.Get <string>(Config.BotSetting.SuperSecretSettings));
            OATokenTextBox.Text         = Token.AccessToken ?? string.Empty;
            botChannelTextBox.Text      = BotEntry.ChatBotChannel.Value;
            BotEntry.NonCommandMessage += (IRCClient.ChannelMessageEventArgs msg) =>
            {
                Actions.Add(() =>
                {
                    foreach (string s in CommandsListBox.Items)
                    {
                        var arr = s.Split('⇒');
                        if (arr[0][0] != '!')
                        {
                            if (msg.Message.ToLower().Contains('!' + arr[0].ToLower()))
                            {
                                string output = arr[1].Replace("{username}", msg.Badge.DisplayName);
                                output        = output.Replace("{channel}", msg.Channel);
                                output        = output.Replace("{message}", msg.Message);
                                BotEntry.client.SendMessage(msg.Channel, output);
                                Logger.Log($"[GENERIC] [{arr[0]}] command executed for |{msg.Badge.DisplayName}|");
                            }
                        }
                        else
                        if (msg.Message.ToLower().Contains(arr[0].ToLower()))
                        {
                            string output = arr[1].Replace("{username}", msg.Badge.DisplayName);
                            output        = output.Replace("{channel}", msg.Channel);
                            output        = output.Replace("{message}", msg.Message);
                            BotEntry.client.SendMessage(msg.Channel, output);
                            Logger.Log($"[GENERIC] [{arr[0]}] command executed for |{msg.Badge.DisplayName}|");
                        }
                    }
                });
            };

            BotEntry.client.RoomStateChanged += (s, b) =>
            {
                Actions.Add(() =>
                {
                    if (BotEntry.client.CurrentChannelBadge != null && b == BotEntry.client.CurrentChannelBadge)
                    {
                        var areq = new JsonWebRequest <RoomModels>($"https://api.twitch.tv/kraken/chat/{BotEntry.client.CurrentChannelBadge.ChannelID}/rooms")
                        {
                            Method = HttpMethod.GET
                        };
                        areq.AddHeader("Accept", "application/vnd.twitchtv.v5+json");
                        areq.AddHeader("Client-ID", "i5ezz567chrsv4rzal4l9q7kuuq9qv");
                        areq.AddHeader("Authorization", "OAuth 5egkvsbduc7frz4lbhyw4u239bv7sr");

                        areq.Finished += () =>
                        {
                            //var str = areq.ResponseString;

                            Actions.Add(() =>
                            {
                                chatRoomsListBox.Items.Clear();
                                foreach (var it in areq.ResponseObject.Rooms)
                                {
                                    chatRoomsListBox.Items.Add(it);
                                }
                            });
                        };
                        areq.Failed += (e) =>
                        {
                            ExceptionExtensions.Rethrow(e);
                        };

                        areq.PerformAsync();
                    }
                });
            };

            BotEntry.client.OnConnect += (s, e) =>
            {
                Actions.Add(() =>
                {
                    connectionStateLabel.Text = $"Connected";
                    connectButton.Text        = $"Disconnect";
                    connectButton.Enabled     = true;
                    this.Text = "Twitch bot API. State: [Connected]";
                });
            };

            BotEntry.client.ConnectionClosed += (s, e) =>
            {
                Actions.Add(() =>
                {
                    connectButton.Enabled     = true;
                    connectButton.Text        = $"Connect";
                    connectionStateLabel.Text = "Disconnected";
                    this.Text = "Twitch bot API. State: Disconnected";
                });
            };

            if (BotEntry.client.Connected)
            {
                connectionStateLabel.Text = $"Connected";
                connectButton.Text        = $"Disconnect";
                connectButton.Enabled     = true;
                this.Text = "Twitch bot API. State: [Connected]";
            }
        }