Beispiel #1
0
        public async void Main()
        {
            var firstRun = true;

            while (true)
            {
                if (firstRun && Channel?.Id != null)
                {
                    // Align database with any potentially missed or offline follows/subs
                    // var followers = await api.Channels.v5.GetAllFollowersAsync(Channel.Id);
                    try
                    {
                        var subs = await api.Channels.v5.GetAllSubscribersAsync(Channel.Id, config.ChatbotAccessToken);

                        // TODO: Need to consider length of sub in db alignment
                        vipHelper.StartupSubVips(subs);
                    }
                    catch (NotPartneredException)
                    {
                        Console.Out.WriteLine("Not a partner. Skipping sub setup.");
                    }

                    // VipHelper.StartupFollowVips(followers);

                    // Set threads for sending out stream info to the chat.
                    HowToRequestTimer = new Timer(
                        e => commandHelper.ProcessCommand("howtorequest", client, "Chatbot", string.Empty, true),
                        null,
                        TimeSpan.Zero,
                        TimeSpan.FromMinutes(25));
                    CustomsForgeTimer = new Timer(
                        e => commandHelper.ProcessCommand("customsforge", client, "Chatbot", string.Empty, true),
                        null,
                        TimeSpan.FromMinutes(5),
                        TimeSpan.FromMinutes(25));
                    FollowTimer = new Timer(
                        e => commandHelper.ProcessCommand("followme", client, "Chatbot", string.Empty, true),
                        null,
                        TimeSpan.FromMinutes(10),
                        TimeSpan.FromMinutes(25));
                    DiscordTimer = new Timer(
                        e => commandHelper.ProcessCommand("discord", client, "Chatbot", string.Empty, true),
                        null,
                        TimeSpan.FromMinutes(15),
                        TimeSpan.FromMinutes(25));
                    TwitterTimer = new Timer(
                        e => commandHelper.ProcessCommand("twitter", client, "Chatbot", string.Empty, true),
                        null,
                        TimeSpan.FromMinutes(20),
                        TimeSpan.FromMinutes(25));

                    // Set thread for checking viewers in chat and giving out Bytes.

                    BytesTimer = new Timer(
                        async e =>
                    {
                        try
                        {
                            var currentChattersJson = await httpClient.GetStringAsync($"https://tmi.twitch.tv/group/user/{config.StreamerChannel}/chatters");
                            // process json into username list.
                            var chattersModel = JsonConvert.DeserializeObject <ChatViewersModel>(currentChattersJson);
                            Console.Out.WriteLine(currentChattersJson);
                            bytesHelper.GiveBytes(chattersModel);
                        }
                        catch (Exception ex)
                        {
                            Console.Out.WriteLine(ex.ToString());
                        }
                    },
                        null,
                        TimeSpan.Zero,
                        TimeSpan.FromMinutes(1));

                    // Set thread for checking for any new Donations from streamlabs and synchronise with the db.
                    // Commenting out so bot can be used.

                    /*
                     * DonationsTimer = new System.Threading.Timer(
                     *  async e =>
                     *  {
                     *      try
                     *      {
                     *          var vals = new Dictionary<string, string>
                     *          {
                     *              { "grant_type", "authorization_code" },
                     *              { "client_id", config.StreamLabsClientId },
                     *              { "client_secret", config.StreamLabsClientSecret },
                     *              { "redirect_uri", "localhost" },
                     *              { "code", config.StreamLabsCode }
                     *          };
                     *          var content = new FormUrlEncodedContent(vals);
                     *          var tokenResponse = await httpClient.PostAsync("https://streamlabs.com/api/v1.0/token", content);
                     *          var tokenJsonString = await tokenResponse.Content.ReadAsStringAsync();
                     *          var tokenModel = JsonConvert.DeserializeObject<TokenJsonModel>(tokenJsonString);
                     *
                     *
                     *
                     *          var donationsJsonString = await httpClient.GetStringAsync($"https://streamlabs.com/api/v1.0/donations?access_token={tokenModel.access_token}");
                     *          var donationsModel = JsonConvert.DeserializeObject<TokenJsonModel>(donationsJsonString);
                     *          var text = "";
                     *
                     *          // NOTES TO SELF. Add &after=<donationId> to end of donations call.
                     *          // This can start at any number (for initialising db) after this it will get anything past whichever donation_id we pass
                     *          // This will ideally always be the latest one, we can then check for empty strings and such to reduce overhead.
                     *      }
                     *      catch (Exception ex)
                     *      {
                     *          Console.Out.WriteLine(ex.ToString());
                     *      }
                     *  },
                     *  null,
                     *  TimeSpan.Zero,
                     *  TimeSpan.FromMinutes(1));
                     */

                    firstRun = false;
                    break;
                }
            }
        }