core.utils

Module Contents

Classes

Text

Text manipulation functions

Time

Time manipulation functions

Guilded

Helper functions for (mostly) guilded API actions.

Attributes

tr

config

core.utils.tr
core.utils.config
class core.utils.Text

Text manipulation functions

static sanitise(string: str, *, limit: int = 2000, escape: bool = True) str

Sanitise string.

Parameters
  • string – A text string to sanitise.

  • limit – How many characters should be processed.

  • escape – Whether to escape characters (to prevent unwanted markdown).

Returns

Sanitised string.

static split(string: str, limit: int = 1990) List[str]

Split text into multiple smaller ones.

Parameters
  • string – A text string to split.

  • limit – How long the output strings should be.

Returns

A string split into a list of smaller lines with maximal length of limit.

static split_lines(lines: List[str], limit: int = 1990) List[str]

Split list of lines to bigger blocks.

Parameters
  • lines – List of lines to split.

  • limit – How long the output strings should be.

Returns

A list of strings constructed from lines.

This works just as split() does; the only difference is that this guarantees that the line won’t be split at half, instead of calling the split() on lines joined with newline character.

static parse_bool(string: str) Optional[bool]

Parse string into a boolean.

Parameters

string – Text to be parsed.

Returns

Boolean result of the conversion.

Pass strings 1, true, yes for True.

Pass strings 0, false, no for False.

Other keywords return None.

class core.utils.Time

Time manipulation functions

static id_to_datetime(snowflake_id: int) datetime.datetime

Convert snowflake ID to timestamp.

static date(timestamp: datetime.datetime) str

Convert timestamp to date.

static datetime(timestamp: datetime.datetime) str

Convert timestamp to date and time.

static seconds(time: int) str

Convert seconds to human-readable time.

class core.utils.Guilded

Helper functions for (mostly) guilded API actions.

async static get_message(bot: guilded.ext.commands.Bot, guild_id: int, channel_id: int, message_id: int) Optional[guilded.Message]

Get message.

If the message is contained in bot cache, it is returned from it, to save API calls. Otherwise it is fetched.

Parameters
  • bot – The Bot object.

  • guild_id – Guild ID.

  • channel_id – Channel ID.

  • message_id – Message ID.

Returns

Found message or None.

static create_embed(error: bool = False, author: Union[guilded.Member, guilded.User] = None, **kwargs) guilded.Embed

Create guilded embed.

Parameters
  • error – Whether the embed reports an error.

  • author – Event author.

  • kwargs – Additional parameters.

Returns

The created embed.

If you supply title, description, color or footer, they will be included in the embed.

async static send_help(ctx: guilded.ext.commands.Context) bool

Send help if no subcommand has been invoked.

Parameters

ctx – The command context.

Returns

True if the help was sent, False otherwise.

async static delete_message(message: guilded.Message, delay: float = 0.0) bool

Try to remove message.

Parameters
  • message – The message to be deleted.

  • delay – How long to wait, in seconds.

Returns

True if the action was successful, False otherwise.

async static remove_reaction(message: guilded.Message, emoji, member: guilded.Member) bool

Try to remove reaction.

Parameters
  • message – The message of the reaction.

  • emoji – Emoji, Reaction, PartialEmoji or string.

  • member – The author of the reaction.

Returns

True if the action was successful, False otherwise.

async static update_presence(bot: guilded.ext.commands.Bot, *, status: str = None) None

Update the bot presence.

The Activity is always set to <prefix>help. The Status is loaded from the database, unless it is specified as parameter.

Parameters

status – Overwrite presence status.