Skip to content

Commit

Permalink
feat: added more callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgiolaga committed Nov 3, 2024
1 parent 5ac0bd8 commit b18c284
Show file tree
Hide file tree
Showing 10 changed files with 664 additions and 200 deletions.
6 changes: 3 additions & 3 deletions callbacks/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def echo(update: Update, context: CallbackContext):
answer = "Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)
else:
players, day, time, target, custom_message, pitch, teams, bot_last_message_id = find_all_info_by_chat_id(chat_id)
players, day, time, target, _, pitch, teams, bot_last_message_id = find_all_info_by_chat_id(chat_id)

if new_message == 'aggiungimi':
sender = "@" + get_sender_name(update)
if is_already_present(chat_id, sender):
Expand Down Expand Up @@ -172,8 +173,7 @@ def echo(update: Update, context: CallbackContext):
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)

if show_summary:
players, day, time, target, default_message, pitch, teams, bot_last_message_id = find_all_info_by_chat_id(
chat_id)
players, day, time, target, default_message, pitch, teams, bot_last_message_id = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)
if bot_last_message_id is None:
msg = print_new_summary(current_situation, update, context)
Expand Down
18 changes: 11 additions & 7 deletions callbacks/participants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ def participants(update: Update, context: CallbackContext):
row = find_row_by_chat_id(chat_id)

if row is None:
answer = "Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)
else:
players, day, time, target, default_message, pitch, _, _ = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)
msg = print_new_summary(current_situation, update, context)
update_bot_last_message_id_on_db(chat_id, msg.message_id)
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text="Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
)
return

players, day, time, target, default_message, pitch, _, _ = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)
msg = print_new_summary(current_situation, update, context)
update_bot_last_message_id_on_db(chat_id, msg.message_id)
55 changes: 34 additions & 21 deletions callbacks/set_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,38 @@ def set_day(update: Update, context: CallbackContext):
row = find_row_by_chat_id(chat_id)

if row is None:
answer = "Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text="Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
)
return

if len(context.args) == 0:
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text="Non hai inserito il giorno: scrivi /setday <giorno>"
)
return

day = flatten_args(context.args)
update_day_on_db(chat_id, day)
remove_job_if_exists(str(chat_id), context)
players, day, time, target, _, pitch, _, bot_last_message_id = find_all_info_by_chat_id(chat_id)
trigger_payment_reminder(update, context, day, time)
sender = "@" + get_sender_name(update)
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text=escape_markdown(f"Ok, {sender}! Ho impostato il giorno della partita il {day}")
)

players, day, time, target, default_message, pitch, _, bot_last_message_id = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)

if bot_last_message_id is None:
msg = print_new_summary(current_situation, update, context)
update_bot_last_message_id_on_db(chat_id, msg.message_id)
else:
if len(context.args) == 0:
answer = "Non hai inserito il giorno: scrivi /setday <giorno>"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)
else:
day = flatten_args(context.args)
update_day_on_db(chat_id, day)
remove_job_if_exists(str(chat_id), context)
players, day, time, target, _, pitch, _, bot_last_message_id = find_all_info_by_chat_id(chat_id)
trigger_payment_reminder(update, context, day, time)
sender = "@" + get_sender_name(update)
answer = "Ok, " + sender + "! Ho impostato il giorno della partita il " + day
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=escape_markdown(answer))
players, day, time, target, default_message, pitch, _, bot_last_message_id = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)
if bot_last_message_id is None:
msg = print_new_summary(current_situation, update, context)
update_bot_last_message_id_on_db(chat_id, msg.message_id)
else:
edit_summary(current_situation, bot_last_message_id, update, context)
edit_summary(current_situation, bot_last_message_id, update, context)
49 changes: 31 additions & 18 deletions callbacks/set_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@ def set_description(update: Update, context: CallbackContext):
row = find_row_by_chat_id(chat_id)

if row is None:
answer = "Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text="Prima di iniziare con le danze, avvia una partita, per farlo usa /start"
)
return

if len(context.args) == 0:
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text="Non hai inserito la descrizione: scrivi /setdescription <descrizione>"
)
return

description = flatten_args(context.args) + "\n"
update_description_on_db(chat_id, description)
sender = "@" + get_sender_name(update)
context.bot.send_message(
chat_id=update.effective_chat.id,
parse_mode='markdown',
text=escape_markdown(f"Ok, {sender}! Ho aggiornato la descrizione!")
)

players, day, time, target, default_message, pitch, _, bot_last_message_id = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)

if bot_last_message_id is None:
msg = print_new_summary(current_situation, update, context)
update_bot_last_message_id_on_db(chat_id, msg.message_id)
else:
if len(context.args) == 0:
answer = "Non hai inserito la descrizione: scrivi /setdescription <descrizione>"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=answer)
else:
description = flatten_args(context.args) + "\n"
update_description_on_db(chat_id, description)
sender = "@" + get_sender_name(update)
answer = "Ok, " + sender + "! Ho aggiornato la descrizione!"
context.bot.send_message(chat_id=update.effective_chat.id, parse_mode='markdown', text=escape_markdown(answer))
players, day, time, target, default_message, pitch, _, bot_last_message_id = find_all_info_by_chat_id(chat_id)
current_situation = format_summary(players, day, time, target, default_message, pitch)
if bot_last_message_id is None:
msg = print_new_summary(current_situation, update, context)
update_bot_last_message_id_on_db(chat_id, msg.message_id)
else:
edit_summary(current_situation, bot_last_message_id, update, context)
edit_summary(current_situation, bot_last_message_id, update, context)
151 changes: 0 additions & 151 deletions test/test_callbacks.py

This file was deleted.

Loading

0 comments on commit b18c284

Please sign in to comment.