evennia.server.portal.discord¶
Implements Discord chat channel integration.
The Discord API uses a mix of websockets and REST API endpoints.
In order for this integration to work, you need to have your own discord bot set up via https://discord.com/developers/applications with the MESSAGE CONTENT toggle switched on, and your bot token added to server/conf/secret_settings.py as your DISCORD_BOT_TOKEN
- evennia.server.portal.discord.random() x in the interval [0, 1).¶
- class evennia.server.portal.discord.QuietConnectionPool(reactor, persistent=True)[source]¶
Bases:
HTTPConnectionPoolA quiet version of the HTTPConnectionPool which sets the factory’s noisy property to False to muffle log output.
- evennia.server.portal.discord.should_retry(status_code)[source]¶
Helper function to check if the request should be retried later.
- Parameters:
status_code (int)
- Returns:
retry (bool) - True if request should be retried False otherwise
- class evennia.server.portal.discord.DiscordWebsocketServerFactory(sessionhandler, *args, **kwargs)[source]¶
Bases:
WebSocketClientFactory,ReconnectingClientFactoryA customized websocket client factory that navigates the Discord gateway process.
- initialDelay = 1¶
- factor = 1.5¶
- maxDelay = 60¶
- noisy = False¶
- gateway = None¶
- resume_url = None¶
- is_connecting = False¶
- __init__(sessionhandler, *args, **kwargs)[source]¶
Note
In addition to all arguments to the constructor of :func:autobahn.websocket.interfaces.IWebSocketClientChannelFactory, you can supply a **reactor** keyword argument to specify the Twisted reactor to be used.
- buildProtocol(addr)[source]¶
Build new instance of protocol
- Parameters:
addr (str) – Not used, using factory/settings data
- startedConnecting(connector)[source]¶
Tracks reconnections for debugging.
- Parameters:
connector (Connector) – Represents the connection.
- class evennia.server.portal.discord.DiscordClient[source]¶
Bases:
WebSocketClientProtocol,SessionImplements the Discord client
- nextHeartbeatCall = None¶
- pending_heartbeat = False¶
- heartbeat_interval = None¶
- last_sequence = 0¶
- session_id = None¶
- discord_id = None¶
- onMessage(payload, isBinary)[source]¶
Callback fired when a complete WebSocket message was received.
- Parameters:
payload (bytes) – The WebSocket message received.
isBinary (bool) – Flag indicating whether payload is binary or UTF-8 encoded text.
- onClose(wasClean, code=None, reason=None)[source]¶
This is executed when the connection is lost for whatever reason. it can also be called directly, from the disconnect method.
- Parameters:
wasClean (bool) – **True** if the WebSocket was closed cleanly.
code (int or None) – Close status as sent by the WebSocket peer.
reason (str or None) – Close reason as sent by the WebSocket peer.
- post_response(body, **kwargs)[source]¶
Process the response from sending a POST request
- Parameters:
body (bytes)
- disconnect(reason=None)[source]¶
Generic hook for the engine to call in order to disconnect this protocol.
- Parameters:
reason (str or None) – Motivation for the disconnection.
- identify(*args, **kwargs)[source]¶
Send Discord authentication. This should be sent once heartbeats begin.
- send_channel(text, channel_id, **kwargs)[source]¶
Send a message from an Evennia channel to a Discord channel.
Use with session.msg(channel=(message, channel, sender))