Ejemplo n.º 1
0
        private void timerTick(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine("Timer tick " + UnixTimeNow());
            Thread t = new Thread(() =>
            {
                Api api = new Api();

                // Graph
                if (nextMin < UnixTimeNow()) {
                    nextMin = UnixTimeNow() + 60;
                    this.Invoke(new Action(() => this.chart1.Series["User(s) in chat"].Points.AddXY(DateTime.Now.ToString("H:mm"), members.Count(user => user.isOnline == true))));
                }

                // bet
                if (bet != null) {
                    if (bet.nextAnnouncement < UnixTimeNow())
                    {
                        bet.nextAnnouncement = UnixTimeNow() + bet.betAnnouncementWaiter;
                        // We write an announcement
                        this.Invoke(new Action(() => connection.Sender.PublicMessage("#" + this.channelBox.Text, "Betting is open: " + bet.name + " !bet a: " + bet.optionA + " !bet b: " + bet.optionB + ". Max. betsize is: " + bet.maxBet + ". To bet, type: !bet a <amount>  or !bet b <amount>.")));
                        bet.nextAnnouncement = UnixTimeNow() + bet.betAnnouncementWaiter;
                    }

                    // Is finished?
                    if (bet.betEnd < UnixTimeNow())
                    {
                        bet.acceptBets = false;
                        this.Invoke(new Action(() =>
                        {
                            MessageBox.Show("The bet has ended, please select a winning option",
                                "BET ENDED",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                            label34.Text = "Status: Not accepting bets.";
                        }));
                    }

                    // we update the stats on the giveaway page
                    this.Invoke(new Action(() =>
                    {
                        currentBetLabel1.Text = "Current members in the bet: " + (bet.membersOptionA.Count() + bet.membersOptionB.Count());
                        currentBetLabel2.Text = "Total points in bet pool: " + (bet.membersOptionA.Sum(temp1 => temp1.Item2) + bet.membersOptionB.Sum(temp2 => temp2.Item2));
                        currentBetLabel3.Text = "Time left on bet: " + (bet.betEnd - UnixTimeNow()) + " seconds";
                    }));

                }

                // Giveaway
                if (giveaway != null)
                {
                    if (giveaway.nextAnnouncement < UnixTimeNow()) {
                        giveaway.nextAnnouncement = UnixTimeNow() + giveaway.timeAnnouncementWaiter;
                        // We write an announcement
                        this.Invoke(new Action(() => connection.Sender.PublicMessage("#" + this.channelBox.Text, "Enter the giveaway for " + giveaway.name + "! Type !" + giveaway.slug + " in chat. Total entries so far: " + giveaway.members.Count() + ".")));
                        giveaway.nextAnnouncement = UnixTimeNow() + giveaway.timeAnnouncementWaiter;
                    }

                    // Is finished?
                    if (giveaway.endTime < UnixTimeNow()) {
                        User winner = giveaway.getWinner();
                        this.Invoke(new Action(() =>  {
                            connection.Sender.PublicMessage("#" + winner.channel, "The winner of the giveaway is: " + winner.nick + "!");
                            currentGiveawayLabel4.Text = "Winner: " + winner.nick;
                            giveawayBox.Enabled = true;
                            currentGiveawayBox.Enabled = false;
                        }));

                        giveaway = null;
                    }

                    // we update the stats on the giveaway page
                    this.Invoke(new Action(() => {
                        currentGiveawayLabel1.Text = "Current members in the giveaway: " + giveaway.members.Count();
                        currentGiveawayLabel2.Text = "Total points used on giveaway: " + giveaway.members.Count() * giveaway.cost;
                        currentGiveawayLabel3.Text = "Time left on giveaway: " + (giveaway.endTime - UnixTimeNow()) + " seconds";
                    }));
                }

                // Sync
                if (nextSync < UnixTimeNow()) {
                    nextSync = UnixTimeNow() + (60 * 5);
                    List<User> _syncMembers = api.syncUsers(api.getUsers(channelBox.Text), channelBox.Text);

                    // update followers
                    this.members = api.updatedFollowers(_syncMembers, channelBox.Text, 0);
                    nextSync = UnixTimeNow() + (60 * 5);
                }
            });
            t.Start();
        }
Ejemplo n.º 2
0
 private void button16_Click(object sender, EventArgs e)
 {
     Api a = new Api();
     a.updatedFollowers(members, channelBox.Text, 0);
 }