DmitrMakeev commited on
Commit
0c2fccf
·
verified ·
1 Parent(s): b06f025

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -40
app.py CHANGED
@@ -32,10 +32,7 @@ from hashlib import sha256
32
  from hmac import HMAC
33
 
34
 
35
- import asyncio
36
- from pywebio.input import *
37
- from pywebio.output import *
38
- from pywebio.session import defer_call, info as session_info, run_async, run_js
39
 
40
 
41
  from base import replace_null_with_empty_string
@@ -50,10 +47,7 @@ ALLOWED_ORIGIN = "https://diamonik7777-up-fail.hf.space"
50
 
51
 
52
 
53
- # апуска вашего чата
54
- chat_msgs = []
55
- online_users = set()
56
- MAX_MESSAGES_COUNT = 100
57
 
58
  # Глобальные переменные для хранения настроек
59
  api_key_auth = ''
@@ -1057,38 +1051,6 @@ def get_order_monitop():
1057
 
1058
 
1059
 
1060
- @app.route('/chat')
1061
- def chat():
1062
- return render_template_string(open('chat_template.html').read())
1063
-
1064
- @app.route('/chat_api', methods=['POST'])
1065
- async def chat_api():
1066
- global chat_msgs
1067
-
1068
- data = request.json
1069
- if data['action'] == 'join':
1070
- nickname = data['nickname']
1071
- if nickname in online_users or nickname == '📢':
1072
- return jsonify({'status': 'error', 'message': 'Такой ник уже используется!'})
1073
- online_users.add(nickname)
1074
- chat_msgs.append(('📢', f'`{nickname}` присоединился к чату!'))
1075
- return jsonify({'status': 'success', 'message': f'📢 `{nickname}` присоединился к чату'})
1076
- elif data['action'] == 'send':
1077
- nickname = data['nickname']
1078
- msg = data['msg']
1079
- chat_msgs.append((nickname, msg))
1080
- return jsonify({'status': 'success', 'message': f"`{nickname}`: {msg}"})
1081
- elif data['action'] == 'leave':
1082
- nickname = data['nickname']
1083
- online_users.remove(nickname)
1084
- chat_msgs.append(('📢', f'Пользователь `{nickname}` покинул чат!'))
1085
- return jsonify({'status': 'success', 'message': f'📢 Пользователь `{nickname}` покинул чат!'})
1086
- elif data['action'] == 'refresh':
1087
- last_idx = data['last_idx']
1088
- new_msgs = chat_msgs[last_idx:]
1089
- return jsonify({'status': 'success', 'messages': new_msgs, 'last_idx': len(chat_msgs)})
1090
- return jsonify({'status': 'error', 'message': 'Неизвестное действие'})
1091
-
1092
 
1093
 
1094
 
 
32
  from hmac import HMAC
33
 
34
 
35
+
 
 
 
36
 
37
 
38
  from base import replace_null_with_empty_string
 
47
 
48
 
49
 
50
+
 
 
 
51
 
52
  # Глобальные переменные для хранения настроек
53
  api_key_auth = ''
 
1051
 
1052
 
1053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1054
 
1055
 
1056