fix: self sending !kot works now

This commit is contained in:
Krzysztof Rudnicki 2024-06-23 23:03:20 +02:00
parent dd11f33d21
commit 09e811a2b7
3 changed files with 10 additions and 6 deletions

2
.gitignore vendored
View File

@ -160,3 +160,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
*.jpg
*.gif

11
main.py
View File

@ -35,7 +35,7 @@ def fetch_and_download_cat_image():
with open(image_filename, 'rb') as image_file: with open(image_filename, 'rb') as image_file:
base64_encoded_data = base64.b64encode(image_file.read()).decode('utf-8') base64_encoded_data = base64.b64encode(image_file.read()).decode('utf-8')
print(f"Base64 Encoded Data: {base64_encoded_data}") os.remove(image_filename)
return base64_encoded_data return base64_encoded_data
def send_cat(): def send_cat():
@ -61,13 +61,12 @@ async def listen_to_server():
try: try:
async for message in websocket: async for message in websocket:
message_json = json.loads(message) message_json = json.loads(message)
#inside_message = message_json.get('envelope', {}).get('syncMessage', {}).get('sentMessage', {})
inside_message = message_json.get('envelope', {}).get('dataMessage', {}) inside_message = message_json.get('envelope', {}).get('dataMessage', {})
if inside_message == {}:
inside_message = message_json.get('envelope', {}).get('syncMessage', {}).get('sentMessage', {})
print("message", message) print("message", message)
if inside_message.get('message') == "!kot": if inside_message.get('message') == "!kot" and inside_message.get('groupInfo', {}).get('groupId', {}) == GROUP_ID:
print("kot message detected") send_cat()
if inside_message.get('groupInfo', {}).get('groupId', {}) == GROUP_ID:
send_cat()
except websockets.ConnectionClosed as e: except websockets.ConnectionClosed as e:
print(f"Connection closed: {e}") print(f"Connection closed: {e}")

3
run.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
sudo apt-get install python3-venv