Esempio n. 1
0
        private void CmdReAuthenticate_Click(object sender, EventArgs e)
        {
            File.Move("./creds.json", "creds.json.old");
            frmCredentials credForm = new frmCredentials();

            if (credForm.ShowDialog(this) == DialogResult.OK)
            {
                //MessageBox.Show("Restart the bot for the changes to take effect.");
                var tempvars = JsonConvert.DeserializeObject <creds>(File.ReadAllText("creds.json"));
                ChannelToMod = tempvars.channeltomod;
                browser.Load("https://www.twitch.tv/popout/" + ChannelToMod + "/chat?popout=");
                UpdateViewerList.Interval = 1;
            }
            else
            {
                File.Move("creds.json.old", "./creds.json");
                DialogResult dialogResult = MessageBox.Show("Your credentials were not changed.", "", MessageBoxButtons.OK);
            }

            if (File.Exists("creds.json"))
            {
                File.Delete("creds.json.old");
            }
        }
Esempio n. 2
0
        private void frmKruBot_Load(object sender, EventArgs e)
        {
            if (File.Exists("creds.json.old"))
            {
                DialogResult dialogResult = MessageBox.Show("We detected that your credentials were in the middle of being replaced. Recover?", "Recover Credentials?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    if (File.Exists("creds.json")) // Stops an error when both .old and .json exist (rare case)
                    {
                        File.Delete("creds.json");
                    }
                    File.Move("creds.json.old", "creds.json");
                }
                else
                {
                    File.Delete("creds.json.old");
                }
            }
            if (File.Exists("ChatCurrency.json"))
            {
                currency = JsonConvert.DeserializeObject <Currency>(File.ReadAllText("ChatCurrency.json"));
            }
            else
            {
                currency = new Currency();
                currency.CurrencyName   = "Krutons";
                currency.CurrencySymbol = "K";
                currency.users          = new List <KeyValuePair <string, int> >();
                currency.users.Add(new KeyValuePair <string, int>("PFCKrutonium", 1));
            }

            CefSettings settings = new CefSettings();

            settings.CachePath              = "./browsercache";
            settings.PersistSessionCookies  = true;
            settings.PersistUserPreferences = true;
            settings.CefCommandLineArgs.Add("autoplay-policy", "no-user-gesture-required");
            Cef.Initialize(settings);

            if (File.Exists("creds.json"))
            {
                cred = JsonConvert.DeserializeObject <creds>(File.ReadAllText("creds.json"));
            }
            else
            {
                frmCredentials frmcreds = new frmCredentials();
                frmcreds.ShowDialog();
                cred = JsonConvert.DeserializeObject <creds>(File.ReadAllText("creds.json"));
            }

            if (File.Exists("quotes.json"))
            {
                try
                {
                    quotes = JsonConvert.DeserializeObject <List <Quote> >(File.ReadAllText("quotes.json"));
                }
                catch (Exception ex)
                {
                    // Could not deserialize quotes file.
                }
            }

            ChannelToMod = cred.channeltomod;
            //Loads our Twitch Credentials from the Json file.
            credentials = new ConnectionCredentials(cred.username, cred.oauth);
            client.Initialize(credentials, ChannelToMod); //Channel were connecting to.
            client.OnConnected       += Client_OnConnected;
            client.OnJoinedChannel   += Client_OnJoinedChannel;
            client.OnMessageReceived += Client_OnMessageReceived;
            client.Connect();
            browser      = new ChromiumWebBrowser("https://www.twitch.tv/popout/" + ChannelToMod + "/chat?popout=");
            browser.Dock = DockStyle.Fill;
            tbMusicVolume.MaximumSize = new System.Drawing.Size(tbMusicVolume.Width, 0);
            BrowserWindow.Controls.Add(browser);
            UpdateViewerList.Enabled = true;
            client.OnDisconnected   += Client_OnDisconnected;
            client.OnReconnected    += Client_OnReconnected;
            browser.AddressChanged  += Browser_AddressChanged;
            //browser. <INJECT JAVASCRIPT ON POPUPS>
            browser.ActivateBrowserOnCreation = true;
            ResetConnection.Enabled           = true;
            var tmpBrowser = new ChromiumWebBrowser(cred.alertsURL);

            tmpBrowser.ActivateBrowserOnCreation = true;
            gbAlerts.Controls.Add(tmpBrowser);
            client.OnDisconnected += Client_OnDisconnected1;

            api.Settings.ClientId    = cred.clientID;
            api.Settings.AccessToken = cred.oauth;
        }