txlyre 2 سال پیش
والد
کامیت
301489b0ff
3فایلهای تغییر یافته به همراه5 افزوده شده و 5 حذف شده
  1. 3 3
      actions.py
  2. 1 1
      commands.py
  3. 1 1
      models.py

+ 3 - 3
actions.py

@@ -62,10 +62,10 @@ async def add_gif(action, file_id):
 async def get_random_gif(action):
   return await action.gifs.all().annotate(order=Random()).order_by('order').first()
 
-async def assign_color(username):
-  user_color = await UserColor.filter(username=username).first()
+async def assign_color(user_id):
+  user_color = await UserColor.filter(user_id=user_id).first()
   if not user_color:
-    user_color = UserColor(username=username, color=randint(0, 7))
+    user_color = UserColor(user_id=user_id, color=randint(0, 7))
     await user_color.save()
   
   return user_color.color

+ 1 - 1
commands.py

@@ -159,7 +159,7 @@ async def make_message_shot(bot, message):
     'output_path': output_path,
     'avatar_path': avatar_path,
     'username': full_name if full_name else message.sender.username,
-    'username_color': await assign_color(message.sender.username),
+    'username_color': await assign_color(message.sender.id),
     'text': message.text
   }).encode('UTF-8')
 

+ 1 - 1
models.py

@@ -14,7 +14,7 @@ class Gif(Model):
 
 class UserColor(Model):
   id = IntField(pk=True)
-  username = CharField(max_length=256, unique=True)
+  user_id = IntField(unique=True)
   color = IntField()
 
 class StickerPack(Model):