Beispiel #1
0
        public static void CheckForNewDonation()
        {
            WebRequest Req = WebRequest.Create("https://streamlabs.com/api/v1.0/donations?access_token=" + Alert.GetAuthCode() + "&limit=100");

            Req.Method = "GET";
            WebResponse Res; Newtonsoft.Json.Linq.JObject CurrentData, OldData = ConfigHandler.LoadConfig("./Data/Donations.dump");

            try
            {
                Res = Req.GetResponse();
                string SData = new StreamReader(Res.GetResponseStream()).ReadToEnd();
                if (SData == null)
                {
                    return;
                }
                CurrentData = Newtonsoft.Json.Linq.JObject.Parse(SData);
            }
            catch (WebException E)
            {
                Console.WriteLine(E.Message);
                return;
            }
            ConfigHandler.SaveConfig("./Data/Donations.dump", CurrentData);
            for (int i = 0; i < OldData["data"].Count(); i++)
            {
                if (CurrentData["data"][i]["donation_id"].ToString() != OldData["data"][0]["donation_id"].ToString())
                {
                    Newtonsoft.Json.Linq.JToken CurrentDonation = CurrentData["data"][i];
                    double Amount = Math.Round(Double.Parse(CurrentDonation["amount"].ToString()), 2);
                    int    Owc    = (int)Math.Floor(Amount * int.Parse(Shared.ConfigHandler.Config["Rewards"]["Twitch"]["Donation"].ToString()));
                    TwitchLib.Api.Models.v5.Users.Users Users = TwitchBot.UserHandler.UserFromUsername(CurrentDonation["name"].ToString());
                    if (Users.Matches.Length != 0)
                    {
                        Data.Accounts.GiveUser(Users.Matches[0].Id, IDType.Twitch, Owc);
                        TwitchBot.MessageHandler.SendMessage(Shared.ConfigHandler.Config["ChannelName"].ToString(), Shared.ConfigHandler.Config["EventMessages"]["Donation"].ToString(), CurrentDonation["name"].ToString(), null, -1, Owc, Amount.ToString() + " " + CurrentDonation["currency"].ToString());
                    }
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #2
0
        private async void RollGiveaway()
        {
            string winner = "";

            if (this.AutoPickCode && Settings.Codes.Count() == 0)
            {
                GiveawayStop();
                bot.SendMessage("Giveaway ended. No codes left to give.");
                MessageBox.Show("Error: No codes left to give. Giveaway stopped.");
                return;
            }

            switch (this.Type)
            {
            case 1:
            case 2:
                try
                {
                    if (this.hashtagUsers.Count() > 0)
                    {
                        winner = this.hashtagUsers[new Random().Next(this.hashtagUsers.Count())];
                        bot.SendMessage($"{winner} {this.WinnerMessage}");
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show($"An exception has occurred: \n\n{e.Message}");
                    this.GiveawayStop();
                }
                break;

            case 3:

                try
                {
                    List <TwitchLib.Api.Models.Undocumented.Chatters.ChatterFormatted> chatters = await bot.GetChatters();

                    List <string> users = new List <string>();
                    if (chatters.Count() <= 0)
                    {
                        MessageBox.Show("Error: No viewers to pick a giveaway winner from.");
                        GiveawayStop();
                        return;
                    }
                    foreach (TwitchLib.Api.Models.Undocumented.Chatters.ChatterFormatted cf in chatters)
                    {
                        TwitchLib.Api.Models.v5.Users.Users user = await bot.GetUserByName(cf.Username);

                        bool uf = await bot.UserFollowsChannel(user.Matches[0].Id);

                        if (uf)
                        {
                            users.Add(user.Matches[0].DisplayName);
                        }
                    }
                    winner = users[new Random().Next(users.Count)];
                    bot.SendMessage($"{winner}  {this.WinnerMessage}");
                }
                catch (Exception e)
                {
                    MessageBox.Show($"An exception has occurred: \n\n{e.Message}");
                    GiveawayStop();
                }
                break;

            case 4:
                try
                {
                    List <TwitchLib.Api.Models.Undocumented.Chatters.ChatterFormatted> chatters = await bot.GetChatters();

                    if (chatters.Count() <= 0)
                    {
                        MessageBox.Show("Error: No viewers to pick a giveaway winner from.");
                        GiveawayStop();
                        return;
                    }
                    winner = chatters[new Random().Next(chatters.Count)].Username;
                    bot.SendMessage($"{winner} {this.WinnerMessage}");
                }
                catch (Exception e)
                {
                    MessageBox.Show($"An exception has occurred: \n\n{e.Message}");
                    this.GiveawayStop();
                }
                break;
            }

            MessageBoxResult result = MessageBox.Show($"{winner} has won \n\n Would you wish to Re-Roll the winner?", this.Name, MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                RollGiveaway();
            }
            else
            {
                if (this.Reward == 1)
                {
                    if (Settings.WhisperCode)
                    {
                        Code code = Settings.Codes[new Random().Next(Settings.Codes.Count())];
                        if (!string.IsNullOrEmpty(this.CodeWhisper))
                        {
                            if (this.AutoPickCode)
                            {
                                bot.SendWhisper(winner, $"{this.CodeWhisper} {code.CodeString}");
                            }
                            else
                            {
                                bot.SendWhisper(winner, $"{this.CodeWhisper} {this.RewardString}");
                            }
                        }
                        else
                        {
                            if (this.AutoPickCode)
                            {
                                bot.SendWhisper(winner, $"Congratulations! You have won the giveaway: {this.Name}. This is a redeem code giveaway, so the code is: {code.CodeString}");
                            }
                            else
                            {
                                bot.SendWhisper(winner, $"Congratulations! You have won the giveaway: {this.Name}. This is a redeem code giveaway, so the code is: {this.Reward}");
                            }
                        }
                        Settings.Codes.Remove(code);
                        DAL.DeleteCode(code);
                        window.Dispatcher.Invoke((Action)(() =>
                        {//this refer to form in WPF application
                            window.UpdateCodes();
                        }));
                    }
                    else
                    {
                        Code code = Settings.Codes[new Random().Next(Settings.Codes.Count())];
                        if (this.AutoPickCode)
                        {
                            MessageBox.Show($"{winner} won the code: {code.CodeString}");
                        }
                        else
                        {
                            MessageBox.Show($"{winner} won the code: {this.RewardString}");
                        }
                        Settings.Codes.Remove(code);
                        DAL.DeleteCode(code);
                        window.Dispatcher.Invoke((Action)(() =>
                        {//this refer to form in WPF application
                            window.UpdateCodes();
                        }));
                    }
                }


                if (this.RanTimes < this.Repeat)
                {
                    this.RanTimes++;
                    timer.Start();
                }
                else
                {
                    this.GiveawayStop();
                }
            }
        }