示例#1
0
        public static async Task HandleContest(SocketMessage message)
        {
            if (message.ToString() == "!d bump")
            {
                BumpGameUser[] lastBumpGameUsers = SecurityFunctions.GetLastBumps();
                DateTime       bumpTime          = DateTime.UtcNow;

                if ((bumpTime - lastBumpGameUsers[0].LastBump).TotalHours >= 2.0)
                {
                    if (SecurityFunctions.GetUser(message.Author.Id) != null)
                    {
                        if (lastBumpGameUsers[0].ID == (long)message.Author.Id && lastBumpGameUsers[1].ID == (long)message.Author.Id && lastBumpGameUsers[2].ID != (long)message.Author.Id)
                        {
                            SecurityFunctions.AddPoints(message.Author.Id, bumpTime, 5);
                        }
                        else
                        {
                            SecurityFunctions.AddPoints(message.Author.Id, bumpTime, 1);
                        }
                    }
                    else
                    {
                        BumpGameUser newUser = new BumpGameUser()
                        {
                            ID = (long)message.Author.Id, Name = message.Author.Username, FirstBump = bumpTime, LastBump = bumpTime, Points = 1
                        };
                        SecurityFunctions.AddUser(newUser);
                    }
                    SecurityFunctions.AddBump(message.Author.Id, bumpTime);
                }
            }
        }
示例#2
0
        //public static SqlConnection SqlConnection = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"E:\\The CyberSec Lounge\\Discord Bot\\Data\\TCL_Database.mdf\";Integrated Security=True");

        // Needs a null value checking

        /*
         * internal static BumpGameUser[] GetLastBumpGameWinners()
         * {
         *  SqlCommand getLastBumpGameWinners = new SqlCommand("SELECT TOP 3 * FROM bumpGameUsers ORDER BY Last_Bump DESC;", SqlConnection);
         *  SqlDataReader reader = getLastBumpGameWinners.ExecuteReader();
         *  reader.Read();
         *  BumpGameUser[] users = new BumpGameUser[3];
         *  users.SetValue(new BumpGameUser() { ID = reader.GetInt64(0), Name = reader.GetString(1), FirstBump = reader.GetDateTime(2), LastBump = reader.GetDateTime(3), Points = reader.GetInt32(4) }, 0);
         *  reader.Read();
         *  users.SetValue(new BumpGameUser() { ID = reader.GetInt64(0), Name = reader.GetString(1), FirstBump = reader.GetDateTime(2), LastBump = reader.GetDateTime(3), Points = reader.GetInt32(4) }, 1);
         *  reader.Read();
         *  users.SetValue(new BumpGameUser() { ID = reader.GetInt64(0), Name = reader.GetString(1), FirstBump = reader.GetDateTime(2), LastBump = reader.GetDateTime(3), Points = reader.GetInt32(4) }, 2);
         *  reader.Close();
         *  return users;
         * }
         */

        // Needs a null value checking
        internal static BumpGameUser[] GetLastBumps()
        {
            BumpGameUser[] users        = new BumpGameUser[3];
            int            indexCounter = 0;

            SqlCommand    getLastBumps    = new SqlCommand("SELECT TOP 3 * FROM Bumps ORDER BY Bump_Time DESC", SqlConnection);
            SqlDataReader lastBumpsReader = getLastBumps.ExecuteReader();

            lastBumpsReader.Read();
            users.SetValue(new BumpGameUser()
            {
                ID = lastBumpsReader.GetInt64(1)
            }, 0);
            lastBumpsReader.Read();
            users.SetValue(new BumpGameUser()
            {
                ID = lastBumpsReader.GetInt64(1)
            }, 1);
            lastBumpsReader.Read();
            users.SetValue(new BumpGameUser()
            {
                ID = lastBumpsReader.GetInt64(1)
            }, 2);

            lastBumpsReader.Close();

            foreach (BumpGameUser user in users)
            {
                users.SetValue(GetUser((ulong)user.ID), indexCounter);
                indexCounter++;
            }
            return(users);
        }
