thelounge/server/plugins/inputs/action.ts

55 lines
1 KiB
TypeScript
Raw Normal View History

import {PluginInputHandler} from "./index";
import Msg, {MessageType} from "../../models/msg";
import {ChanType} from "../../models/chan";
const commands = ["slap", "me"];
const input: PluginInputHandler = function ({irc}, chan, cmd, args) {
if (chan.type !== ChanType.CHANNEL && chan.type !== ChanType.QUERY) {
2019-07-17 11:33:59 +02:00
chan.pushMessage(
this,
new Msg({
type: MessageType.ERROR,
2019-07-17 11:33:59 +02:00
text: `${cmd} command can only be used in channels and queries.`,
})
);
return;
}
2018-01-11 12:33:36 +01:00
let text;
2015-10-01 00:39:57 +02:00
2014-09-13 23:29:45 +02:00
switch (cmd) {
2019-07-17 11:33:59 +02:00
case "slap":
text = "slaps " + args[0] + " around a bit with a large trout";
2014-09-13 23:29:45 +02:00
/* fall through */
2019-07-17 11:33:59 +02:00
case "me":
if (args.length === 0) {
break;
}
2015-10-01 00:39:57 +02:00
2019-07-17 11:33:59 +02:00
text = text || args.join(" ");
2016-03-08 14:36:25 +01:00
2019-07-17 11:33:59 +02:00
irc.action(chan.name, text);
2016-04-22 18:38:13 +02:00
// If the IRCd does not support echo-message, simulate the message
// being sent back to us.
2019-07-17 11:33:59 +02:00
if (!irc.network.cap.isEnabled("echo-message")) {
irc.emit("action", {
nick: irc.user.nick,
target: chan.name,
message: text,
});
}
2016-04-22 18:38:13 +02:00
2019-07-17 11:33:59 +02:00
break;
2014-09-13 23:29:45 +02:00
}
2016-03-06 10:24:56 +01:00
return true;
2014-09-13 23:29:45 +02:00
};
export default {
commands,
input,
};