Example #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();
        }
Example #2
0
 private void giveawayStopAndRefund_Click(object sender, EventArgs e)
 {
     giveawayBox.Enabled = true;
     currentGiveawayBox.Enabled = false;
     giveaway.refund();
     giveaway = null;
 }
Example #3
0
 private void giveawayStop_Click(object sender, EventArgs e)
 {
     giveaway = null;
     giveawayBox.Enabled = true;
     currentGiveawayBox.Enabled = false;
 }
Example #4
0
 private void giveawayStart_Click(object sender, EventArgs e)
 {
     if      (!checkString(giveawaySlug.Text, "Please enter a valid slug.")) { }
     else if (!checkString(giveawayName.Text, "Please enter a valid name.")) { }
     else if (!checkInt(giveawayCost.Text, "Please enter a valid cost.")) { }
     else if (!checkInt(giveawayMaxEnterTimes.Text, "Please enter a valid max entry times.")) { }
     else if (!checkInt(giveawayDuration.Text, "Please enter a valid duration.")) { }
     else if (!checkInt(giveawayAnnouncementInterval.Text, "Please enter a valid announcement interval.")) { }
     else
     {
         giveawayStop.Enabled = true;
         giveawayBox.Enabled = false;
         currentGiveawayBox.Enabled = true;
         giveaway = new Giveaway(giveawaySlug.Text,
             giveawayName.Text,
             Convert.ToInt32(giveawayCost.Text),
             Convert.ToInt32(giveawayMaxEnterTimes.Text),
             Convert.ToInt64(giveawayDuration.Text) + UnixTimeNow(),
             Convert.ToInt32(giveawayAnnouncementInterval.Text)
         );
         connection.Sender.PublicMessage("#" + this.channelBox.Text, "Enter the giveaway for " + giveawayName.Text + "! Type !" + giveawaySlug.Text + " in chat.");
     }
 }