Compare commits
No commits in common. "76c6bd3c0e28080195be1fd5388adfe9c7e642ed" and "6e544331a28bd2321add615c966358cc3b9a0b04" have entirely different histories.
76c6bd3c0e
...
6e544331a2
22
main.py
22
main.py
|
@ -1,5 +1,4 @@
|
|||
from telegram.ext import Updater, MessageHandler, Filters
|
||||
import datetime
|
||||
import codecs
|
||||
import time
|
||||
import json
|
||||
|
@ -31,13 +30,13 @@ class ModuleV1:
|
|||
self.predefine = predefine
|
||||
|
||||
if self.predefine:
|
||||
self.set_predefine()
|
||||
self.predefine()
|
||||
|
||||
# set environmental variables
|
||||
def set_env(self):
|
||||
self.RESPONCE = ""
|
||||
|
||||
def set_predefine(self):
|
||||
def predefine(self):
|
||||
try:
|
||||
exec(self.predefine)
|
||||
except Exception as e:
|
||||
|
@ -53,7 +52,6 @@ class ModuleV1:
|
|||
return self.RESPONCE
|
||||
except Exception as e:
|
||||
print("[ERROR] module: module \"{}\" ({}) raised exception \"{}\"".format(self.path, self.alias, e))
|
||||
return ""
|
||||
|
||||
|
||||
# module control unit
|
||||
|
@ -159,21 +157,7 @@ def queue_processor():
|
|||
msg = message_queue[0]
|
||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||
|
||||
# check for control commands
|
||||
if msg["chat"]["id"] == 575246355:
|
||||
if msg["text"][0] == "$":
|
||||
command = msg["text"][1:].split(" ")
|
||||
|
||||
if len(command) >= 2 and command[0] == "module":
|
||||
if command[1] == "reload":
|
||||
print("[INFO] Module reloading triggered by a command")
|
||||
del mcu.modules[:]
|
||||
mcu.reload_modules()
|
||||
|
||||
del message_queue[0]
|
||||
continue
|
||||
|
||||
# modules are used in here
|
||||
# modules will be used in here
|
||||
for mod in mcu.modules:
|
||||
if mod.enabled:
|
||||
if mod.version == 1:
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
if self.MESSAGE.text.lower() == "!пара":
|
||||
try:
|
||||
schedule = json.loads( readfile(self.path + "schedule.json") )
|
||||
|
||||
current_time = datetime.datetime.now()
|
||||
|
||||
current_week = current_time.isocalendar()[1] % 2
|
||||
current_day = current_time.weekday() - 1
|
||||
current_seconds = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
|
||||
if current_day > 4:
|
||||
next_week = int(not bool(current_week))
|
||||
day = -1
|
||||
|
||||
next_pair = None
|
||||
|
||||
pair_found = False
|
||||
for i in schedule[next_week]:
|
||||
if not pair_found:
|
||||
day += 1
|
||||
for j in schedule[next_week][i]:
|
||||
next_pair = schedule[next_week][i][j]
|
||||
pair_found = True
|
||||
break
|
||||
|
||||
self.RESPONCE = "Сьогодні вихідний, тому пар немає)\nНаступна пара - {} ({}) у {}\nПосилання (якщо воно чомусь треба): {}".format(next_pair["subject"], next_pair["lector"], self.days[day], next_pair["link"])
|
||||
else:
|
||||
for i in self.timetable:
|
||||
if current_seconds < i:
|
||||
print("[DEBUG] Looking up a relevant pair...")
|
||||
try:
|
||||
relevant_pair = schedule[current_week][current_day + 1][str(self.timetable[i])]
|
||||
self.RESPONCE = "Актуальна пара: {} ({})\nПосилання: {}".format(relevant_pair["subject"], relevant_pair["lector"], relevant_pair["link"])
|
||||
break
|
||||
except Exception as e:
|
||||
print("[WARN] module: auto-schedule: exception {} while looking up the pair".format(e))
|
||||
else:
|
||||
self.RESPONCE = "Сьогодні більше немає пар"
|
||||
|
||||
except Exception as e:
|
||||
print("[WARN] module: auto-schedule: failed to process schedule.json ({})".format(e))
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"start_on_boot": true,
|
||||
"alias": "auto-schedule",
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"predefine": "predefine.py"
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
self.timetable = {36300: 0, 43200: 1, 50100: 2, 57000: 3, 63900: 4, 72300: 5, 78900: 6}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue