mirror of
https://github.com/Llloooggg/Jarvis.git
synced 2026-03-06 03:56:23 +03:00
Объединил триггеры и эшены
This commit is contained in:
20
__init__.py
20
__init__.py
@@ -72,13 +72,13 @@ def workshop():
|
||||
new_scenario = db_routing.add_scenario(current_user.get_id(), newScenarioName, triggerID, triggerArgs,
|
||||
actionID,
|
||||
actionArgs)
|
||||
activeScenario = Executor(new_scenario)
|
||||
activeScenario = Executor(new_scenario, current_user.get_tg_id())
|
||||
activeScenario.start()
|
||||
return redirect(url_for('workshop'))
|
||||
|
||||
if 'TGUsername' in request.form:
|
||||
new_tg_username = request.form['TGUsername']
|
||||
db_routing.tg_username_update(current_user.get_id(), new_tg_username)
|
||||
if 'TGID' in request.form:
|
||||
new_tg_id = request.form['TGID']
|
||||
db_routing.tg_id_update(current_user.get_id(), new_tg_id)
|
||||
return redirect(url_for('workshop'))
|
||||
|
||||
if 'ScenarioID' in request.form:
|
||||
@@ -91,16 +91,16 @@ def workshop():
|
||||
user_scripts_list = db_routing.get_user_scripts(current_user.get_id())
|
||||
User = db_routing.get_user(id=current_user.get_id())
|
||||
if User:
|
||||
tg_username = User.tg_username
|
||||
tg_id = User.tg_id
|
||||
else:
|
||||
tg_username = None
|
||||
tg_id = None
|
||||
return render_template('workshop.html', triggers_list=triggers_list, actions_list=actions_list,
|
||||
user_scripts_list=user_scripts_list, tg_username=tg_username)
|
||||
user_scripts_list=user_scripts_list, tg_id=tg_id)
|
||||
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def universal_error(error):
|
||||
return render_template('error.html'), 404
|
||||
# @app.errorhandler(Exception)
|
||||
# def universal_error(error):
|
||||
# return render_template('error.html'), 404
|
||||
|
||||
|
||||
def string_check(string):
|
||||
|
||||
17
actions.py
17
actions.py
@@ -1,16 +1,18 @@
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.header import Header
|
||||
from flask_login import current_user
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
import telegram
|
||||
|
||||
|
||||
def test_action(var, tg_id):
|
||||
print(var)
|
||||
|
||||
|
||||
# Ответ на письмо
|
||||
# формат строки (логин#пароль#адресат#текст)
|
||||
# send_mail_config='login@gmail.com#Password123#myfriend@gmail.com#Текст сообщения'
|
||||
|
||||
def send_mail(send_mail_config):
|
||||
|
||||
def send_mail(send_mail_config, tg_id):
|
||||
send_mail_list = send_mail_config.split('#')
|
||||
mail_sender = send_mail_list[0] # отправитель
|
||||
mail_receiver = send_mail_list[2] # адресат
|
||||
@@ -32,6 +34,5 @@ def send_mail(send_mail_config):
|
||||
server.quit()
|
||||
|
||||
|
||||
def send_message_tg(text, user_id=current_user.get_tg_id()):
|
||||
telegram.send_message(user_id, text)
|
||||
|
||||
def send_message_tg(text, tg_id):
|
||||
telegram.send_message(tg_id, text)
|
||||
|
||||
@@ -127,7 +127,7 @@ def delete_scenario(scenario_id):
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def tg_username_update(current_user_id, new_tg_username):
|
||||
def tg_id_update(current_user_id, new_tg_username):
|
||||
current_user = User.query.filter_by(id=current_user_id).first()
|
||||
current_user.tg_username = new_tg_username
|
||||
db.session.commit()
|
||||
|
||||
@@ -5,8 +5,9 @@ import db_routing
|
||||
|
||||
|
||||
class Executor(Thread):
|
||||
def __init__(self, scenario):
|
||||
def __init__(self, scenario, tg_id):
|
||||
Thread.__init__(self)
|
||||
self.tg_id = tg_id
|
||||
self.sceanrio_id = scenario.id
|
||||
self.trigger_def = db_routing.get_trigers(scenario.id).def_name
|
||||
self.trigger_args = scenario.trigger_args
|
||||
@@ -15,9 +16,9 @@ class Executor(Thread):
|
||||
|
||||
def execute(self):
|
||||
trigger = getattr(triggers, self.trigger_def)
|
||||
trigger(self.trigger_args)
|
||||
trigger(self.trigger_args, self.tg_id)
|
||||
action = getattr(actions, self.action_def)
|
||||
action(self.action_args)
|
||||
action(self.action_args, self.tg_id)
|
||||
|
||||
def run(self):
|
||||
thread = Thread(target=self.execute)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import telebot
|
||||
|
||||
botToken = ''
|
||||
botToken = '1003282848:AAHM72fKodCByupZihiOdtTF1996fDsYB8A'
|
||||
bot = telebot.TeleBot(botToken)
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<section class="condition">
|
||||
<div class="form">
|
||||
<div class="form__title">
|
||||
Создать новый
|
||||
Создать новый сценарий
|
||||
</div>
|
||||
<form action="/workshop" method="POST" name="NewSceanrio">
|
||||
<div class="form_condition">
|
||||
@@ -133,11 +133,11 @@
|
||||
</div>
|
||||
<form action="/workshop" method="POST" name="Telegram">
|
||||
<label class="form__log">
|
||||
{% if tg_username %}
|
||||
<input class="form__input-text" name="TGUsername" placeholder=@{{ tg_username }}
|
||||
{% if tg_id %}
|
||||
<input class="form__input-text" name="TGID" placeholder=@{{ tg_id }}
|
||||
type="text">
|
||||
{% else %}
|
||||
<input class="form__input-text" name="TGUsername" placeholder="@Логин" type="text">
|
||||
<input class="form__input-text" name="TGID" placeholder="@Логин" type="text">
|
||||
{% endif %}
|
||||
</label>
|
||||
<div class="form__btns">
|
||||
|
||||
@@ -4,14 +4,14 @@ import imaplib
|
||||
import time
|
||||
|
||||
|
||||
def test_trigger(var):
|
||||
def test_trigger(var, tg_id):
|
||||
time.sleep(int(var))
|
||||
|
||||
|
||||
# Будильник
|
||||
# Формат строки (год месяц день час минута секунда)
|
||||
# Config_time='2020#3#22#15#20#0'
|
||||
def alarm_clock(config_time):
|
||||
def alarm_clock(config_time, tg_id):
|
||||
config_list = config_time.split('#')
|
||||
dt = datetime.datetime(int(config_list[0]), int(config_list[1]), int(config_list[2]), int(config_list[3]),
|
||||
int(config_list[4]),
|
||||
@@ -28,7 +28,7 @@ def alarm_clock(config_time):
|
||||
# Нужно включить https://myaccount.google.com/lesssecureapps и https://mail.google.com/mail/u/2/#settings/fwdandpop
|
||||
# Формат строки (логин#пароль)
|
||||
# check_mail_config='login@gmail.com Password123'
|
||||
def check_email(check_mail_config):
|
||||
def check_email(check_mail_config, tg_id):
|
||||
mail_config_list = check_mail_config.split('#')
|
||||
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
|
||||
mail.login(mail_config_list[0], mail_config_list[1])
|
||||
|
||||
Reference in New Issue
Block a user