コード例 #1
0
ファイル: Giveaway.cs プロジェクト: zahlio/hugbotty
        public bool addUser(User u)
        {
            int count = 0;
            foreach (User u1 in members) {
                if (u1.nick == u.nick) {
                    count++;
                }
            }

            if (count <= maxEnterTimes - 1)
            {
                if (u.points - cost >= 0)
                {
                    members.Add(u);
                    u.points -= cost;
                    return true;
                }
                else {
                    return false;
                }

            }
            else {
                return false;
            }
        }
コード例 #2
0
ファイル: SQL.cs プロジェクト: zahlio/hugbotty
        public User getUser(string nick)
        {
            string query = "SELECT * FROM botdata WHERE nick = '" + nick + "' AND channel = '" + _channelName + "'";

            // User var
            User user = null;

            //Open connection
            MySqlConnection tempCon = OpenConnection();
            if (tempCon != null)
            {
                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(query, tempCon);

                MySqlDataReader dataReader = cmd.ExecuteReader();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        user = new User(
                            (string)dataReader["channel"],
                            (string)dataReader["nick"],
                            Convert.ToInt32(dataReader["points"]),
                            Convert.ToInt32(dataReader["points_recieved"]),
                            Convert.ToInt32(dataReader["points_given"]),
                            false,
                            false
                        );
                    }
                }
                CloseConnection(tempCon);
            }

            // if the user is null then we need to create it
            if (user == null) {
                this.createUser(nick);
            }

            return user;
        }
コード例 #3
0
ファイル: Bet.cs プロジェクト: zahlio/hugbotty
        public bool addToBet(User u, int amount, bool optionA)
        {
            if (!acceptBets) {
                return false;
            }

            int count = 0;

            count = membersOptionA.Count(user => user.Item1.nick.Equals(u.nick)) + membersOptionB.Count(user => user.Item1.nick.Equals(u.nick));

            if (count >= maxBetEntries) {
                return false;
            }

            if (optionA)
            {
                if (u.points - amount >= 0 && amount < maxBet && amount > 0)
                {
                    membersOptionA.Add(new Tuple<User, int>(u, amount));
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else {
                if (u.points - amount >= 0 && amount < maxBet && amount > 0)
                {
                    membersOptionB.Add(new Tuple<User, int>(u, amount));
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }