Queer European MD passionate about IT
Browse Source

Create users table if missing

Davte 4 years ago
parent
commit
87d95fbfed
2 changed files with 33 additions and 13 deletions
  1. 1 1
      davtelepot/__init__.py
  2. 32 12
      davtelepot/bot.py

+ 1 - 1
davtelepot/__init__.py

@@ -14,7 +14,7 @@ __author__ = "Davide Testa"
 __email__ = "davide@davte.it"
 __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
 __license__ = "GNU General Public License v3.0"
-__version__ = "2.4.15"
+__version__ = "2.4.16"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 

+ 32 - 12
davtelepot/bot.py

@@ -223,18 +223,38 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
         self.shared_data = dict()
         self.Role = None
         # Add `users` table with its fields if missing
-        self.db['users'].upsert(
-            dict(
-                telegram_id=000000000,
-                privileges=100,
-                username="username",
-                first_name="First",
-                last_name="Last",
-                language_code="en",
-                selected_language_code="en"
-            ),
-            ['telegram_id']
-        )
+        if 'users' not in self.db.tables:
+            table = self.db.create_table(
+                table_name='users'
+            )
+            table.create_column(
+                'telegram_id',
+                self.db.types.integer
+            )
+            table.create_column(
+                'privileges',
+                self.db.types.integer
+            )
+            table.create_column(
+                'username',
+                self.db.types.string
+            )
+            table.create_column(
+                'first_name',
+                self.db.types.string
+            )
+            table.create_column(
+                'last_name',
+                self.db.types.string
+            )
+            table.create_column(
+                'language_code',
+                self.db.types.string
+            )
+            table.create_column(
+                'selected_language_code',
+                self.db.types.string
+            )
         return
 
     @property