codestyle
This commit is contained in:
@@ -10,14 +10,19 @@ bot = telebot.TeleBot("1994460106:AAGrGsCZjF6DVG_T-zycELuVfxnWw8x7UyU")
|
||||
|
||||
@bot.message_handler(commands=["start"])
|
||||
def do_action(message: Message):
|
||||
bot.send_message(message.chat.id, "Привет! Я тут чтобы помогать!\n/register - зарегистрироваться в сервисе\nБольше команд нет:(")
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
"Привет! Я тут чтобы помогать!\n/register - зарегистрироваться в сервисе\nБольше команд нет:(",
|
||||
)
|
||||
|
||||
|
||||
@bot.message_handler(commands=["register"])
|
||||
def register(message: Message):
|
||||
username = message.from_user.username
|
||||
if username == "" or message.from_user.username is None:
|
||||
bot.send_message(message.chat.id, "Добавть имя пользователя к своему телеграм аккаунту")
|
||||
bot.send_message(
|
||||
message.chat.id, "Добавть имя пользователя к своему телеграм аккаунту"
|
||||
)
|
||||
return
|
||||
ui = UserInfo.objects.filter(telegram_chat_id=message.chat.id).first()
|
||||
if ui:
|
||||
@@ -27,21 +32,30 @@ def register(message: Message):
|
||||
ui = UserInfo.objects.create(user=user, telegram_chat_id=message.chat.id)
|
||||
name = message.from_user.first_name
|
||||
surname = message.from_user.last_name
|
||||
if surname is None or surname == '' or name is None or name == '':
|
||||
bot.send_message(message.chat.id, 'Приветствую в Sprint! Сейчас я помогу тебе создать аккаунт.\nДля начала отправь мне свою фамилию')
|
||||
if surname is None or surname == "" or name is None or name == "":
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
"Приветствую в Sprint! Сейчас я помогу тебе создать аккаунт.\nДля начала отправь мне свою фамилию",
|
||||
)
|
||||
else:
|
||||
ui.surname = surname
|
||||
ui.name = name
|
||||
ui.verified = True
|
||||
ui.save()
|
||||
bot.send_message(message.chat.id, f"Регистрация завершена! Теперь можешь ты можешь войти в сервис под именем пользователя: {user.username}")
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
f"Регистрация завершена! Теперь можешь ты можешь войти в сервис под именем пользователя: {user.username}",
|
||||
)
|
||||
|
||||
|
||||
@bot.message_handler(content_types=["text"])
|
||||
def do_action(message: Message):
|
||||
user = User.objects.filter(userinfo__telegram_chat_id=message.chat.id).first()
|
||||
if not user:
|
||||
bot.send_message(message.chat.id, "Зарегистрируйся в сервисе, чтобы взаимодействовать со мной")
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
"Зарегистрируйся в сервисе, чтобы взаимодействовать со мной",
|
||||
)
|
||||
return
|
||||
if user.userinfo.surname is None:
|
||||
user.userinfo.surname = message.text
|
||||
@@ -51,15 +65,18 @@ def do_action(message: Message):
|
||||
user.userinfo.name = message.text
|
||||
user.userinfo.verified = True
|
||||
user.userinfo.save()
|
||||
bot.send_message(message.chat.id, f"Регистрация завершена! Теперь можешь ты можешь войти в сервис под именем пользователя: {user.username}")
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
f"Регистрация завершена! Теперь можешь ты можешь войти в сервис под именем пользователя: {user.username}",
|
||||
)
|
||||
else:
|
||||
bot.send_message(message.chat.id, "Я пока больше ничего не умею")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'starts bot'
|
||||
help = "starts bot"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print('bot is starting')
|
||||
print("bot is starting")
|
||||
bot.polling()
|
||||
print('bot failed')
|
||||
print("bot failed")
|
||||
|
@@ -9,29 +9,31 @@ from SprintLib.testers import *
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Tests solution'
|
||||
help = "Tests solution"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Enter worker")
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host=settings.RABBIT_HOST))
|
||||
connection = pika.BlockingConnection(
|
||||
pika.ConnectionParameters(host=settings.RABBIT_HOST)
|
||||
)
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(queue='test')
|
||||
channel.queue_declare(queue="test")
|
||||
|
||||
def callback(ch, method, properties, body):
|
||||
try:
|
||||
id = int(str(body, encoding='utf-8'))
|
||||
id = int(str(body, encoding="utf-8"))
|
||||
print(f"Received id {id}")
|
||||
while True:
|
||||
try:
|
||||
solution = Solution.objects.get(id=id)
|
||||
break
|
||||
except:
|
||||
sleep(.5)
|
||||
eval(solution.language.work_name + 'Tester')(solution).execute()
|
||||
sleep(0.5)
|
||||
eval(solution.language.work_name + "Tester")(solution).execute()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
solution.result = 'TE'
|
||||
solution.result = "TE"
|
||||
solution.save()
|
||||
|
||||
channel.basic_consume(queue='test', on_message_callback=callback, auto_ack=True)
|
||||
channel.basic_consume(queue="test", on_message_callback=callback, auto_ack=True)
|
||||
channel.start_consuming()
|
||||
|
@@ -3,7 +3,7 @@ from FileStorage.root import runserver
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'starts FileStorage'
|
||||
help = "starts FileStorage"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
runserver()
|
||||
|
Reference in New Issue
Block a user