Bug 1718428 - Tidy up existing plugin code in cZ. r=frg

This commit is contained in:
Ian Neal 2021-06-27 03:30:17 +01:00
Родитель a609fad995
Коммит b1b349b389
3 изменённых файлов: 51 добавлений и 57 удалений

Просмотреть файл

@ -199,8 +199,7 @@ function cmgr_defcmds(cmdary)
* @param name The |String| name of the command to define. * @param name The |String| name of the command to define.
* @param func A |Function| to call to handle dispatch of the new command. * @param func A |Function| to call to handle dispatch of the new command.
* @param flags Optional. A |Number| indicating any special requirements for the * @param flags Optional. A |Number| indicating any special requirements for the
* command. The |CommandManager| only checks for |CMD_NO_HELP|; * command.
* flags are stored unchanged.
* @param usage Optional. A |String| specifying the arguments to the command. If * @param usage Optional. A |String| specifying the arguments to the command. If
* not specified, the property string "cmd." + |name| + ".params" * not specified, the property string "cmd." + |name| + ".params"
* is read from |bundle| or |defaultBundle|. * is read from |bundle| or |defaultBundle|.
@ -214,16 +213,13 @@ function cmdmgr_defcmd(name, func, flags, usage, bundle)
if (!bundle) if (!bundle)
bundle = this.defaultBundle; bundle = this.defaultBundle;
var helpDefault; var helpDefault = MSG_NO_HELP;
var labelDefault = name; var labelDefault = name;
var aliasFor; var aliasFor;
if (typeof flags != "number") if (typeof flags != "number")
flags = this.defaultFlags; flags = this.defaultFlags;
if (flags & CMD_NO_HELP)
helpDefault = MSG_NO_HELP;
if (typeof usage != "string") if (typeof usage != "string")
usage = getMsgFrom(bundle, "cmd." + name + ".params", null, ""); usage = getMsgFrom(bundle, "cmd." + name + ".params", null, "");

Просмотреть файл