示例#3
0
        internal static BumpGameUser[] GetAllUsers()
        {
            SqlCommand rowCountCommand = new SqlCommand("SELECT COUNT(*) FROM bumpGameUsers;", SqlConnection);
            int        rowCount        = (int)rowCountCommand.ExecuteScalar();

            SqlCommand    getUsers   = new SqlCommand("SELECT * FROM bumpGameUsers ORDER BY Points DESC;", SqlConnection);
            SqlDataReader dataReader = getUsers.ExecuteReader();

            if (rowCount > 0)
            {
                BumpGameUser[] users = new BumpGameUser[rowCount];

                for (int row = 0; row <= rowCount - 1; row++)
                {
                    dataReader.Read();
                    users.SetValue(new BumpGameUser()
                    {
                        ID = dataReader.GetInt64(0), Name = dataReader.GetString(1), FirstBump = dataReader.GetDateTime(2), LastBump = dataReader.GetDateTime(3), Points = dataReader.GetInt32(4)
                    }, row);
                }
                dataReader.Close();
                return(users);
            }

            else
            {
                dataReader.Close();
                return(null);
            }
        }
示例#4
0
        internal static BumpGameUser[] GetTopUsers(int amount)
        {
            SqlCommand countUsers = new SqlCommand("SELECT COUNT(*) FROM(SELECT TOP(@amount) * FROM bumpGameUsers ORDER BY Points DESC) AS result;", SqlConnection);

            countUsers.Parameters.AddWithValue("@amount", amount);
            int rowCount = (int)countUsers.ExecuteScalar();

            SqlCommand getUsers = new SqlCommand("SELECT TOP (@amount) * FROM bumpGameUsers ORDER BY Points DESC;", SqlConnection);

            getUsers.Parameters.AddWithValue("@amount", amount);
            SqlDataReader dataReader = getUsers.ExecuteReader();

            if (rowCount > 0)
            {
                BumpGameUser[] users = new BumpGameUser[rowCount];

                for (int row = 0; row <= rowCount - 1; row++)
                {
                    dataReader.Read();
                    users.SetValue(new BumpGameUser()
                    {
                        ID = dataReader.GetInt64(0), Name = dataReader.GetString(1), FirstBump = dataReader.GetDateTime(2), LastBump = dataReader.GetDateTime(3), Points = dataReader.GetInt32(4)
                    }, row);
                }
                dataReader.Close();
                return(users);
            }

            else
            {
                dataReader.Close();
                return(null);
            }
        }
示例#5
0
        internal static BumpGameUser GetUser(ulong userId)
        {
            SqlCommand rowCountCommand = new SqlCommand("SELECT COUNT(*) FROM bumpGameUsers WHERE UUID = @userId;", SqlConnection);

            rowCountCommand.Parameters.AddWithValue("@userId", (long)userId);
            int rowCount = (int)rowCountCommand.ExecuteScalar();

            SqlCommand getUser = new SqlCommand("SELECT * FROM bumpGameUsers WHERE UUID = @userId;", SqlConnection);

            getUser.Parameters.AddWithValue("@userId", (long)userId);

            SqlDataReader dataReader = getUser.ExecuteReader();

            dataReader.Read();

            if (rowCount > 0)
            {
                BumpGameUser user = new BumpGameUser()
                {
                    ID = dataReader.GetInt64(0), Name = dataReader.GetString(1), FirstBump = dataReader.GetDateTime(2), LastBump = dataReader.GetDateTime(3), Points = dataReader.GetInt32(4)
                };
                dataReader.Close();
                return(user);
            }
            else
            {
                dataReader.Close();
                return(null);
            }
        }
示例#6
0
        internal static bool AddUser(BumpGameUser user)
        {
            SqlCommand addUser = new SqlCommand("INSERT INTO bumpGameUsers (UUID, Gamer_Name, First_Bump, Last_Bump, Points) VALUES (@userId, @name, @firstBump, @lastBump, @points);", SqlConnection);

            addUser.Parameters.AddWithValue("@userId", user.ID);
            addUser.Parameters.AddWithValue("@name", user.Name);
            addUser.Parameters.AddWithValue("@firstBump", user.FirstBump);
            addUser.Parameters.AddWithValue("@lastBump", user.LastBump);
            addUser.Parameters.AddWithValue("@points", user.Points);

            SqlDataReader dataReader = addUser.ExecuteReader();

            dataReader.Read();


            if (dataReader.RecordsAffected > 0)
            {
                dataReader.Close();
                return(true);
            }
            else
            {
                dataReader.Close();
                return(false);
            }
        }