mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 20:13:07 +00:00
dd05ee3a65
Co-authored-by: Eric Nemchik <eric@nemchik.com> Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
102 lines
1.8 KiB
TypeScript
102 lines
1.8 KiB
TypeScript
import Client from "../../client";
|
|
import log from "../../log";
|
|
import Chan, {Channel} from "../../models/chan";
|
|
import Network, {NetworkWithIrcFramework} from "../../models/network";
|
|
import {PackageInfo} from "../packages";
|
|
|
|
export type PluginInputHandler = (
|
|
this: Client,
|
|
network: NetworkWithIrcFramework,
|
|
chan: Channel,
|
|
cmd: string,
|
|
args: string[]
|
|
) => void;
|
|
|
|
type Plugin = {
|
|
commands: string[];
|
|
input: (network: Network, chan: Chan, cmd: string, args: string[]) => void;
|
|
allowDisconnected?: boolean | undefined;
|
|
};
|
|
|
|
const clientSideCommands = ["/collapse", "/expand", "/search"];
|
|
|
|
const passThroughCommands = [
|
|
"/as",
|
|
"/bs",
|
|
"/cs",
|
|
"/ho",
|
|
"/hs",
|
|
"/join",
|
|
"/ms",
|
|
"/ns",
|
|
"/os",
|
|
"/rs",
|
|
];
|
|
|
|
const userInputs = new Map<string, Plugin>();
|
|
const builtInInputs = [
|
|
"action",
|
|
"away",
|
|
"ban",
|
|
"connect",
|
|
"ctcp",
|
|
"disconnect",
|
|
"ignore",
|
|
"invite",
|
|
"kick",
|
|
"kill",
|
|
"list",
|
|
"mode",
|
|
"msg",
|
|
"nick",
|
|
"notice",
|
|
"part",
|
|
"quit",
|
|
"raw",
|
|
"rejoin",
|
|
"topic",
|
|
"whois",
|
|
"mute",
|
|
];
|
|
|
|
for (const input of builtInInputs) {
|
|
import(`./${input}`)
|
|
.then(
|
|
(plugin: {
|
|
default: {
|
|
commands: string[];
|
|
input: (network: Network, chan: Chan, cmd: string, args: string[]) => void;
|
|
allowDisconnected?: boolean;
|
|
};
|
|
}) => {
|
|
plugin.default.commands.forEach((command: string) =>
|
|
userInputs.set(command, plugin.default)
|
|
);
|
|
}
|
|
)
|
|
.catch((err) => {
|
|
log.error(err);
|
|
});
|
|
}
|
|
|
|
const pluginCommands = new Map();
|
|
|
|
const getCommands = () =>
|
|
Array.from(userInputs.keys())
|
|
.concat(Array.from(pluginCommands.keys()))
|
|
.map((command) => `/${command}`)
|
|
.concat(clientSideCommands)
|
|
.concat(passThroughCommands)
|
|
.sort();
|
|
|
|
const addPluginCommand = (packageInfo: PackageInfo, command, func) => {
|
|
func.packageInfo = packageInfo;
|
|
pluginCommands.set(command, func);
|
|
};
|
|
|
|
export default {
|
|
addPluginCommand,
|
|
getCommands,
|
|
pluginCommands,
|
|
userInputs,
|
|
};
|