Mts Ipc Modules

mts_ipc.client Module

class mts_ipc.client.Client(host: localhost, secret_key: Union[str, bytes] = 'public-ipc-key', path: str = '/ipc')[source]

Handles webserver side requests to the bot process.

Parameters
  • host (str) – The IP or host of the IPC server, defaults to localhost.

  • path (str) – The path of the IPC server’s IPC connections, defaults to /ipc.

  • secret_key (Union[str, bytes]) – The secret key for your IPC server. Must match the server secret_key or requests will not go ahead, defaults to None

coroutine request(endpoint, **kwargs)[source]

Make a request to the IPC server process.

Parameters
  • endpoint (str) – The endpoint to request on the server

  • **kwargs – The data to send to the endpoint

mts_ipc.server Module

mts_ipc.server.route(name: Optional[str] = None)[source]

Used to register a coroutine as an endpoint when you don’t have access to an instance of Server

Parameters

name (str) – The endpoint name. If not provided the method name will be used.

This can be used in cogs. For ex -

import mts_ipc as ipc
from discord.ext import commands

class IpcCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @ipc.server.route(name = "test")
    async def test(self, data: ipc.server.IpcServerResponse):
        return "Successfully tested the endpoint, which name is " + str(data.endpoint)
class mts_ipc.server.IpcServerResponse(data: dict)[source]

Server response made for handling coroutines reserved for endpoints.

Parameters

data (dict) – The data from which response is to be made.

class mts_ipc.server.Server(bot: Union[discord.client.Client, discord.ext.commands.bot.Bot, discord.ext.commands.bot.AutoShardedBot], secret_key: str = 'public-ipc-key')[source]

The IPC server. Usually used on the bot process for receiving requests from the client.

Parameters
  • bot (Union[Client, Bot, AutoShardedBot]) – Your bot instance

  • secret_key (str) – A secret key. Used for authentication and should be the same as your client’s secret key.

route(name: Optional[str] = None)[source]

Used to register a coroutine as an endpoint when you have access to an instance of Server.

Parameters

name (str) – The endpoint name. If not provided the method name will be used.

update_endpoints()[source]

Called internally to update the server’s endpoints for cog routes.

coroutine handle_accept(request: aiohttp.web_request.Request)[source]

Handles client requests from the client process.

Parameters

request (Request) – The request made by the client, parsed by aiohttp.

start(*args, **kwargs) Tuple[aiohttp.web_app.Application, aiohttp.web_runner.TCPSite][source]

Method to start IPC

Parameters
  • app (Optional[Application]) – An aiohttp application if already made with important things. It is optional creates a new one when None given.

  • path (Optional[str]) – The path where IPC connections are to be made, takes “/ipc” when None given.

  • host (Optional[str]) – The host where the app has to be host for ex ‘0.0.0.0’ for repl, defaults to localhost.

  • port (Optional[int]) – The port where app has to be run, defaults to 8080

Returns

Return type

Tuple[Application, TCPSite]

setup(app: Optional[aiohttp.web_app.Application] = None, path: Optional[str] = '/ipc') aiohttp.web_app.Application[source]

Setups IPC app but doesn’t runs it

Parameters
  • app (Optional[Application]) – An aiohttp application if already made with important things. It is optional creates a new one when None given.

  • path (Optional[str]) – The path where IPC connections are to be made, takes “/ipc” when None given.

Returns

formatted application

Return type

application

mts_ipc.errors Module

class mts_ipc.errors.IpcError[source]

Base error

class mts_ipc.errors.JSONEncodeError[source]

An error raised when JSONDecode problem is there