Project

General

Profile

[Plugin] C# API to Python wrapper

Added by Per Amundsen 5 months ago

This is just a test to allow using Python to listen/respond to AdiIRC API events.

Uses ironpython to provide .NET python support.

Installing

Download and unpack the attached PyWrapper.zip to the $adiircdir\Plugins folder.
Open Plugins Dialog and load PyWrapper.dll.

Using

Put the python files in the $adiircdir\Plugins\py folder, file extension must end with .py, the plugin monitors and updates the folder in real time.

The plugin will call all python files with the function name matching the API call e.g OnJoin() (Use plugin docs as reference)

To eat the text or eat the entire event, use EatData.EatNone, EatData.EatText, EatData.EatAll as the return value in the function.

Properties for all objects needs more testing.

Feel free to use/edit/distribute the wrapper, it's public domain.

Global Variables

These variables is always available to the script.

plugin - The c# plugin.
myHost - The plugin host API.
myTools - The plugin tools API.
scriptFile - Full path to the python file.

Event Variables

Available variables will be in camelCase version from the docs e.g Server is server, QuitMessage is quitMessage, if unsure just check the PyWrapper source code.

These variables will have a value or NULL depending on the event called.

server - IServer
channel - IChannel
user - IUser
window - object, can be either IServer, IChannel, IUser or ICustomWindow.
quitMessage - string.
partMessage - string.
newNick - string.
mode - string.
message - string.
kickReason - string.
newTopic - string.
notice - string.
data - string.
byUser - string
editbox - IEditbox
bytes - byte[]. (Not tested)
menuItems ToolstripMenuItems[] array. (Not tested)
keyPressEventArgs - KeyPressEventArgs

Examples

# set a global variable
joined = 0

def OnJoin():
    # print a message to the server window.
    myHost.NotifyUser(server, user.Nick + " just joined " + channel.Name)

    # don't do anything to the original message.
    return EatData.EatNone

def OnPart():
    # eat/hide the part message..
    return EatData.EatText

def OnUserJoin():
    # update the global variable.
    global joined
    joined = joined + 1

    # print number of times joined a channel while the script was running.
    myHost.NotifyUser(server, "I have joined a channel " + str(joined) + " times")

def OnLoad():
    # print a message when the script is loaded.
    myHost.NotifyUser(myHost.ActiveWindow, "Loaded script " + scriptFile)

    # add a hook for the command /testpy
    myHost.HookCommand(plugin, "/testpy", "/testpy", "Command for testing HookCommand from Python")

    # add a hook for the command /testeval
    myHost.HookCommand(plugin, "/testeval", "/testeval", "Command for testing msl evaluation from Python")

    # add a hook for the command /listnicks
    myHost.HookCommand(plugin, "/listnicks", "/listnicks", "Command for testing list enumeration")

    # add a hook for the command /testcmd
    myHost.HookCommand(plugin, "/testcmd", "/testcmd", "Command for testing sending commands")

def OnUnLoad():
    # unhook the commands
    myHost.UnHookCommand(plugin, "/testpy")
    myHost.UnHookCommand(plugin, "/testeval")
    myHost.UnHookCommand(plugin, "/listnicks")
    myHost.UnHookCommand(plugin, "/testcmd")

    # print a message when the script is unloaded.
    myHost.NotifyUser(myHost.ActiveWindow, "Unloaded script " + scriptFile)

def OnCommand():
    if command == "/testpy":

        # if the typed command was /testpy, print a message.
        myHost.NotifyUser(window, "You typed /testpy " + args)

    elif command == "/testeval":

        # if the typed command was /testeval, try to evaluate "$me" 
        myHost.NotifyUser(window, "$me evaluates to " + myHost.Evaluate(myHost.ActiveWindow, "$me", ""))

    elif command == "/listnicks":

        # if the typed command was /listnicks, print all nicks in the channel
        for value in window.GetUsers:
            myHost.NotifyUser(myHost.ActiveWindow, value.Nick)

    elif command == "/testcmd":

        # send a "/echo -ag Hello world" command to the active window.
        myHost.SendCommand(myHost.ActiveWindow, "/echo", "-ag Hello World")

Changelog

  • v1.1
    Changed to using the Nuget package.
  • v1.0
    Initial release