BotRPC — JSON RPC Controller

PyIRCBot has a json rpc interface for controlling some aspects of the bot remotely via JSON-RPC.

It’s important to know the different states a module can be in.

  • Deported - Module’s code exists on disk but has not been read
  • Imported - Module’s code exists in memory but has not been instantiated
  • Loaded - Module’s code exists in memory and has been instantiated. “Running” modules are of this state.
class pyircbot.rpc.BotRPC(main)[source]

Bases: threading.Thread

Parameters:main (PyIRCBot) – A reference to the PyIRCBot instance this instance will control
deportModule(moduleName)[source]

Remove a module’s code from memory. If the module is loaded it will be unloaded silently.

Parameters:moduleName (str) – Name of the module to import
eval(code)[source]

Execute arbitrary python code on the bot

Parameters:code (str) – Python code to pass to eval
exec(code)[source]

Execute arbitrary python code on the bot

Parameters:code (str) – Python code to pass to exec
getLoadedModules()[source]

Return a list of active modules

Returns:list – [‘ModuleName1’, ‘ModuleName2’]
getPluginVar(moduleName, moduleVarName)[source]

Extract a property from an active module and return it

Parameters:
  • moduleName (str) – Name of the target module
  • moduleVarName (str) – Name of the target property
Returns:

mixed – Any basic type extracted from an active module

importModule(moduleName)[source]

Import a module

Parameters:moduleName (str) – Name of the module to import
loadModule(moduleName)[source]

Activate a module.

Parameters:moduleName (str) – Name of the module to activate
pluginCommand(moduleName, methodName, argList)[source]

Run a method of an active module

Parameters:
  • moduleName (str) – Name of the target module
  • methodName (str) – Name of the target method
  • argList (list) – List of positional arguments to call the method with
Returns:

mixed – Any basic type the target method may return

quit(message)[source]

Tell the bot to quit IRC and exit

Parameters:message – Quit message
redoModule(moduleName)[source]

Reload a running module from disk

Parameters:moduleName (str) – Name of the target module
reloadModule(moduleName)[source]

Deactivate and activate a module.

Parameters:moduleName (str) – Name of the target module
run()[source]

Internal, starts the RPC server

setPluginVar(moduleName, moduleVarName, value)[source]

Set a property of an active module

Parameters:
  • moduleName (str) – Name of the target module
  • moduleVarName (str) – Name of the target property
  • value (str) – Value the target property will be set to
unloadModule(moduleName)[source]

Deactivate a module.

Parameters:moduleName (str) – Name of the module to deactivate