realJoshByrnes / js4irc

V8 Javascript engine plugin for AdiIRC
GNU Affero General Public License v3.0
0 stars 0 forks source link

Web API objects not implemented #1

Open realJoshByrnes opened 2 years ago

realJoshByrnes commented 2 years ago

We have full access to the Javascript API, but there are objects in the Web API that could be useful.

eg. Timers

Here's a very rough implementation of setTimeout and clearTimeout using AdiIRC's timers. Unfortunately, as /timer evaluates the text, we would never get the original back. It's possible to counteract this by encapsulating text.

eg. Instead of "Hi", we could send "$+($chr(72),$chr(105))" to mIRC to have the data not messed up. AFAIK AdiIRC does not have line limits as mIRC does (need to check).

private Func<ScriptObject, int, int> setTimeout;
private Action<int> clearTimeout;

setTimeout = (func, delay) =>
{
    executeCommand($".timer -m 1 {delay} noop $js.execScript({func})");
    return int.Parse(evaluate("$timer($timer(0))"));
};
engine.AddHostObject("setTimeout", setTimeout);

clearTimeout = (int timeoutID) =>
{
    executeCommand($".timer{timeoutID} off");
};
engine.AddHostObject("clearTimeout", clearTimeout);
realJoshByrnes commented 2 years ago

I don't think many Web API objects should be included as part of this project, however there are a few such as timers that would be globally useful. Interaction with AdiIRC where possible rather than using a C# implementation would be preferable.