Compare commits

22 Commits

Author SHA1 Message Date
b313b15686 Test fix nft_svc
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
2022-05-08 01:11:56 +07:00
aacb413176 Some fix
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-08 01:06:05 +07:00
efc711cd3b Added jpeg to png converted images
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-08 01:02:04 +07:00
b77f1bc13d Remove jpeg's
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-08 00:49:08 +07:00
55f17606d6 Merge branch 'main' of https://gitea.gavt45.ru/gav/es-bot
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-08 00:44:41 +07:00
e0c9aad35a Update pictures 2022-05-08 00:44:19 +07:00
gav
8c558f7bc0 Merge pull request 'Job of fucking copywriter!!!' (#4) from text-edition into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #4
Reviewed-by: gav <a@a.aa>
2022-05-05 12:13:54 +07:00
gav
a66fde985f Merge branch 'main' into text-edition
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-05-05 12:13:24 +07:00
f97a8286b7 Updated gitignore
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-05 12:12:27 +07:00
1dfd81de31 Merge branch 'main' of https://gitea.gavt45.ru/gav/es-bot
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-05 12:11:40 +07:00
20eaea722f added images and updated svc 2022-05-05 12:11:20 +07:00
ee834376db Job of fucking copywriter!!!
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-05-04 22:05:35 +07:00
gav
ca6ac97e33 Merge pull request 'Job of fucking copiwriter!!!' (#3) from text-edition into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #3
Reviewed-by: gav <a@a.aa>
2022-05-04 21:03:34 +07:00
be430673f1 Job of fucking copiwriter!!!
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-05-04 21:02:03 +07:00
gav
2dc6327fe1 Merge pull request 'text-edition' (#2) from text-edition into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #2
2022-05-04 20:44:44 +07:00
221ff51d3d Text edited
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-04 20:43:53 +07:00
0fc4d0df82 Text edited
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-04 19:59:59 +07:00
fe897a596c Merge pull request 'Text edited' (#1) from text-edition into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #1
Reviewed-by: dshestakova <d.shestakova2@g.nsu.ru>
2022-05-04 16:58:04 +07:00
2bc65d37dd Merge branch 'main' into text-edition
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-05-04 16:56:46 +07:00
cc206ff358 Fixed keyboard and added man page
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-03 21:06:32 +07:00
9065115927 Fixed bug in image gen
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-03 11:18:05 +07:00
db629bb804 Update nft svc
All checks were successful
continuous-integration/drone/push Build is passing
2022-05-03 11:04:21 +07:00
98 changed files with 338 additions and 90 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
*__pycache__*
tmp
.env
docker-compose-dev.yml
*.DS_Store*
.idea/

View File

@ -1,4 +1,5 @@
from .menu import menu_router
from .test import test_router
from .teacher import teacher_router
from .student import student_router
from .student import student_router
from .man import man_router

19
blueprints/man.py Normal file
View File

@ -0,0 +1,19 @@
from vkwave.bots import DefaultRouter, SimpleBotEvent, simple_bot_message_handler, PayloadContainsFilter, BotEvent, \
EventTypeFilter
from vkwave.types.bot_events import BotEventType
import locales
man_router = DefaultRouter()
@man_router.registrar.with_decorator(
EventTypeFilter(BotEventType.MESSAGE_NEW.value),
PayloadContainsFilter("man"),
)
async def man_menu(event: BotEvent):
sevent = SimpleBotEvent(event)
return await sevent.answer(
message=locales.MAN,
keyboard=locales.MAN_KB.get_keyboard(),
)

View File

@ -1,43 +1,21 @@
import json
import logging
import random
from vkwave.bots import DefaultRouter, SimpleBotEvent, simple_bot_message_handler, PayloadFilter, PayloadContainsFilter, \
PhotoUploader, Storage
from vkwave.bots import Keyboard, ButtonColor
from vkwave.bots import DefaultRouter, SimpleBotEvent, PayloadContainsFilter
from vkwave.bots import Keyboard
from vkwave.bots import EventTypeFilter, BotEvent
from vkwave.types.bot_events import BotEventType
from vkwave.bots.fsm import FiniteStateMachine, StateFilter, ForWhat, State, ANY_STATE
import locales
import util
from config import Config
from db import DB
from db.db import TestResult
from locales import INPUT_NAME_TEXT
# MENU_KB.add_row()
# MENU_KB.add_text_button(text="Профиль", payload={"command": "profile"}, color=ButtonColor.SECONDARY)
# MENU_KB.add_row()
# MENU_KB.add_text_button(text="Бонус", payload={"command": "bonus"}, color=ButtonColor.POSITIVE)
# from nft_things.NftSender import NFTSender
from util.redis_db import RedisDB
from util.nft_util import get_image
test_router = DefaultRouter()
EMPTY_KB = '{"buttons": [], "inline": false, "one_time": false}'
# # exiting from poll (works on any state)
# @test_router.registrar.with_decorator(
# lambda event: event.object.object.message.text == "exit",
# StateFilter(fsm=fsm, state=ANY_STATE, for_what=ForWhat.FOR_USER)
# )
# async def simple_handler(event: BotEvent):
# # Check if we have the user in database
# if await fsm.get_data(event, for_what=ForWhat.FOR_USER) is not None:
# await fsm.finish(event=event, for_what=ForWhat.FOR_USER)
# return "You are quited!"
@test_router.registrar.with_decorator(
EventTypeFilter(BotEventType.MESSAGE_NEW.value),
@ -51,7 +29,6 @@ async def main_part_handle(event: BotEvent):
state_idx = int(payload["test"])
logging.debug(f"State index: {state_idx}")
q_res = payload['q'] if 'q' in payload else event.object.object.message.text
logging.debug(f"Qres: {q_res}")
@ -73,7 +50,7 @@ async def main_part_handle(event: BotEvent):
return await botevent.answer(
message=locales.questions[state_idx + 1][0],
payload=json.dumps({"test": state_idx + 1}),
keyboard=EMPTY_KB, # try to remove keyboard
)
else:
# todo add task to send user an image here
@ -92,21 +69,3 @@ async def main_part_handle(event: BotEvent):
message=locales.LAST_MESSAGE,
keyboard=locales.LAST_MESSAGE_KB.get_keyboard(),
)
# @test_router.registrar.with_decorator(
# StateFilter(fsm=fsm, state=MyState.age, for_what=ForWhat.FOR_USER),
# )
# async def simple_handler(event: BotEvent):
# if not event.object.object.message.text.isdigit():
# return f"Please, send only positive numbers!"
# await fsm.add_data(
# event=event,
# for_what=ForWhat.FOR_USER,
# state_data={"age": event.object.object.message.text},
# )
# user_data = await fsm.get_data(event=event, for_what=ForWhat.FOR_USER)
#
# # finish poll and delete the user
# # `fsm.finish` will do it
# await fsm.finish(event=event, for_what=ForWhat.FOR_USER)
# return f"Your data - {user_data}"

BIN
img.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 131 B

View File

@ -1,21 +1,20 @@
from vkwave.bots import Keyboard, ButtonColor
# menu
MENU = """Здравствуйте, дорогие друзья Инженерной школы НГУ!
Мы создали этого бота, чтобы помочь вам ориентироваться в информации про ИШ. Вы можете:
MENU = """С помощью бота вы можете:
&#9881; пройти тест и получить индивидуальный NFT-талисман, сгенерированный специально для вас нейросетью;
&#9881; вступить в чат абитуриентов, студентов и преподавателей;
&#9881; пообщаться со студентом (можно выбрать, с кем);
&#9881; пообщаться с руководителем ИШ или преподавателем (можно выбрать, с кем);
Добро пожаловать!"""
&#9881; пообщаться со студентом (можно выбрать с кем);
&#9881; пообщаться с руководителем ИШ или преподавателем (можно выбрать с кем)."""
MENU_KB = Keyboard()
MENU_KB.add_text_button(text="Пройти тест", payload={"test": "-1"}, color=ButtonColor.POSITIVE)
MENU_KB.add_link_button(text="Чат абитуриентов", link="https://vk.me/join/AJQ1dw97/SBEQYIyQdZfG69y")
MENU_KB.add_row()
MENU_KB.add_text_button(text="Пообщаться со студентом", payload={"student": "1"}, color=ButtonColor.PRIMARY)
MENU_KB.add_row()
MENU_KB.add_text_button(text="Задать вопрос преподавателю", payload={"teacher": "1"}, color=ButtonColor.PRIMARY)
MENU_KB.add_text_button(text="Пообщаться с преподавателем", payload={"teacher": "1"}, color=ButtonColor.PRIMARY)
# MENU_KB.add_row()
# MENU_KB.add_text_button(text="АЧе делать?", payload={"man": "1"}, color=ButtonColor.PRIMARY)
# Student menu
ST_MENU = """Если вы ходите узнать про жизнь студента Инженерной школы, то можете написать этим ребятам:
@ -58,6 +57,16 @@ TC_KB.add_link_button(text="Юрий Даниилович", link="https://vk.com
TC_KB.add_row()
TC_KB.add_text_button(text="Вернуться на главную", payload={}, color=ButtonColor.NEGATIVE)
# Manual
MAN = """Если вы хотите пройти тест - нажми на соответствующую кнопку.
Если вы абитуриент, и хотите узнать больше про инженерную школу, то вы можете пообщаться со студентами или преподавателями!
Для этого нажмите на кнопку “Диалог со студентом” или “Диалог с преподавателем”.
Также вы можете узнать про нас из соцсетей - для этого нажмите на кнопку “Таплинк”.
Если вы хотите пообщаться с другими абитуриентами - нажми на кнопку “Неформальный чат”.
Приятного пользования!"""
MAN_KB = Keyboard()
MAN_KB.add_text_button(text="ХОЧУ ДОМОЙ!!!!!!!!!!!!!!!", payload={}, color=ButtonColor.NEGATIVE)
# TEST Questions
INPUT_NAME_TEXT = "Пожалуйста, введите имя:"
@ -67,9 +76,10 @@ WHAT_ENGINEER_ARE_YOU = "Кто ты из инженеров?"
WHAT_ENGINEER_ARE_YOU_KB = Keyboard()
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Илон Маск", payload={"q": "Илон Маск"}, color=ButtonColor.PRIMARY)
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Дмитрий Рогозин", payload={"q": "Дмитрий Рогозин"}, color=ButtonColor.PRIMARY)
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Никола Тесла", payload={"q": "Никола Тесла"}, color=ButtonColor.PRIMARY)
WHAT_ENGINEER_ARE_YOU_KB.add_row()
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Никола Тесла", payload={"q": "Никола Тесла"}, color=ButtonColor.PRIMARY)
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Иван Кулибин", payload={"q": "Иван Кулибин"}, color=ButtonColor.PRIMARY)
WHAT_ENGINEER_ARE_YOU_KB.add_row()
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Михаил Калашников", payload={"q": "Михаил Калашников"}, color=ButtonColor.PRIMARY)
WHAT_ENGINEER_ARE_YOU_KB.add_text_button(text="Юрий Кондратюк", payload={"q": "Юрий Кондратюк"}, color=ButtonColor.PRIMARY)
@ -92,9 +102,11 @@ FAV_THEME = "Какая школьная дисциплина нравится
FAV_THEME_KB = Keyboard()
FAV_THEME_KB.add_text_button(text="Математика", payload={"q": "Математика"}, color=ButtonColor.PRIMARY)
FAV_THEME_KB.add_text_button(text="Русский/Литература", payload={"q": "русскийлитра"}, color=ButtonColor.PRIMARY)
FAV_THEME_KB.add_text_button(text="Информатика/программирование", payload={"q": "Инфа"}, color=ButtonColor.PRIMARY)
FAV_THEME_KB.add_row()
FAV_THEME_KB.add_text_button(text="Информатика/программирование", payload={"q": "Инфа"}, color=ButtonColor.PRIMARY)
FAV_THEME_KB.add_text_button(text="Физика", payload={"q": "Физика"}, color=ButtonColor.PRIMARY)
FAV_THEME_KB.add_row()
FAV_THEME_KB.add_text_button(text="История/обществознание", payload={"q": "Инфа"}, color=ButtonColor.PRIMARY)
FAV_THEME_KB.add_text_button(text="Другой", payload={"q": "other"}, color=ButtonColor.PRIMARY)
# 4
@ -117,15 +129,14 @@ TRANS_ENGINEER_COUNT_KB.add_text_button(text="5", payload={"q": "5"}, color=Butt
# 6
ZODIAC = "Кто вы по знаку зодиака?"
# ZODIAC_KB = Keyboard()
# 7
CONTACT = "Введите почту или ник в телеграмме, по которому мы сможем прислать вам результаты"
# # 7
# CONTACT = "Введите почту или ник в телеграмме, по которому мы сможем прислать вам результаты"
# last
LAST_MESSAGE = "Спасибо, что прошли тест!"
LAST_MESSAGE = "Теперь у вас есть ваш персональный NFT-талисман! Он поможет вам при сдаче экзаменов и поступлении в желаемый университет &#127775;"
LAST_MESSAGE_KB = Keyboard()
LAST_MESSAGE_KB.add_text_button(text="Вернуться на главную", payload={}, color=ButtonColor.POSITIVE)
questions = [
(WHAT_ENGINEER_ARE_YOU, WHAT_ENGINEER_ARE_YOU_KB),
(PROG_LANG, PROG_LANG_KB),
@ -133,5 +144,5 @@ questions = [
(EGE, EGE_KB),
(TRANS_ENGINEER_COUNT, TRANS_ENGINEER_COUNT_KB),
(ZODIAC, None),
(CONTACT, None),
# (CONTACT, None),
]

View File

@ -3,7 +3,7 @@ import logging
from vkwave.bots import SimpleLongPollBot, PhotoUploader
from blueprints import (
menu_router, test_router, student_router, teacher_router,
menu_router, test_router, student_router, teacher_router, man_router,
)
from config import Config
from middlewares import UserMiddleware
@ -21,10 +21,10 @@ Config().uploader = uploader
bot.middleware_manager.add_middleware(UserMiddleware())
bot.middleware_manager.add_middleware(TestStateMiddleware())
bot.dispatcher.add_router(test_router)
bot.dispatcher.add_router(student_router)
bot.dispatcher.add_router(teacher_router)
bot.dispatcher.add_router(man_router)
# регаем последним чтобы сначала проверялись все остальные команды
bot.dispatcher.add_router(menu_router)

View File

@ -1,32 +1,14 @@
import base64
import io
import random
import os
from PIL import Image
from flask import Flask, request, jsonify
import matplotlib.image as mpimg
import numpy as np
import numba
import base64
app = Flask(__name__)
@numba.njit
def optimized_mandelbrot(n_rows, n_columns, iterations, cx, cy):
x_cor = np.linspace(-2, 2, n_rows)
y_cor = np.linspace(-2, 2, n_columns)
output = np.zeros((n_rows,n_columns))
c = cx + 1j * cy
for i in range(n_rows):
for j in range(n_columns):
z = x_cor[i] + y_cor[j] * 1j
count = 0
for k in range(iterations):
z = (z*z) + c
count += 1
if np.abs(z) > 4:
break
output[i, j] = count
return output.T
IMAGE_PATH = 'pics'
def open_image_as_array(path):
@ -34,21 +16,24 @@ def open_image_as_array(path):
def get_encoded_img(arr):
img = Image.fromarray(arr).convert("L")
img = Image.fromarray(arr)
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return encoded_img
return str(encoded_img)
@app.route('/getImage', methods=['GET'])
def get_image():
name = request.args.get('name')
fractal = optimized_mandelbrot(1000, 1000, np.random.randint(2, 251), np.random.uniform(-1, 1), np.random.uniform(-1, 1))
img = get_encoded_img(fractal)
# print(random.choice(os.listdir(IMAGE_PATH)))
file = os.path.join(IMAGE_PATH, random.choice(os.listdir(IMAGE_PATH)))
# buffered = io.BytesIO()
# image.save(buffered, format="JPEG")
# img_str = base64.b64encode(buffered.getvalue())
image = base64.encodebytes(open(file, 'rb').read()).decode('ascii')
return jsonify({
"code": 0,
"image": img,
"image": image,
"first_time": 1
})

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.