Skip to content

Commit

Permalink
api: Adding a profile picture for the bot
Browse files Browse the repository at this point in the history
  • Loading branch information
okbrandon committed Oct 16, 2024
1 parent e3b4382 commit 3c1c559
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions backend/api/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import base64

from django.apps import AppConfig
from django.db.models.signals import post_migrate

Expand Down Expand Up @@ -32,13 +34,18 @@ def create_ai_account(sender, **kwargs):
from .models import User

if not User.objects.filter(userID="user_ai").exists():
encoded_avatar = None
with open("static/ai_avatar.jpg", "rb") as f:
encoded_avatar = base64.b64encode(f.read()).decode('utf-8')

User.objects.create(
userID="user_ai",
username='ai',
displayName='Prune',
email='prune@brandoncodes.dev',
password='',
lang='EN',
avatarID=f"data:image/jpeg;base64,{encoded_avatar}",
flags=3
)

Expand Down
5 changes: 4 additions & 1 deletion backend/api/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ async def handle_identify(self, data):
await self.close()
else:
self.user = await self.get_user_from_id('user_ai')
await self.send_json({"e": "READY", "d": get_safe_profile(UserSerializer(self.user).data, me=True)})
user_data = UserSerializer(self.user).data
safe_profile = get_safe_profile(user_data, me=True)
safe_profile.pop('avatarID', None)
await self.send_json({"e": "READY", "d": safe_profile})
logger.info(f"[{self.__class__.__name__}] AI identified: {self.user.userID}")

async def get_user_profile(self, token):
Expand Down
Binary file added backend/static/ai_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3c1c559

Please sign in to comment.