Sonnet

DB_HLAPI endpoints

Preface

The db_hlapi, or database high level api, is sonnets default interface with a database
It is used in libraries and lower level commands to access configuration data, infractions, and custom tables from guilds
Any endpoints not listed here are not supported, and should not be relied on
Absolutely do not access the .database parameter of db_hlapi, that is the low level connection to a db_handler, and should never be used to maintain portability

Documentation Documentation

The functions below interact primarily with a SQL style database, because of this certain functions inputs can lead to SQL injections (Also known as getting bobby tables'd)
inputs marked green denote safe inputs, while inputs marked red could potentially lead to SQL injection and should only be used with known inputs

Primary functions

Function Description
__init__(guild_id: int) Init connection to hlapi with a guild id parameter
add_config(config: str, value: str) Adds a named config to the configuration pool, functionally this should be treated as a per guild Dict[str, str]
add_infraction(infractionID: str, userID: str, moderatorID: str, Type: str, reason: str, timestamp: int) Add an infraction to infraction db
close() Closes connection to database, called implicitly on __exit__
create_guild_db() Creates tables of the current guild, may be called up to 1 time in other commands if they get an error relating to a lack of database
delete_config(config: str) Deletes the specified config from the config database
delete_guild_db() Deletes the current guilds db tables, to be used for GDPR compliance or wiping a guild for any reason
delete_infraction(infraction_id: str) Deletes the infraction as specified by the id, does not raise an error if it does not exist
download_guild_db() -> Dict[str, List[str, int]] Downloads current guilds database to a hashmap that is json serializable
fetch_all_mutes() -> List[List[Union[str, int]]] Fetches all mutes from all guilds, does not need a guild_id to init
grab_config(config: str) -> Optional[str] grabs a config from the current guilds config table, returns None if none found
grab_filter_infractions(user: int = None, moderator: int = None, itype: str = None automod: bool = True) Grabs infractions that meet the search parameters provided
grab_infraction(infractionID: str) -> Optional[List[Union[str, int]]] Grabs a single infraction by its id
is_muted(userid: Optional[int] = None, infractionid: Optional[str] = None) -> bool Returns if a user or infractionid is currently in the mute database, at least one input must be defined
mute_user(user: int, endtime: int, infractionID: str) Add a user and an accompanying infraction to the mute database
unmute_user(infractionid: Optional[str] = None, userid: Optional[int] = None) Remove a user from the mute database either by infraction id or by user id
upload_guild_db(dbdict: Dict[str, List[List[Any]]]) Upload a guilds db to the database, NOTE THAT THIS IS SQL INJECTION SAFE, BUT IS STILL GIVING FULL ACCESS TO ALL DATA ROWS AT ONCE, AND SHOULD NOT BE HANDED TO END USERS PROGRAMATICALLY

Database Enumeration Functions (hazmat layer)

Function Description
inject_enum(enumname: str, schema: List[Tuple[str, Any]]) Add a custom table schema to the database
grab_enum(name: str, itemname: str) -> Optional[List[Union[int, str]]] Grabs an item from the database table based on primary key
set_enum(name: str, cpush: List[Union[str, int]]) Sets a row in the custom table to the cpush data, schema must match what was defined in inject_enum

Deprecated Functions

Function Description Deprecation reason
add_to_starboard(message_id: int) -> bool Add a message to the starboard database, the bool returned gives a sucess indicator Same can be accomplished by db enumerations, as starboard should have been a more modular addition initially
grab_moderator_infractions(moderatorid: Union[int, str]) -> Tuple[Any, ...] Grabs all moderator infractions Superceeded by grab_filter_infractions that does multiple filters directly in sql, allowing it to be faster in some situations
grab_user_infractions(userid: int) -> Tuple[List[Union[str, int]], ...] Grabs all user infractions Superceeded by grab_filter_infractions that does multiple filters directly in sql, allowing it to be faster in some situations
in_starboard(message_id: int) -> bool Checks if the message id provided is in starboard Same can be accomplished by db enumerations, as starboard should have been a more modular addition initially