module-name-fix
This commit is contained in:
13
api/index.py
13
api/index.py
@@ -4,6 +4,7 @@ from tgbot.rest import delete_message, register_webhook, send_message, ban_membe
|
|||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.response import json, text
|
from sanic.response import json, text
|
||||||
import redis
|
import redis
|
||||||
|
import json as codec
|
||||||
|
|
||||||
app = Sanic()
|
app = Sanic()
|
||||||
|
|
||||||
@@ -74,13 +75,13 @@ async def handle(req):
|
|||||||
)
|
)
|
||||||
welcome_msg_id = r.json()['result']['message_id']
|
welcome_msg_id = r.json()['result']['message_id']
|
||||||
print(f'welcome message id: {welcome_msg_id}')
|
print(f'welcome message id: {welcome_msg_id}')
|
||||||
s["newcomer"] = True,
|
s["newcomer"] = True
|
||||||
s["welcome_id"] = welcome_msg_id
|
s["welcome_id"] = welcome_msg_id
|
||||||
else:
|
else:
|
||||||
s['newcomer'] = False
|
s['newcomer'] = False
|
||||||
|
|
||||||
# create session
|
# create session
|
||||||
storage.set(f'usr-{member_id}', json.dumps(s))
|
storage.set(f'usr-{member_id}', codec.dumps(s))
|
||||||
|
|
||||||
elif 'text' in msg:
|
elif 'text' in msg:
|
||||||
chat_id = str(msg['chat']['id'])
|
chat_id = str(msg['chat']['id'])
|
||||||
@@ -90,7 +91,7 @@ async def handle(req):
|
|||||||
author = storage.get(f'usr-{member_id}')
|
author = storage.get(f'usr-{member_id}')
|
||||||
|
|
||||||
if author:
|
if author:
|
||||||
author = json.parse(author)
|
author = codec.parse(author)
|
||||||
if author.get("newcomer"):
|
if author.get("newcomer"):
|
||||||
print(f'new member speaks {msg["text"]}')
|
print(f'new member speaks {msg["text"]}')
|
||||||
answer = msg['text']
|
answer = msg['text']
|
||||||
@@ -102,7 +103,7 @@ async def handle(req):
|
|||||||
author["newcomer"] = False
|
author["newcomer"] = False
|
||||||
|
|
||||||
# set author as not a newcomer
|
# set author as not a newcomer
|
||||||
storage.set(f'usr-{member_id}', json.dumps(author))
|
storage.set(f'usr-{member_id}', codec.dumps(author))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('remove some message')
|
print('remove some message')
|
||||||
@@ -122,7 +123,7 @@ async def handle(req):
|
|||||||
print(f'callback_query in {CHAT_ID}')
|
print(f'callback_query in {CHAT_ID}')
|
||||||
s = storage.get(f'usr-{member_id}')
|
s = storage.get(f'usr-{member_id}')
|
||||||
if s:
|
if s:
|
||||||
s = json.parse(s)
|
s = codec.parse(s)
|
||||||
if callback_data == BUTTON_NO:
|
if callback_data == BUTTON_NO:
|
||||||
print('wrong answer, cleanup')
|
print('wrong answer, cleanup')
|
||||||
r = delete_message(CHAT_ID, s['enter_id'])
|
r = delete_message(CHAT_ID, s['enter_id'])
|
||||||
@@ -138,7 +139,7 @@ async def handle(req):
|
|||||||
r = delete_message(CHAT_ID, s['welcome_id'])
|
r = delete_message(CHAT_ID, s['welcome_id'])
|
||||||
print(r.json())
|
print(r.json())
|
||||||
s['newcomer'] = False
|
s['newcomer'] = False
|
||||||
storage.set(f'usr-{member_id}', json.dumps(s))
|
storage.set(f'usr-{member_id}', codec.dumps(s))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return text('ok')
|
return text('ok')
|
||||||
|
Reference in New Issue
Block a user