@ -9,7 +9,6 @@ const CMD_NEED_NET = 0x02;
const CMD_NEED_SRV = 0x04; const CMD_NEED_SRV = 0x04;
const CMD_NEED_CHAN = 0x08; const CMD_NEED_CHAN = 0x08;
const CMD_NEED_USER = 0x10; const CMD_NEED_USER = 0x10;
const CMD_NO_HELP = 0x20;
function initCommands() function initCommands()
{ {
@ -67,11 +66,11 @@ function initCommands()
["default-charset", cmdCharset, CMD_CONSOLE], ["default-charset", cmdCharset, CMD_CONSOLE],
["delete-view", cmdDeleteView, CMD_CONSOLE], ["delete-view", cmdDeleteView, CMD_CONSOLE],
["desc", cmdDesc, CMD_CONSOLE], ["desc", cmdDesc, CMD_CONSOLE],
["disable-plugin", cmdAblePlugin, CMD_CONSOLE], ["disable-plugin", cmdDisablePlugin, CMD_CONSOLE],
["disconnect", cmdDisconnect, CMD_NEED_SRV | CMD_CONSOLE], ["disconnect", cmdDisconnect, CMD_NEED_SRV | CMD_CONSOLE],
["disconnect-all", cmdDisconnectAll, CMD_CONSOLE], ["disconnect-all", cmdDisconnectAll, CMD_CONSOLE],
["echo", cmdEcho, CMD_CONSOLE], ["echo", cmdEcho, CMD_CONSOLE],
["enable-plugin", cmdAblePlugin, CMD_CONSOLE], ["enable-plugin", cmdEnablePlugin, CMD_CONSOLE],
["eval", cmdEval, CMD_CONSOLE], ["eval", cmdEval, CMD_CONSOLE],
["evalsilent", cmdEval, CMD_CONSOLE], ["evalsilent", cmdEval, CMD_CONSOLE],
["except", cmdBanOrExcept, CMD_NEED_CHAN | CMD_CONSOLE], ["except", cmdBanOrExcept, CMD_NEED_CHAN | CMD_CONSOLE],
@ -238,7 +237,7 @@ function initCommands()
cmdary.stringBundle = client.defaultBundle; cmdary.stringBundle = client.defaultBundle;
client.commandManager = new CommandManager(client.defaultBundle); client.commandManager = new CommandManager(client.defaultBundle);
client.commandManager.defaultFlags = CMD_NO_HELP | CMD_CONSOLE; client.commandManager.defaultFlags = CMD_CONSOLE;
client.commandManager.isCommandSatisfied = isCommandSatisfied; client.commandManager.isCommandSatisfied = isCommandSatisfied;
client.commandManager.defineCommands(cmdary); client.commandManager.defineCommands(cmdary);
@ -793,69 +792,67 @@ function getToggle (toggle, currentState)
* command definitions from here on down. * command definitions from here on down.
*/ */
function cmdAblePlugin(e) function cmdDisablePlugin(e)
{ {
if (e.command.name == "disable-plugin") if (!e.plugin.enabled)
{ {
if (!e.plugin.enabled) display(getMsg(MSG_IS_DISABLED, e.plugin.id));
{ return;
display(getMsg(MSG_IS_DISABLED, e.plugin.id)); }
return;
}
if (e.plugin.API > 0) if (e.plugin.API > 0)
{ {
if (!e.plugin.disable()) if (!e.plugin.disable())
{
display(getMsg(MSG_CANT_DISABLE, e.plugin.id));
return;
}
e.plugin.prefs["enabled"] = false;
}
else if (!("disablePlugin" in e.plugin.scope))
{ {
display(getMsg(MSG_CANT_DISABLE, e.plugin.id)); display(getMsg(MSG_CANT_DISABLE, e.plugin.id));
return; return;
} }
else e.plugin.prefs["enabled"] = false;
{ }
e.plugin.scope.disablePlugin(); else if (!("disablePlugin" in e.plugin.scope))
} {
display(getMsg(MSG_CANT_DISABLE, e.plugin.id));
display(getMsg(MSG_PLUGIN_DISABLED, e.plugin.id)); return;
e.plugin.enabled = false;
} }
else else
{ {
if (e.plugin.enabled) e.plugin.scope.disablePlugin();
{ }
display(getMsg(MSG_IS_ENABLED, e.plugin.id));
return;
}
if (e.plugin.API > 0) display(getMsg(MSG_PLUGIN_DISABLED, e.plugin.id));
{ e.plugin.enabled = false;
if (!e.plugin.enable()) }
{
display(getMsg(MSG_CANT_ENABLE, e.plugin.id)); function cmdEnablePlugin(e)
e.plugin.prefs["enabled"] = false; {
return; if (e.plugin.enabled)
} {
e.plugin.prefs["enabled"] = true; display(getMsg(MSG_IS_ENABLED, e.plugin.id));
} return;
else if (!("enablePlugin" in e.plugin.scope)) }
if (e.plugin.API > 0)
{
if (!e.plugin.enable())
{ {
display(getMsg(MSG_CANT_ENABLE, e.plugin.id)); display(getMsg(MSG_CANT_ENABLE, e.plugin.id));
e.plugin.prefs["enabled"] = false;
return; return;
} }
else e.plugin.prefs["enabled"] = true;
{
e.plugin.scope.enablePlugin();
}
display(getMsg(MSG_PLUGIN_ENABLED, e.plugin.id));
e.plugin.enabled = true;
} }
else if (!("enablePlugin" in e.plugin.scope))
{
display(getMsg(MSG_CANT_ENABLE, e.plugin.id));
return;
}
else
{
e.plugin.scope.enablePlugin();
}
display(getMsg(MSG_PLUGIN_ENABLED, e.plugin.id));
e.plugin.enabled = true;
} }
function cmdBanOrExcept(e) function cmdBanOrExcept(e)

Просмотреть файл

@ -3040,6 +3040,7 @@ function cli_installPlugin(name, source)
display(getMsg(MSG_INSTALL_PLUGIN_INSTALLING, [source.path, dest.path]), display(getMsg(MSG_INSTALL_PLUGIN_INSTALLING, [source.path, dest.path]),
MT_INFO); MT_INFO);
var ary;
if (source.path.match(/\.(jar|zip)$/i)) if (source.path.match(/\.(jar|zip)$/i))
{ {
try try