Commands package
Description
All the commands the bot will react to
aulario
Aulario command
- module.commands.aulario.aulario(update, context, chat_id=None, message_id=None)
Called by the /aulario command. Shows the calendar to the user to allow him to select a day from the calendar
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat. Defaults to None.message_id (
int) – id of the message. Defaults to None.
- Return type:
None
- module.commands.aulario.calendar_handler(update, context)
Called by clicking on a day on the calendar of the /aulario command. Show the list of subject for the day
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.aulario.create_calendar(last_day, year=None, month=None)
Called by
aulario()andmonth_handler(). Creates an InlineKeyboard to append to the message- Parameters:
last_day (
date) – last selectable dayyear (
int) – yeat. Defaults to None.month (
int) – month. Defaults to None.
- Return type:
InlineKeyboardMarkup- Returns:
calendar
- module.commands.aulario.create_map(sub, h, room)
Called by
subjects_handler(). Creates an image to show where the lesson will take place. Returns None if the hall is not in the base image- Parameters:
sub (
str) – name of the subjecth (
str) – timeroom (
str) – hall
- Return type:
BytesIO|None- Returns:
photo to send
- module.commands.aulario.get_subjs_keyboard(page, day)
Called by
calendar_handler()subjects_arrow_handler(). Generates the keyboard that lists all the subjects for the selected date- Parameters:
page (
int) – page of the subject selectorday (
str) – day, in ISO format (YYYY-MM-DD)
- Return type:
list- Returns:
InlineKeyboard
- module.commands.aulario.month_handler(update, context)
Called when navigating the calendar of the /aulario command. Updates the calendar
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.aulario.subjects_arrow_handler(update, context)
Called when navigating the /aulario menu with the arrows. Shows the next or previous page
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.aulario.subjects_handler(update, context)
Called when clicking on a subject of the /aulario command. Shows more information on the subject selected
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
esami
/esami command
- module.commands.esami.esami(update, context)
Called by the /esami command. Shows the options available to execute an exam query.
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.esami.esami_button_anno(update, context, chat_id, message_id)
Called by one of the buttons of the /esami command. Allows the user to choose an year among the ones proposed
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat of the usermessage_id (
int) – id of the sub-menu message
- Return type:
None
- module.commands.esami.esami_button_insegnamento(update, context, chat_id, message_id)
Called by one of the buttons of the /esami command. Allows the user to write the subject they want to search for
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat of the usermessage_id (
int) – id of the sub-menu message
- Return type:
None
- module.commands.esami.esami_button_sessione(update, context, chat_id, message_id)
Called by one of the buttons of the /esami command. Allows the user to choose a session among the ones proposed
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat of the usermessage_id (
int) – id of the sub-menu message
- Return type:
None
- module.commands.esami.esami_handler(update, context)
Called by any of the buttons in the /esami command sub-menus. The action will change depending on the button:
anno -> adds / removes the selected year from the query parameters
sessione -> adds / removes the selected session from the query parameters
search -> executes the query with all the selected parametes and shows the result
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.esami.esami_input_insegnamento(update, context)
Called after
esami_button_insegnamento(). Allows the user to input the wanted subject, in the format [Ii]ns: <insegnamento>- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.esami.generate_esami_text(locale, user_dict)
Called by
esami()after the search button in the /esami command has been pressed. Executes the query and returns the text to send to the user- Parameters:
locale (
str) – user’s languageuser_dict (
dict) – dictionary that stores the user selected parameters to use in the query
- Return type:
str- Returns:
result of the query to send to the user
- module.commands.esami.get_esami_text_inline_keyboard(locale, context)
Generates the text and the InlineKeyboard for the /esami command, based on the current parameters.
- Parameters:
locale (
str) – user’s languagecontext (
CallbackContext) – context passed by the handler
- Return type:
tuple[str,InlineKeyboardMarkup]- Returns:
message_text and InlineKeyboardMarkup to use
gdrive
/drive command
- module.commands.gdrive.drive(update, context)
Called by the /drive command. Lets the user navigate the drive folders, if he has the permissions
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.gdrive.drive_handler(update, context)
Called by any of the buttons of the /drive command. Allows the user to navigate in the google drive and download files
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.gdrive.get_files_keyboard(file_list, row_len=2)
Called by
drive()anddrive_handler(). Generates the InlineKeyboard that allows the user to navigate among the files in the list- Parameters:
file_list (
list) – list of filesrow_len (
int) – lenght of the row. Defaults to 2
- Return type:
list- Returns:
InlineKeyboard
help
/help command
Called by a sm_help_back_to_menu button from the sub menu. Allows the user to return back to the command list
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id – id of the chat the command was invoked from
message_id – id of the help message
- Return type:
None
- module.commands.help.help_cmd(update, context, edit=False)
Called by the /help command. Shows all the actions supported by the bot
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handleredit (
bool) – bool flag that affects how the message should be handled
- Return type:
None
- module.commands.help.help_dip_cdl(update, context, chat_id, message_id)
Called by the sm_help_dip_cdl button from the /help command. Lists to the user the commands related to the department or the CDL
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat the command was invoked frommessage_id (
int) – id of the help message
- Return type:
None
- module.commands.help.help_ersu(update, context, chat_id, message_id)
Called by the sm_help_ersu button from the /help command. Lists to the user the commands related to the ERSU
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat the command was invoked frommessage_id (
int) – id of the help message
- Return type:
None
- module.commands.help.help_misc(update, context, chat_id, message_id)
Called by the sm_help_misc button from the /help command. Lists to the user the commands related to the miscellaneous stuff
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat the command was invoked frommessage_id (
int) – id of the help message
- Return type:
None
- module.commands.help.help_projects_acknowledgements(update, context, chat_id, message_id)
Called by the sm_help_projects_acknowledgements button from the /help command. Lists to the user the commands related to the other’s project and acknowledgements
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat the command was invoked frommessage_id (
int) – id of the help message
- Return type:
None
Called by the sm_help_rapp_menu button from the /help command. Allows the user to select the department
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat the command was invoked frommessage_id (
int) – id of the help message
- Return type:
None
- module.commands.help.help_segr(update, context, chat_id, message_id)
Called by the sm_help_segr button from the /help command. Lists to the user the commands related to the secretariats’ office hours
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerchat_id (
int) – id of the chat the command was invoked frommessage_id (
int) – id of the help message
- Return type:
None
lezioni
/lezioni command
- module.commands.lezioni.find_timetable_pdfs(page, page_url)
Finds the timetable PDFs of a course page. PDFs embedded in a viewer come first, as the attached ones may be from past semesters (e.g. LM-40).
- Parameters:
page (
BeautifulSoup) – content of the course pagepage_url (
str) – url of the course page
- Return type:
List[str]- Returns:
urls of the PDFs
- module.commands.lezioni.get_course_page(url)
Downloads the main content of a course page
- Parameters:
url (
str) – url of the page- Return type:
BeautifulSoup|None- Returns:
content of the page, or None if it could not be downloaded
- module.commands.lezioni.get_course_urls()
Reads the timetable page of each course from the lezioni_link markdown file
- Return type:
Dict[str,str]- Returns:
course code (e.g. L-31) -> url of its timetable page
- module.commands.lezioni.get_courses_keyboard()
Generates the keyboard to choose the course of the /lezioni command
- Return type:
InlineKeyboardMarkup- Returns:
InlineKeyboard
- module.commands.lezioni.lezioni(update, context)
Called by the /lezioni command. Shows the courses to the user, to choose the one whose timetable to see
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.lezioni.lezioni_course_handler(update, context)
Called by clicking on a course of the /lezioni command. Shows its curricula if the course page has a timetable, otherwise sends its PDFs
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.lezioni.lezioni_courses_handler(update, _)
Called by the back button of the /lezioni curricula. Shows the courses again
- Parameters:
update (
Update) – update eventcontext – context passed by the handler
- Return type:
None
- module.commands.lezioni.lezioni_curriculum_handler(update, _)
Called by clicking on a curriculum of the /lezioni command. Shows its timetable
- Parameters:
update (
Update) – update eventcontext – context passed by the handler
- Return type:
None
- module.commands.lezioni.parse_timetable(page)
Parses the timetable tables of a course page, as published by LM-18. Each table starts with a single-cell header like “CURRICULUM HEALTH INFORMATICS - Primo Anno”, followed by rows of subject, days, time and room; a row without subject continues the one above.
- Parameters:
page (
BeautifulSoup) – content of the course page- Return type:
Dict[str,str]- Returns:
curriculum -> its timetable, formatted as Telegram HTML
professori
/prof command
- module.commands.professori.generate_prof_text(locale, names)
Called from the
prof()method. Executes the query and returns the text to send to the user- Parameters:
locale (
str) – user’s languagenames (
list) – list of args passed to the context
- Return type:
str- Returns:
result of the query to send to the user
- module.commands.professori.prof(update, context)
Called by the /prof command. Use: /prof <nomeprofessore> … Shows all the professors that match the request
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
regolamento_didattico
/regolamentodidattico command
- module.commands.regolamento_didattico.cdl_handler(update, context)
- Return type:
None
- module.commands.regolamento_didattico.get_cdl_keyboard(locale, reg_doc=None)
Called by
regolamentodidattico()andregolamentodidattico_handler(). Generates the whole list of rulebooks to append as an InlineKeyboard- Parameters:
locale (
str) – the user languagereg_doc (
dict) – rulebooks to show
- Return type:
InlineKeyboardMarkup- Returns:
list of rulebooks
- module.commands.regolamento_didattico.get_inf_keyboard(locale)
- Return type:
InlineKeyboardMarkup
- module.commands.regolamento_didattico.get_mat_keyboard(locale)
- Return type:
InlineKeyboardMarkup
- module.commands.regolamento_didattico.regolamentodidattico(update, _)
Called by the /regolamentodidattico command. Shows a menu from with the user can choose between (triennale | magistrale)
- Parameters:
update (
Update) – update eventcontext – context passed by the handler
- Return type:
None
- module.commands.regolamento_didattico.regolamentodidattico_handler(update, context)
Called by any of the /regolamentodidattico buttons. Data can be ( home | triennale | magistrale ). Allows the used to navigate between the rulebooks
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.regolamento_didattico.send_regolamento(update, context)
Called by clicking on a rulebook. Sends said rulebook to the user.
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
report
/report command
- module.commands.report.report(update, context)
Called by the /report command. Use: /report <word> … Allows the user to report something to the administrators
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
start
/start command
- module.commands.start.get_help_keyboard(locale)
Generates the reply keyboard shown at the bottom of the screen
- Return type:
ReplyKeyboardMarkup- Returns:
reply keyboard
- module.commands.start.start(update, context)
Called by the /start command. Sends a welcome message
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
stats
/stats command
- module.commands.stats.send_graph(rows, bot, chat_id)
Called by
stats_gen(). Generates a graph and sends it to the user- Parameters:
rows (
list) – hystory of commandsbot (
Bot) – telegram botchat_id (
int) – id of the chat
- Return type:
None
- module.commands.stats.stats(update, context)
Called by the /stats command. Use: /stats [days] Shows the history of all the commands requested to the bot in the last ‘days’. Defaults to 30.
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None
- module.commands.stats.stats_gen(update, context, days=0)
Called by
stats()orstats_tot(). Generates the requested stats, both with text and graph- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handlerdays (
int) – number of days to consider. Defaults to 0.
- Return type:
None
- module.commands.stats.stats_tot(update, context)
Called by the /stats_tot command. Shows the history of all the commands requested to the bot
- Parameters:
update (
Update) – update eventcontext (
CallbackContext) – context passed by the handler
- Return type:
None