Matrigram code

Bot

class matrigram.bot.MatrigramBot(*args, **kwargs)[source]
_get_chat_id(client)[source]

Get telegram id associated with client.

Parameters:client (MatrigramClient) – The client to be queried.
Returns:The chat_id associated to the client.
Return type:str
_get_client(chat_id)[source]

Get matrigram client.

Parameters:chat_id – Telegram user id.
Returns:The client associated to the telegram user with chat_id.
Return type:MatrigramClient
login(msg, match)[source]

Perform login.

Parameters:
  • msg – The message object received from telegram user.
  • match – Match object containing extracted data.
on_callback_query(msg)[source]

Handle callback queries.

Route queries using self.callback_query_routes.

Parameters:msg – The message object received from telegram user.
on_chat_message(msg)[source]

Main entry point.

This function is our main entry point to the bot. Messages will be routed according to their content type.

Parameters:msg – The message object received from telegram user.
on_text_message(msg)[source]

Handle text messages.

Route text messages using self.routes.

Parameters:msg – The message object received from telegram user.
send_message(sender, msg, client)[source]

Send message to telegram user.

Parameters:
  • sender (str) – Name of the sender.
  • msg (str) – Text message.
  • client (MatrigramClient) – The client the message is originated in.

Returns:

Client

class matrigram.client.MatrigramClient(server, tb, username)[source]
_get_rooms_updated()[source]

Return rooms dictionary with updated aliases.

Returns (dict): Return rooms dictionary with updated aliases.

_room_alias_to_id(alias)[source]

Convert room alias to id.

Parameters:alias (str) – Room alias.

Returns (str): Room id.

_room_id_to_alias(id)[source]

Convert room id to alias.

Parameters:id (str) – Room id.

Returns (str): Room alias.

get_room_obj(room_id_or_alias)[source]

Get room object of specific id or alias.

Parameters:room_id_or_alias (str) – Room’s id or alias.

Returns (Room): Room object corresponding to room_id_or_alias.

Helper

matrigram.helper.chunks(l, n)[source]

Yield successive n-sized chunks from l.

Parameters:
  • l (list) – List to be split.
  • n (int) – Size of chunk.
matrigram.helper.config_filled()[source]

Check if the user filled the config file.

Returns:True if config is filled, else False.
Return type:bool
matrigram.helper.download_file(url, path)[source]

Download a file from the net.

Parameters:
  • url (str) – Link to the file.
  • path (str) – Where to save.
matrigram.helper.get_config()[source]

Query config file.

Returns:The config dictionary.
Return type:dict
matrigram.helper.init_config()[source]

Init ~/.matrigramconfig.

matrigram.helper.list_to_nice_lines(l)[source]

Convert a string list to lines ready to printed.

Parameters:l (list) – List of strings to be printed
Returns:A line separated string that can be printed.
Return type:str
matrigram.helper.list_to_nice_str(l)[source]

Convert a string list to a ready to print string.

Parameters:l (list) – List of strings to be printed
Returns:A string that can be printed.
Return type:str
matrigram.helper.pprint_json(to_print)[source]

Pretty print json.

Parameters:to_print (json) – The json to be printed.
Returns:Pretty printed json string.
Return type:str