-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
358da54
commit e130ca3
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from telegram import Update | ||
from telegram.ext import CallbackContext | ||
|
||
def edit_summary(current_situation, bot_last_message_id, update: Update, context: CallbackContext): | ||
context.bot.edit_message_text(chat_id=update.effective_chat.id, message_id=bot_last_message_id, | ||
parse_mode='markdown', text=current_situation) | ||
try: | ||
context.bot.pin_chat_message(chat_id=update.effective_chat.id, message_id=bot_last_message_id) | ||
except: | ||
print("No admin rights to pin the message") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from telegram import Update | ||
from telegram.ext import CallbackContext | ||
from telegram.utils.helpers import escape_markdown | ||
from db.queries import update_bot_last_message_id_on_db | ||
|
||
def print_new_summary(chat_id, current_situation, update: Update, context: CallbackContext): | ||
markdown_error = False | ||
try: | ||
msg = context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', | ||
text=current_situation) | ||
except: | ||
markdown_error = True | ||
error_message = "Sembra che tu abbia inserito nella descrizione un carattere speciale di telegram (`, *, _).\n" \ | ||
"Per favore cambiala con /setdescription <descrizione> assicurandoti di non inserire uno di questi caratteri.\n" \ | ||
"Se la tua intenzione era, invece, di formattare il testo, ricordati di usare anche il carattere di chiusura, come in questo *esempio*." | ||
msg = context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', | ||
text=escape_markdown(error_message)) | ||
if not markdown_error: | ||
try: | ||
context.bot.pin_chat_message(chat_id=update.effective_chat.id, message_id=msg.message_id) | ||
except: | ||
print("No admin rights to pin the message") | ||
update_bot_last_message_id_on_db(chat_id, msg.message_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def remove_job_if_exists(name, context): | ||
current_jobs = context.job_queue.get_jobs_by_name(name) | ||
if not current_jobs: | ||
return False | ||
for job in current_jobs: | ||
job.schedule_removal() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from jobs.payment_reminder import payment_reminder | ||
from utils.utils import extract_match_time, extract_match_day, compute_seconds_from_now | ||
|
||
def trigger_payment_reminder(update, context, day, time): | ||
chat_id = update.effective_message.chat_id | ||
match_time = extract_match_time(time) | ||
reminder_time_from_now = -1 | ||
|
||
if match_time == -1: | ||
match_date = extract_match_day(day) | ||
waiting_time_in_seconds = 36 * 3600 | ||
else: | ||
match_date = extract_match_day(f"{day} {time}") | ||
waiting_time_in_seconds = 2 * 3600 | ||
|
||
if match_date != -1: | ||
reminder_time_from_now = compute_seconds_from_now(match_date) + waiting_time_in_seconds | ||
|
||
if reminder_time_from_now > 0: | ||
context.job_queue.run_once(payment_reminder, reminder_time_from_now, context=context, name=str(chat_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from db.queries import update_bot_last_message_id_on_db | ||
|
||
def payment_reminder(context): | ||
job = context.job | ||
chat_id = job.name | ||
|
||
msg = context.bot.send_message(chat_id, text="Ciao bestie 😎, com'è andata la partita? C'è qualcuno che non ha ancora pagato la sua quota?") | ||
|
||
try: | ||
context.bot.pin_chat_message(chat_id=chat_id, message_id=msg.message_id) | ||
except: | ||
print("No admin rights to pin the message") | ||
|
||
update_bot_last_message_id_on_db(chat_id, msg.message_id) |