Exemple #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();
        }
Exemple #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     Api a = new Api();
     a.listUsers(members);
 }
Exemple #3
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            // Check values
            if (!checkString(channelBox.Text, "Please enter a valid channelname.")) { }
            else if (!checkString(serverBox.Text, "Please enter a valid server")) { }
            else if (!checkString(usernameBox.Text, "Please enter a valid username.")) { }
            else if (!checkString(OAuthBox.Text, "Please enter a valid oAuth key.")) { }
            else if (!checkInt(giftMin.Text, "Please enter a number in gift min.")) { }
            else if (!checkInt(textBox5.Text, "Please enter a number in gift reward amount.")) { }
            else if (!checkInt(costOfHugBox.Text, "Please enter a number in cost of " + textBox13.Text + "(s).")) { }
            else if (!checkInt(followRewardBox.Text, "Please enter a number in follow reward.")) { }
            else if (!checkString(textBox12.Text, "Please enter a valid HugPoints name.")) { }
            else if (!checkString(textBox13.Text, "Please enter a valid HugPoints short name.")) { }
            else
            {
                try
                {
                    // load users
                    this.Invoke(new Action(() => this.chatMessage.Text += "[SYSTEM] Loading users from API...\n"));
                    Api a = new Api();
                    this.members = a.getUsers(channelBox.Text);
                    this.Invoke(new Action(() => this.chatMessage.Text += "[SYSTEM] Loaded af total of " + members.Count + " members from API.\n"));
                }
                catch (Exception e1)
                {
                    Console.WriteLine("Could not connect to API.");
                    this.chatMessage.Text += "[SYSTEM] Could not connect to API.\n";
                    MessageBox.Show("Could not connect to API",
                        "ERROR",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1
                    );
                    return;
                }

                CreateConnection();

                //OnRegister tells us that we have successfully established a connection with
                //the server. Once this is established we can join channels, check for people
                //online, or whatever.
                connection.Listener.OnRegistered += new RegisteredEventHandler(OnRegistered);
                //Listen for any messages sent to the channel
                connection.Listener.OnPublic += new PublicMessageEventHandler(OnPublic);

                // If a user joins
                connection.Listener.OnJoin += new JoinEventHandler(OnJoin);

                // If a user leaves
                connection.Listener.OnPart += new PartEventHandler(OnPart);

                //Listen for bot commands sent as private messages
                connection.Listener.OnPrivate += new PrivateMessageEventHandler(OnPrivate);
                //Listen for notification that an error has ocurred
                connection.Listener.OnError += new ErrorMessageEventHandler(OnError);

                //Listen for notification that we are no longer connected.
                connection.Listener.OnDisconnected += new DisconnectedEventHandler(OnDisconnected);
            }
        }
Exemple #4
0
 private void button16_Click(object sender, EventArgs e)
 {
     Api a = new Api();
     a.updatedFollowers(members, channelBox.Text, 0);
 }