Skip to content

Utils

General helper functions used by bot commands

Generic utility functions for Compass Bot

URL

Bases: str

URL substring checking class

If URL contains "substring", equality returns True. For example: URL("https://www.youtube.com/watch?v=1234567890") == "youtube" => True

ddict

Bases: dict

dot.notation access to dictionary attributes

check_time_format

Check that datetime input is in format YYYY-MM-DD HH:MM AM/PM TZ

chunk_list

Yield successive n-sized chunks from list l

Parameters:

Name Type Description Default
list_to_chunk list

List to chunk into sublists

required
chunk_size int

Size of sublists to subdivide list into

required

Yields:

Name Type Description
list list

n-sized sublists of list l

download async

Download an attachment from a message

Parameters:

Name Type Description Default
itx Message

Message context

required
attachment Attachment

Attachment to download

required
path Optional[Union[str, PathLike]]

Path to save attachment to

required

dt_to_epoch

Convert datetime to epoch time (requires format: YYYY-MM-DD HH:MM AM/PM TZ)

epoch_to_dt

Convert epoch time to datetime

extract_url

Extracts URL from message content, or returns as is

get_resource_path

Returns path to resource

Parameters:

Name Type Description Default
guild_name str

Name of guild

required
resource str

Resource path (can be nested, e.g. "emojis/png")

()

get_resource_repo

Clone or pull resource repo

getfilepath

Returns filepath with guild-specific download prefix

Parameters:

Name Type Description Default
itx Message

Message context

required
fp str

File path

required

parse_args

Parse arguments from a string into a dictionary