Beispiel #1
0
        internal static List <long> GetActiveChats()
        {
            List <long> chatIds = new List <long>();

            Connect();
            using (SqlCommand cmd = _db.CreateCommand())
            {
                cmd.CommandText = "SELECT * FROM Chats";
                try
                {
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        chatIds.Add(long.Parse(reader["ChatID"].ToString()));
                    }
                }
                catch (Exception e)
                {
                    FormatHelpers.Error(e.Message);
                    CallHome.SomethingBad($"{DateTime.UtcNow.ToString()} || {e.Message}");
                }
            }
            Disconnect();

            return(chatIds);
        }
Beispiel #2
0
        public static List <ITelegramDbEntry> GetAllMessages()
        {
            Connect();
            SqlCommand cmd = _db.CreateCommand();

            cmd.CommandText = "SELECT Text, Id FROM Messages";
            List <TelegramDbEntry> messages = new List <TelegramDbEntry>();

            try
            {
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    messages.Add(new TelegramDbEntry(uint.Parse(reader["Id"].ToString()), reader["Text"].ToString()));
                }
            }
            catch (Exception e)
            {
                FormatHelpers.Error(e.Message);
                CallHome.SomethingBad(DateTime.UtcNow.ToString() + "|| " + e.Message);
            }
            Disconnect();

            return(messages.Cast <ITelegramDbEntry>().ToList()); /* <-- What the f**k is this monster */
        }
Beispiel #3
0
 internal static void AddMessage(long chatId, string text)
 {
     Connect();
     using (SqlCommand cmd = _db.CreateCommand())
     {
         cmd.CommandText = $"INSERT INTO Messages (Id, Text) VALUES ({Properties.Settings.Default.NextId}, @message)";
         cmd.Parameters.Add("@message", System.Data.SqlDbType.NVarChar);
         cmd.Parameters["@message"].Value = text;
         try
         {
             int rows = cmd.ExecuteNonQuery();
             Properties.Settings.Default.NextId++;
             Properties.Settings.Default.Save();
         }
         catch (Exception e)
         {
             if (e.Message.StartsWith("Violation of PRIMARY KEY"))
             {
                 Disconnect();
                 return;
             }
             FormatHelpers.Error(e.Message);
             CallHome.SomethingBad($"{DateTime.UtcNow.ToString()} || {e.Message}");
         }
     }
     Disconnect();
 }
Beispiel #4
0
        public static void DeactivateChat(long chatId)
        {
            Connect();
            SqlCommand cmd = _db.CreateCommand();

            cmd.CommandText = $"DELETE FROM Chats WHERE ChatId = {chatId}";
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                FormatHelpers.Error(e.Message);
                CallHome.SomethingBad(DateTime.UtcNow.ToString() + "|| " + e.Message);
            }
            Disconnect();
        }
Beispiel #5
0
 internal static void AddChat(long chatId)
 {
     Connect();
     using (SqlCommand cmd = _db.CreateCommand())
     {
         cmd.CommandText = $"INSERT INTO Chats VALUES ({chatId})";
         try
         {
             cmd.ExecuteNonQuery();
         }
         catch (Exception e)
         {
             FormatHelpers.Error(e.Message);
             CallHome.SomethingBad($"{DateTime.UtcNow.ToString()} || {e.Message}");
         }
     }
     Disconnect();
 }