honor, force, sick
This commit is contained in:
parent
0f405d370a
commit
bbd59e4ad0
220
bot.py
220
bot.py
|
@ -84,7 +84,7 @@ def pop_db(field: str):
|
|||
|
||||
|
||||
load_db()
|
||||
write_db("about.version", "v1.0rc3")
|
||||
write_db("about.version", "v1.0rc4")
|
||||
write_db("about.author", "electromagneticcyclone")
|
||||
write_db("about.tester", "angelbeautifull")
|
||||
if (read_db("about.host") is None) and __debug__:
|
||||
|
@ -210,6 +210,45 @@ def format_user_info(forum: int, uid):
|
|||
+ telebot.formatting.escape_markdown(i) + '\n')
|
||||
return r
|
||||
|
||||
def prepend_user(forum: int, ulist_s: str, uid):
|
||||
uid = str(uid)
|
||||
ulist = read_db(str(forum) + "." + ulist_s, [])
|
||||
ulist = list(set([uid] + ulist))
|
||||
write_db(str(forum) + "." + ulist_s, ulist)
|
||||
|
||||
def append_user(forum: int, ulist_s: str, uid):
|
||||
uid = str(uid)
|
||||
ulist = read_db(str(forum) + "." + ulist_s, [])
|
||||
ulist = list(set(ulist + [uid]))
|
||||
write_db(str(forum) + "." + ulist_s, ulist)
|
||||
|
||||
def pop_user(forum: int, ulist_s: str, uid):
|
||||
uid = str(uid)
|
||||
ulist = read_db(str(forum) + "." + ulist_s, [])
|
||||
r = None
|
||||
if len(ulist) > 0:
|
||||
r = ulist.pop(0)
|
||||
write_db(str(forum) + "." + ulist_s, ulist)
|
||||
return r
|
||||
|
||||
def insert_user_in_current_order(forum: int, uid) -> bool:
|
||||
uid = str(uid)
|
||||
order = read_db(str(forum) + ".rookies.order", [])
|
||||
people = read_db(str(forum) + ".people", {})
|
||||
current = read_db(str(forum) + ".rookies.current")
|
||||
if uid not in people:
|
||||
return False
|
||||
order = list(map(lambda x: (x, people[x]), order))
|
||||
if current is not None:
|
||||
order = dict(sorted(list(order.items()) + [(current, people[current])], key = lambda item: item[1]["surname"]))
|
||||
order = dict(sorted(list(order.items()) + [uid, people[uid]], key = lambda item: item[1]["surname"]))
|
||||
pos = list(order.keys()).index(current)
|
||||
if pos == 0:
|
||||
return False
|
||||
else:
|
||||
write_db(str(forum) + ".rookies.order", list(order.keys())[1:])
|
||||
return True
|
||||
|
||||
timeout = None
|
||||
caution = True
|
||||
def antispam(message, chat, forum):
|
||||
|
@ -272,9 +311,9 @@ def help(message):
|
|||
+ "/phase \\[Числитель/знаменатель\\] — узнать или скорректировать фазу текущей недели\n"
|
||||
+ "/skip \\[00\\.00\\] — пропустить сегодняшний или заданный день\n"
|
||||
+ "/work \\[00\\.00\\] — поработать в сегодняшнем или заданном дне\n"
|
||||
+ "*TODO* /honor \\[\\-\\]@ — пропуск следующего дежурства, так как студент молодец\n"
|
||||
+ "*TODO* /sick @ \\[дата\\] — пропуск дежурства по причине болезни\n"
|
||||
+ "*TODO* /force \\[\\-\\]@ — провинившийся дежурит как только так сразу\n"
|
||||
+ "/honor \\[\\-\\]@ — пропуск следующего дежурства, так как студент молодец\n"
|
||||
+ "/sick @ \\[дата\\] — пропуск дежурства по причине болезни\n"
|
||||
+ "/force \\[\\-\\]@ — провинившийся дежурит как только так сразу\n"
|
||||
+ "/stop — остановить дежурства\n"
|
||||
+ "/begin \\[@\\] — начать сначала с определённого студента")
|
||||
|
||||
|
@ -818,6 +857,131 @@ def stop_queue(message):
|
|||
bot.delete_message(forum, message.id)
|
||||
bot.reply_to(chat, "Держурство остановлено")
|
||||
|
||||
@bot.message_handler(commands=['honor'])
|
||||
def add_honor(message):
|
||||
forum = message.chat.id
|
||||
chat = get_chat(message)
|
||||
if chat is not None:
|
||||
if antispam(message, chat, forum):
|
||||
return
|
||||
if check_if_admin(message):
|
||||
args = message.text.split()[1:]
|
||||
if len(args) != 1:
|
||||
bot.reply_to(chat, "Нужно указать человека")
|
||||
return
|
||||
user = args[0]
|
||||
if user[1:] == bot.get_me().username:
|
||||
bot.reply_to(chat, "Рад, что всегда в почёте")
|
||||
return
|
||||
f = find_uids(forum, user)
|
||||
if f is None:
|
||||
bot.reply_to(chat, "Никого не нашёл")
|
||||
return
|
||||
if len(f) > 1:
|
||||
bot.reply_to(chat, "Немогу определиться…")
|
||||
list_users(message)
|
||||
bot.reply_to(chat, "Конкретезируй плиз")
|
||||
return
|
||||
user = f[0]
|
||||
force = read_db(str(forum) + ".rookies.force_order", [])
|
||||
honor = read_db(str(forum) + ".rookies.honor_order", [])
|
||||
honor.append(user)
|
||||
for i in people:
|
||||
if (i in force) and (i in honor):
|
||||
force.remove(i)
|
||||
honor.remove(i)
|
||||
write_db(str(forum) + ".rookies.force_order", force)
|
||||
write_db(str(forum) + ".rookies.honor_order", honor)
|
||||
if read_db(str(forum) + ".settings.delete_messages"):
|
||||
bot.delete_message(forum, message.id)
|
||||
bot.reply_to(chat, "Готово")
|
||||
|
||||
@bot.message_handler(commands=['force'])
|
||||
def add_force(message):
|
||||
forum = message.chat.id
|
||||
chat = get_chat(message)
|
||||
if chat is not None:
|
||||
if antispam(message, chat, forum):
|
||||
return
|
||||
if check_if_admin(message):
|
||||
args = message.text.split()[1:]
|
||||
if len(args) != 1:
|
||||
bot.reply_to(chat, "Нужно указать человека")
|
||||
return
|
||||
user = args[0]
|
||||
if user[1:] == bot.get_me().username:
|
||||
bot.reply_to(chat, "Рад, что всегда в почёте")
|
||||
return
|
||||
f = find_uids(forum, user)
|
||||
if f is None:
|
||||
bot.reply_to(chat, "Никого не нашёл")
|
||||
return
|
||||
if len(f) > 1:
|
||||
bot.reply_to(chat, "Немогу определиться…")
|
||||
list_users(message)
|
||||
bot.reply_to(chat, "Конкретезируй плиз")
|
||||
return
|
||||
user = f[0]
|
||||
force = read_db(str(forum) + ".rookies.force_order", [])
|
||||
honor = read_db(str(forum) + ".rookies.honor_order", [])
|
||||
force.append(user)
|
||||
for i in people:
|
||||
if (i in force) and (i in honor):
|
||||
force.remove(i)
|
||||
honor.remove(i)
|
||||
write_db(str(forum) + ".rookies.force_order", force)
|
||||
write_db(str(forum) + ".rookies.honor_order", honor)
|
||||
if read_db(str(forum) + ".settings.delete_messages"):
|
||||
bot.delete_message(forum, message.id)
|
||||
bot.reply_to(chat, "Готово")
|
||||
|
||||
@bot.message_handler(commands=['sick'])
|
||||
def add_sick(message):
|
||||
forum = message.chat.id
|
||||
chat = get_chat(message)
|
||||
if chat is not None:
|
||||
if antispam(message, chat, forum):
|
||||
return
|
||||
if check_if_admin(message):
|
||||
args = message.text.split()[1:]
|
||||
if len(args) not in (1, 2):
|
||||
bot.reply_to(chat, "Нужно указать человека и дату выздоровления")
|
||||
return
|
||||
user = args[0]
|
||||
if user[1:] == bot.get_me().username:
|
||||
if read_db(str(forum) + ".settings.delete_messages"):
|
||||
bot.delete_message(forum, message.id)
|
||||
bot.reply_to(chat, "Ты сейчас быканул\\?")
|
||||
return
|
||||
f = find_uids(forum, user)
|
||||
if f is None:
|
||||
bot.reply_to(chat, "Никого не нашёл")
|
||||
return
|
||||
if len(f) > 1:
|
||||
bot.reply_to(chat, "Немогу определиться…")
|
||||
list_users(message)
|
||||
bot.reply_to(chat, "Конкретезируй плиз")
|
||||
return
|
||||
user = f[0]
|
||||
if len(args) > 1:
|
||||
dates = parse_dates(args[1:])
|
||||
if type(dates) is str:
|
||||
bot.reply_to(chat, telebot.formatting.escape_markdown(dates)
|
||||
+ " — это точно дата из ближайшего будущего?")
|
||||
return
|
||||
if dates is None:
|
||||
bot.reply_to(chat, "Нечего добавлять")
|
||||
return
|
||||
date = dates[0]
|
||||
else:
|
||||
date = get_time(forum).date() + dt.timedelta(days=30)
|
||||
sicks = read_db(str(forum) + ".rookies.sick_order", {})
|
||||
sicks[user] = (date, False)
|
||||
write_db(str(forum) + ".rookies.sick_order", sicks)
|
||||
if read_db(str(forum) + ".settings.delete_messages"):
|
||||
bot.delete_message(forum, message.id)
|
||||
bot.reply_to(chat, "Готово")
|
||||
|
||||
@bot.message_handler(commands=['begin'])
|
||||
def begin_queue(message):
|
||||
forum = message.chat.id
|
||||
|
@ -953,29 +1117,59 @@ def get_hours(forum: int) -> list:
|
|||
# return list(range(utc_range[0], utc_range[1]))
|
||||
|
||||
def stack_update(forum: int, force_reset = False):
|
||||
now = get_time(forum)
|
||||
now_date = now.date()
|
||||
order = read_db(str(forum) + ".rookies.order", [])
|
||||
force = read_db(str(forum) + ".rookies.force_order", [])
|
||||
honor = read_db(str(forum) + ".rookies.honor_order", [])
|
||||
sicks = read_db(str(forum) + ".rookies.sick_order", [])
|
||||
sicks = read_db(str(forum) + ".rookies.sick_order", {})
|
||||
people = read_db(str(forum) + ".people", {})
|
||||
for i in sicks:
|
||||
if now_date >= sicks[i][0]:
|
||||
if sicks[i][1]:
|
||||
prepend_user(forum, ".rookies.force_order", i)
|
||||
sicks.pop(i)
|
||||
write_db(str(forum) + ".rookies.sick_order", sicks)
|
||||
for i in people:
|
||||
if (i in force) and (i in honor):
|
||||
force.remove(i)
|
||||
honor.remove(i)
|
||||
write_db(str(forum) + ".rookies.force_order", force)
|
||||
write_db(str(forum) + ".rookies.honor_order", honor)
|
||||
for i in order:
|
||||
if i not in people.keys():
|
||||
order.remove(i)
|
||||
print(order)
|
||||
if len(order) == 0 or force_reset != False:
|
||||
order = list(dict(sorted(people.items(), key = lambda item: item[1]["surname"])).keys())
|
||||
if force_reset != False:
|
||||
write_db(str(forum) + ".rookies.force_order", [])
|
||||
write_db(str(forum) + ".rookies.honor_order", [])
|
||||
write_db(str(forum) + ".rookies.sick_order", {})
|
||||
if force_reset is not None:
|
||||
try:
|
||||
order = order[order.index(force_reset):]
|
||||
except:
|
||||
pass
|
||||
write_db(str(forum) + ".rookies.order", order)
|
||||
if len(order) == 0:
|
||||
return
|
||||
if force_reset == False:
|
||||
write_db(str(forum) + ".rookies.current", order[0])
|
||||
print(people[order[0]]["surname"])
|
||||
order.pop(0)
|
||||
write_db(str(forum) + ".rookies.order", order)
|
||||
if len(force) > 0:
|
||||
write_db(str(forum) + ".rookies.current", pop_user(forum, "rookies.force_order"))
|
||||
else:
|
||||
current = pop_user(forum, "rookies.order")
|
||||
if current in honor:
|
||||
honor.remove(current)
|
||||
write_db(str(forum) + ".rookies.honor_order", honor)
|
||||
stack_update(forum)
|
||||
elif any([(sicks[i][1] == False) and (i == current) for i in sicks]):
|
||||
skipped = list(sicks[current])
|
||||
skipped[1] = True
|
||||
sicks[current] = tuple(skipped)
|
||||
write_db(str(forum) + ".rookies.sick_order", sicks)
|
||||
stack_update(forum)
|
||||
else:
|
||||
write_db(str(forum) + ".rookies.current", pop_user(forum, "rookies.order"))
|
||||
|
||||
def clean_old_dates(date, array: str):
|
||||
a = read_db(array)
|
||||
|
@ -1007,12 +1201,6 @@ def update(forum: int):
|
|||
remind_users(forum)
|
||||
|
||||
|
||||
# Debug
|
||||
def day(forum: int):
|
||||
pop_db(str(forum) + ".schedule.last_notification_date")
|
||||
pop_db(str(forum) + ".schedule.last_stack_update_date")
|
||||
return "Ok"
|
||||
|
||||
def process1():
|
||||
bot.infinity_polling(none_stop=True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue