daemons
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from Main.models import LanguageApply, Set
|
||||
from SprintLib.language import languages
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "starts FileStorage"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for language in languages:
|
||||
apply = LanguageApply.objects.filter(language_id=language.id, applied=True).first()
|
||||
if apply is None:
|
||||
for s in Set.objects.filter(auto_add_new_languages=True):
|
||||
if language.id not in s.languages:
|
||||
s.languages.append(language.id)
|
||||
s.save()
|
||||
obj, _ = LanguageApply.objects.get_or_create(language_id=language.id)
|
||||
obj.applied = True
|
||||
obj.save()
|
@@ -1,86 +0,0 @@
|
||||
import os
|
||||
|
||||
import telebot
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.base import BaseCommand
|
||||
from telebot.types import Message
|
||||
|
||||
from Main.models import UserInfo
|
||||
|
||||
|
||||
# инстанс бота
|
||||
bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
|
||||
|
||||
|
||||
@bot.message_handler(commands=["start"])
|
||||
def do_action(message: Message):
|
||||
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, "Добавть имя пользователя к своему телеграм аккаунту"
|
||||
)
|
||||
return
|
||||
ui = UserInfo.objects.filter(telegram_chat_id=message.chat.id).first()
|
||||
if ui:
|
||||
bot.send_message(message.chat.id, "Ты уже зарегистрировался")
|
||||
return
|
||||
user = User.objects.create(username=username)
|
||||
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Для начала отправь мне свою фамилию",
|
||||
)
|
||||
else:
|
||||
ui.surname = surname
|
||||
ui.name = name
|
||||
ui.verified = True
|
||||
ui.save()
|
||||
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,
|
||||
"Зарегистрируйся в сервисе, чтобы взаимодействовать со мной",
|
||||
)
|
||||
return
|
||||
if user.userinfo.surname is None:
|
||||
user.userinfo.surname = message.text
|
||||
user.userinfo.save()
|
||||
bot.send_message(message.chat.id, "Отлично! Теперь отправь мне свое имя")
|
||||
elif user.userinfo.name is None:
|
||||
user.userinfo.name = message.text
|
||||
user.userinfo.verified = True
|
||||
user.userinfo.save()
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
f"Регистрация завершена! Теперь можешь ты можешь войти в сервис под именем пользователя: {user.username}",
|
||||
)
|
||||
else:
|
||||
bot.send_message(message.chat.id, "Я пока больше ничего не умею")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "starts bot"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("bot is starting")
|
||||
bot.polling()
|
||||
print("bot failed")
|
@@ -1,21 +0,0 @@
|
||||
import datetime
|
||||
from time import sleep
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
|
||||
from Checker.models import Checker
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "starts loop"
|
||||
|
||||
def check_checkers(self):
|
||||
for checker in Checker.objects.filter(testing_solution__isnull=False, last_request__lt=timezone.now() - datetime.timedelta(seconds=3)):
|
||||
checker.testing_solution.result = 'In queue'
|
||||
checker.testing_solution.save()
|
||||
|
||||
def handle(self, *args, **options):
|
||||
while True:
|
||||
self.check_checkers()
|
||||
sleep(5)
|
@@ -1,44 +0,0 @@
|
||||
from os.path import join, exists
|
||||
from shutil import rmtree
|
||||
|
||||
import pika
|
||||
from django.core.management.base import BaseCommand
|
||||
from pika.adapters.utils.connection_workflow import AMQPConnectionWorkflowFailed
|
||||
|
||||
from Main.models import Solution
|
||||
from Sprint import settings
|
||||
from SprintLib.testers import *
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Tests solution"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Enter worker")
|
||||
while True:
|
||||
try:
|
||||
connection = pika.BlockingConnection(
|
||||
pika.ConnectionParameters(host=settings.RABBIT_HOST)
|
||||
)
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(queue="test")
|
||||
|
||||
def callback(ch, method, properties, body):
|
||||
id = int(str(body, encoding="utf-8"))
|
||||
print(f"Received id {id}")
|
||||
solution = Solution.objects.get(id=id)
|
||||
try:
|
||||
eval(solution.language.work_name + "Tester")(solution).execute()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
solution.result = "TE"
|
||||
solution.save()
|
||||
finally:
|
||||
path = join("solutions", str(id))
|
||||
if exists(path):
|
||||
rmtree(path)
|
||||
|
||||
channel.basic_consume(queue="test", on_message_callback=callback, auto_ack=True)
|
||||
channel.start_consuming()
|
||||
except AMQPConnectionWorkflowFailed:
|
||||
print("connection to rabbit failed: reconnecting")
|
@@ -1,9 +0,0 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from FileStorage.root import runserver
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "starts FileStorage"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
runserver()
|
@@ -1,10 +0,0 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from Main.management.commands.bot import bot
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
for user in User.objects.filter(is_superuser=True):
|
||||
bot.send_message(user.userinfo.telegram_chat_id, "Деплой прошел успешно")
|
@@ -1,7 +1,7 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Q
|
||||
|
||||
from Main.management.commands.bot import bot
|
||||
from daemons import bot
|
||||
from Main.models import Friendship
|
||||
from SprintLib.BaseView import BaseView
|
||||
from SprintLib.language import languages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from django.contrib.auth import login
|
||||
|
||||
from Main.management.commands.bot import bot
|
||||
from daemons import bot
|
||||
from SprintLib.BaseView import BaseView
|
||||
from django.contrib.auth.models import User
|
||||
from random import randrange
|
||||
|
Reference in New Issue
Block a user