Birthdays notification made
This commit is contained in:
parent
2f24739cbb
commit
9ea575b2cb
@ -65,6 +65,6 @@ After all of that you're good to go! Happy using :)
|
|||||||
* [x] Get applications .json
|
* [x] Get applications .json
|
||||||
* [ ] Get application by id and user_id
|
* [ ] Get application by id and user_id
|
||||||
* [x] Age as a DD.MM.YYYY
|
* [x] Age as a DD.MM.YYYY
|
||||||
* [ ] Notify about upcoming birthdays
|
* [x] Notify about upcoming birthdays
|
||||||
* [x] Change the application data
|
* [x] Change the application data
|
||||||
* [x] Check if user is already in group
|
* [x] Check if user is already in group
|
@ -2,6 +2,8 @@
|
|||||||
"locale": "uk",
|
"locale": "uk",
|
||||||
"owner": 0,
|
"owner": 0,
|
||||||
"age_allowed": 0,
|
"age_allowed": 0,
|
||||||
|
"birthdays_notify": true,
|
||||||
|
"birthdays_time": "09:00",
|
||||||
"admin_group": 0,
|
"admin_group": 0,
|
||||||
"destination_group": 0,
|
"destination_group": 0,
|
||||||
"admins": [],
|
"admins": [],
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
"sus_refused_by": "❌ **Доступ заборонено**\nАдмін **{0}** заборонив `{1}` доступ до спільноти не за персональним посиланням.",
|
"sus_refused_by": "❌ **Доступ заборонено**\nАдмін **{0}** заборонив `{1}` доступ до спільноти не за персональним посиланням.",
|
||||||
"reapply_forbidden": "❌ **Дія неможлива**\nТвоя минула анкета ще не була схвалена або відхилена.",
|
"reapply_forbidden": "❌ **Дія неможлива**\nТвоя минула анкета ще не була схвалена або відхилена.",
|
||||||
"reapply_in_progress": "❌ **Дія неможлива**\nТи прямо зараз вже заповнюєш анкету. Якщо в ній є помилка - після заповнення просто натисни **{0}** та почни знову.",
|
"reapply_in_progress": "❌ **Дія неможлива**\nТи прямо зараз вже заповнюєш анкету. Якщо в ній є помилка - після заповнення просто натисни **{0}** та почни знову.",
|
||||||
|
"birthday": "У користувача **{0}** (@{1}) сьогодні день народження! Виповнилось {2} років",
|
||||||
"question_titles": {
|
"question_titles": {
|
||||||
"question1": "Ім'я/звертання:",
|
"question1": "Ім'я/звертання:",
|
||||||
"question2": "День народження:",
|
"question2": "День народження:",
|
||||||
|
23
main.py
23
main.py
@ -1,8 +1,11 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from threading import Thread
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from time import time
|
from time import time
|
||||||
from os import getpid, path
|
from os import getpid, path
|
||||||
|
from modules.birthdays import check_birthdays
|
||||||
from modules.utils import *
|
from modules.utils import *
|
||||||
|
from schedule import run_pending, every
|
||||||
|
|
||||||
from pyrogram.client import Client
|
from pyrogram.client import Client
|
||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
@ -558,6 +561,26 @@ if __name__ == "__main__":
|
|||||||
# I did compare performance, almost no difference and it's much more useful this way. Change my mind.
|
# I did compare performance, almost no difference and it's much more useful this way. Change my mind.
|
||||||
app.start() # type: ignore
|
app.start() # type: ignore
|
||||||
|
|
||||||
|
if configGet("birthdays_notify"):
|
||||||
|
|
||||||
|
every().day.at(configGet("birthdays_time")).do(check_birthdays, app)
|
||||||
|
|
||||||
|
# Background tasks checker
|
||||||
|
def background_task():
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
run_pending()
|
||||||
|
#print('Checked')
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('\nShutting down')
|
||||||
|
killProc(pid)
|
||||||
|
t = Thread(target=background_task)
|
||||||
|
t.start()
|
||||||
|
|
||||||
app.send_message(configGet("owner"), f"Starting up with pid `{pid}`") # type: ignore
|
app.send_message(configGet("owner"), f"Starting up with pid `{pid}`") # type: ignore
|
||||||
|
|
||||||
# Registering user commands
|
# Registering user commands
|
||||||
|
18
modules/birthdays.py
Normal file
18
modules/birthdays.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from os import fsdecode, listdir, sep
|
||||||
|
from modules.utils import configGet, jsonLoad, locale
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
|
|
||||||
|
def check_birthdays(app):
|
||||||
|
for user_file in listdir(f"{configGet('data', 'locations')}{sep}users{sep}"):
|
||||||
|
filename = fsdecode(f"{configGet('data', 'locations')}{sep}users{sep}{user_file}")
|
||||||
|
if filename.endswith(".json"):
|
||||||
|
user = jsonLoad(filename)
|
||||||
|
if isinstance(user["application"]["2"], str):
|
||||||
|
try:
|
||||||
|
if ".".join([((user["application"]["2"]).split("."))[0], ((user["application"]["2"]).split("."))[1]]) == datetime.now().strftime("%d.%m"):
|
||||||
|
tg_user = app.get_users(int(user_file.replace(".json", "")))
|
||||||
|
app.send_message( configGet("admin_group"), locale("birthday", "message").format(str(tg_user.first_name), str(tg_user.username), str(relativedelta(datetime.now(), datetime.strptime(user["application"]["2"], '%d.%m.%Y')).years)) )
|
||||||
|
except AttributeError:
|
||||||
|
continue
|
@ -2,3 +2,4 @@ pyrogram>=2.0.59
|
|||||||
tgcrypto>=1.2.4
|
tgcrypto>=1.2.4
|
||||||
ujson>=5.5.0
|
ujson>=5.5.0
|
||||||
psutil>=5.9.2
|
psutil>=5.9.2
|
||||||
|
schedule
|
Reference in New Issue
Block a user