Chat Command Middleware#

A selection of preimplemented chat command middleware.

Note

See Chat - Introduction to Middleware for a more detailed walkthough on how to use these.

Available Middleware#

Middleware

Description

ChannelRestriction

Filters in which channels a command can be executed in.

UserRestriction

Filters which users can execute a command.

StreamerOnly

Restricts the use of commands to only the streamer in their channel.

ChannelCommandCooldown

Restricts a command to only be executed once every cooldown_seconds in a channel regardless of user.

ChannelUserCommandCooldown

Restricts a command to be only executed once every cooldown_seconds in a channel by a user.

GlobalCommandCooldown

Restricts a command to be only executed once every cooldown_seconds in any channel.

Class Documentation#

class twitchAPI.chat.middleware.BaseCommandMiddleware#

Bases: ABC

The base for chat command middleware, extend from this when implementing your own

execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

abstract async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

abstract async was_executed(command)#

Will be called when a command was executed, use to update internal state

class twitchAPI.chat.middleware.ChannelRestriction#

Bases: BaseCommandMiddleware

Filters in which channels a command can be executed in

__init__(allowed_channel=None, denied_channel=None, execute_blocked_handler=None)#
Parameters:
execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

async was_executed(command)#

Will be called when a command was executed, use to update internal state

class twitchAPI.chat.middleware.UserRestriction#

Bases: BaseCommandMiddleware

Filters which users can execute a command

__init__(allowed_users=None, denied_users=None, execute_blocked_handler=None)#
Parameters:
execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

async was_executed(command)#

Will be called when a command was executed, use to update internal state

class twitchAPI.chat.middleware.StreamerOnly#

Bases: BaseCommandMiddleware

Restricts the use of commands to only the streamer in their channel

__init__(execute_blocked_handler=None)#
Parameters:

execute_blocked_handler (Optional[Callable[[ChatCommand], Awaitable[None]]]) – optional specific handler for when the execution is blocked

execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

async was_executed(command)#

Will be called when a command was executed, use to update internal state

class twitchAPI.chat.middleware.ChannelCommandCooldown#

Bases: BaseCommandMiddleware

Restricts a command to only be executed once every cooldown_seconds in a channel regardless of user.

__init__(cooldown_seconds, execute_blocked_handler=None)#
Parameters:
execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

async was_executed(command)#

Will be called when a command was executed, use to update internal state

class twitchAPI.chat.middleware.ChannelUserCommandCooldown#

Bases: BaseCommandMiddleware

Restricts a command to be only executed once every cooldown_seconds in a channel by a user.

__init__(cooldown_seconds, execute_blocked_handler=None)#
Parameters:
execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

async was_executed(command)#

Will be called when a command was executed, use to update internal state

class twitchAPI.chat.middleware.GlobalCommandCooldown#

Bases: BaseCommandMiddleware

Restricts a command to be only executed once every cooldown_seconds in any channel

__init__(cooldown_seconds, execute_blocked_handler=None)#
Parameters:
execute_blocked_handler: Optional[Callable[[ChatCommand], Awaitable[None]]] = None#

If set, this handler will be called should can_execute() fail.

async can_execute(command)#

return True if the given command should execute, otherwise False

Parameters:

command (ChatCommand) – The command to check if it should be executed

Return type:

bool

async was_executed(command)#

Will be called when a command was executed, use to update internal state