[Plugin] C# API to Ruby wrapper
Added by Per Amundsen over 3 years ago
This is just a test to allow using Ruby to listen/respond to AdiIRC API events.
Uses ironruby to provide .NET ruby support.
Installing
Download and unpack the attached RubyWrapper.zip to the $adiircdir\Plugins folder.
Open Plugins Dialog and load RubyWrapper.dll.
Using
Put the ruby files in the $adiircdir\Plugins\rb folder, file extension must end with .rb, the plugin monitors and updates the folder in real time.
The plugin will call all ruby 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 ruby 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 RubyWrapper 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 end def OnPart() # eat/hide the part message.. return eatData.EatText end def OnUserJoin() # update the global variable. $joined = $joined + 1 # print number of times joined a channel while the script was running. myHost.NotifyUser(server, "I have joined a channel " + $joined.to_s + " times") end def OnLoad() # print a message when the script is loaded. myHost.NotifyUser(myHost.ActiveWindow, "Loaded script " + scriptFile) # add a hook for the command /testruby myHost.HookCommand(plugin, "/testruby", "/testruby", "Command for testing HookCommand from Ruby") # add a hook for the command /testeval myHost.HookCommand(plugin, "/testeval", "/testeval", "Command for testing msl evaluation from Ruby") # 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") end def OnUnLoad() # unhook the commands myHost.UnHookCommand(plugin, "/testruby") 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) end def OnCommand() if command == "/testruby" # if the typed command was /testruby, print a message. myHost.NotifyUser(window, "You typed /testruby " + args) elsif command == "/testeval" # if the typed command was /testeval, try to evaluate "$me" myHost.NotifyUser(window, "$me evaluates to " + myHost.Evaluate(myHost.ActiveWindow, "$me", "")) elsif 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) end elsif command == "/testcmd" # send a "/echo -ag Hello world" command to the active window. myHost.SendCommand(myHost.ActiveWindow, "/echo", "-ag Hello World") end end
TODO
Figure out how to access and compare MenuType/WindowType enums from AdiIRCAPI (WindowTypeNum can be used for now).
Changelog
- v1.0
Initial release
RubyWrapper.zip (1.12 MB) RubyWrapper.zip | |||
RubyWrapper_source.zip (2.47 MB) RubyWrapper_source.zip |