Pincer Utils Module#

Api Object#

APIObject#

class APIObject#

Bases: object

Represents an object which has been fetched from the Discord API.

classmethod bind_client(client)#

Links the object to the client.

Parameters

client (Client) – The client to link to.

classmethod from_dict(data)#

Parse an API object from a dictionary.

to_dict()#

Transform the current object to a dictionary representation. Parameters that start with an underscore are not serialized.

APIObject Properties#

class ChannelProperty#

Bases: object

property channel#

Return a channel from an APIObject :param obj: :type obj: APIObject

Return type

Channel

class GuildProperty#

Bases: object

property guild#

Return a guild from an APIObject :param self: :type self: APIObject

Return type

Guild

Directory#

chdir#

with chdir(path)#

Change the cwd to the given path as a context manager.

Parameters

path – Path to change to.

Yields

Generator[str, Any, None]

Signature#

get_signature_and_params#

get_signature_and_params(func)#

Get the parameters and signature from a coroutine.

func: Callable

The coroutine from whom the information should be extracted.

Returns

Signature and list of parameters of the coroutine.

Return type

Tuple[List[Union[str, inspect.Parameter]]]

get_params#

get_params(func)#

Get the parameters from a coroutine.

func: Callable

The coroutine from whom the information should be extracted.

Returns

List of parameters of the coroutine.

Return type

List[Union[str, inspect.Parameter]]

Snowflake#

Snowflake#

class Snowflake#

Bases: int

Discord utilizes Twitter’s snowflake format for uniquely identifiable descriptors (IDs).

These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent’s ID.

Because Snowflake IDs are up to 64 bits in size (e.g. an uint64), they are always returned as strings in the HTTP API to prevent integer overflows in some languages.

classmethod from_string(string)#

Initialize a new Snowflake from a string.

Parameters

string (str) – The snowflake as a string.

property increment#

For every ID that is generated on that process, this number is incremented.

Type

int

property process_id#

Internal process ID

Type

int

property timestamp#

Milliseconds since Discord Epoch, the first second of 2015 or 14200704000000

Type

int

property worker_id#

Internal worker ID

Type

int

Tasks#

Task#

Methods
class Task#

Bases: object

A Task is a coroutine that is scheduled to repeat every x seconds. Use a TaskScheduler in order to create a task. :param scheduler: The scheduler to use. :type scheduler: TaskScheduler :param coro: The coroutine to register as a task. :type coro: Coro :param delay: Delay between each iteration of the task. :type delay: float

cancel()#

Cancel the task.

property cancelled#

Check if the task has been cancelled or not.

Type

bool

property client_required#
property running#

Check if the task is running.

Type

bool

start()#

Register the task in the TaskScheduler and start the execution of the task.

TaskScheduler#

Methods
class TaskScheduler#

Bases: object

@loop(days=0, weeks=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0)#

A decorator to create a task that repeat the given amount of t :Example usage:

from pincer import Client
from pincer.utils import TaskScheduler

client = Client("token")
task = TaskScheduler(client)

@task.loop(minutes=3)
async def my_task(self):
    ...

my_task.start()
client.run()
Parameters
  • days (int) – Days to wait between iterations.

    Default: 0

  • weeks (int) – Days to wait between iterations.

    Default: 0

  • hours (int) – Days to wait between iterations.

    Default: 0

  • minutes (int) – Days to wait between iterations.

    Default: 0

  • seconds (int) – Days to wait between iterations.

    Default: 0

  • milliseconds (int) – Days to wait between iterations.

    Default: 0

  • microseconds (int) – Days to wait between iterations.

    Default: 0

Raises
  • TaskIsNotCoroutine: – The task is not a coroutine.

  • TaskInvalidDelay: – The delay is 0 or negative.

close()#

Gracefully stops any running task.

register(task)#

Register a task. :param task: The task to register. :type task: Task

Timestamp#

Timestamp#

Attributes
class Timestamp#

Bases: object

Contains a lot of useful methods for working with timestamps.

date#

The time of the timestamp.

Type

str

time#

Alias for date.

Type

str

Parameters

time (Union[str, int, float, datetime.datetime]) –

staticmethod epoch_to_datetime(epoch)#

Convert an epoch to a datetime object.

epoch: Union[int, float]

The epoch to convert to a datetime object.

Returns

The converted datetime object.

Return type

datetime.datetime

staticmethod parse(time=None)#

Convert a time to datetime object.

time: Optional[Union[str, int, float, datetime.datetime]]

The time to be converted to a datetime object. This can be one of these types: datetime, float, int, str

If no parameter is passed it will return the current datetime.

Returns

The converted datetime object.

Return type

datetime.datetime

staticmethod string_to_datetime(string)#

Convert a string to a datetime object.

string: str

The string to convert.

Returns

The converted datetime object.

Return type

datetime.datetime

staticmethod to_epoch(time)#

Convert a datetime to an epoch.

time: datetime.datetime

The datetime to convert.

Returns

The epoch time integer.

Return type

int

Types#

MissingType#

class MissingType#

Bases: object

Type class for missing attributes and parameters.

MISSING#

MISSING: MissingType#

APINullable#

APINullable: Union[T, MissingType]#

Represents a value which is optionally returned from the API

Coro#

Coro: TypeVar("Coro", bound=Callable[..., Coroutine[Any, Any, Any]])#

Represents a coroutine.

choice_value_types#

choice_value_types: Tuple[str, int, float]#