mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Minor module changes
Added trips to listusers output. Added 'reason' to reload broadcast. Fixed removemod bug. Added /nick hook to changenick. Added 'type' and 'from' fields to invite event.
This commit is contained in:
parent
7e1c679b00
commit
02f6fbf701
|
@ -20,7 +20,10 @@ exports.run = async (core, server, socket, data) => {
|
|||
if (typeof channels[currentUsers[i].channel] === 'undefined') {
|
||||
channels[currentUsers[i].channel] = [];
|
||||
}
|
||||
channels[currentUsers[i].channel].push(currentUsers[i].nick);
|
||||
|
||||
channels[currentUsers[i].channel].push(
|
||||
`[${currentUsers[i].trip||'null'}]${currentUsers[i].nick}`
|
||||
);
|
||||
}
|
||||
|
||||
// build output
|
||||
|
|
|
@ -19,9 +19,14 @@ exports.run = async (core, server, socket, data) => {
|
|||
|
||||
// build reply based on reload results
|
||||
if (loadResult == '') {
|
||||
loadResult = `Loaded ${core.commands._commands.length} commands, 0 errors`;
|
||||
loadResult = `Reloaded ${core.commands._commands.length} commands, 0 errors`;
|
||||
} else {
|
||||
loadResult = `Loaded ${core.commands._commands.length} commands, error(s): ${loadResult}`;
|
||||
loadResult = `Reloaded ${core.commands._commands.length} commands, error(s):
|
||||
${loadResult}`;
|
||||
}
|
||||
|
||||
if (typeof data.reason !== 'undefined') {
|
||||
loadResult += `\nReason: ${data.reason}`;
|
||||
}
|
||||
|
||||
// reply with results
|
||||
|
@ -42,5 +47,5 @@ exports.info = {
|
|||
name: 'reload',
|
||||
description: '(Re)loads any new commands into memory, outputs errors if any',
|
||||
usage: `
|
||||
API: { cmd: 'reload' }`
|
||||
API: { cmd: 'reload', reason: '<optional reason append>' }`
|
||||
};
|
||||
|
|
|
@ -14,8 +14,8 @@ exports.run = async (core, server, socket, data) => {
|
|||
|
||||
// find targets current connections
|
||||
let targetMod = server.findSockets({ trip: data.trip });
|
||||
if (newMod.length !== 0) {
|
||||
for (let i = 0, l = newMod.length; i < l; i++) {
|
||||
if (targetMod.length !== 0) {
|
||||
for (let i = 0, l = targetMod.length; i < l; i++) {
|
||||
// downgrade privilages
|
||||
targetMod[i].uType = 'user';
|
||||
|
||||
|
@ -30,7 +30,9 @@ exports.run = async (core, server, socket, data) => {
|
|||
// return success message
|
||||
server.reply({
|
||||
cmd: 'info',
|
||||
text: `Removed mod trip: ${data.trip}, remember to run 'saveconfig' to make it permanent`
|
||||
text: `Removed mod trip: ${
|
||||
data.trip
|
||||
}, remember to run 'saveconfig' to make it permanent`
|
||||
}, socket);
|
||||
|
||||
// notify all mods
|
||||
|
|
|
@ -55,6 +55,8 @@ exports.run = async (core, server, socket, data) => {
|
|||
}
|
||||
|
||||
// build join and leave notices
|
||||
// TODO: this is a legacy client holdover, name changes in the future will
|
||||
// have thieir own event
|
||||
let leaveNotice = {
|
||||
cmd: 'onlineRemove',
|
||||
nick: socket.nick
|
||||
|
@ -81,11 +83,49 @@ exports.run = async (core, server, socket, data) => {
|
|||
socket.nick = newNick;
|
||||
};
|
||||
|
||||
// module hook functions
|
||||
exports.initHooks = (server) => {
|
||||
server.registerHook('in', 'chat', this.nickCheck);
|
||||
};
|
||||
|
||||
// hooks chat commands checking for /whisper
|
||||
exports.nickCheck = (core, server, socket, payload) => {
|
||||
if (typeof payload.text !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (payload.text.startsWith('/nick')) {
|
||||
let input = payload.text.split(' ');
|
||||
|
||||
// If there is no nickname target parameter
|
||||
if (input[1] === undefined) {
|
||||
server.reply({
|
||||
cmd: 'warn',
|
||||
text: 'Refer to `/help nick` for instructions on how to use this command.'
|
||||
}, socket);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
let newNick = input[1].replace(/@/g, '');
|
||||
|
||||
this.run(core, server, socket, {
|
||||
cmd: 'changenick',
|
||||
nick: newNick
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return payload;
|
||||
};
|
||||
|
||||
// module meta
|
||||
exports.requiredData = ['nick'];
|
||||
exports.info = {
|
||||
name: 'changenick',
|
||||
description: 'This will change your current connections nickname',
|
||||
usage: `
|
||||
API: { cmd: 'changenick', nick: '<new nickname>' }`
|
||||
API: { cmd: 'changenick', nick: '<new nickname>' }
|
||||
Text: /nick <new nickname>`
|
||||
};
|
||||
|
|
|
@ -90,14 +90,12 @@ exports.commandCheckOut = (core, server, socket, payload) => {
|
|||
return payload;
|
||||
}
|
||||
|
||||
// TODO: make emotes their own module/event #lazydev
|
||||
if (payload.text.startsWith('//me ')) {
|
||||
payload.text = payload.text.substr(1, payload.text.length);
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
// TODO: make emotes their own module #lazydev
|
||||
if (payload.text.startsWith('/me ')) {
|
||||
} else if (payload.text.startsWith('/me ')) {
|
||||
let emote = payload.text.substr(4);
|
||||
if (emote.trim() === '') {
|
||||
emote = 'fails at life';
|
||||
|
@ -106,6 +104,7 @@ exports.commandCheckOut = (core, server, socket, payload) => {
|
|||
let newPayload = {
|
||||
cmd: 'info',
|
||||
type: 'emote',
|
||||
nick: payload.nick,
|
||||
text: `@${payload.nick} ${emote}`
|
||||
};
|
||||
|
||||
|
|
|
@ -31,11 +31,16 @@ exports.run = async (core, server, socket, data) => {
|
|||
// build and send invite
|
||||
let payload = {
|
||||
cmd: 'info',
|
||||
type: 'invite',
|
||||
from: socket.nick,
|
||||
invite: channel,
|
||||
text: `${socket.nick} invited you to ?${channel}`
|
||||
};
|
||||
|
||||
let inviteSent = server.broadcast( payload, { channel: socket.channel, nick: data.nick });
|
||||
let inviteSent = server.broadcast( payload, {
|
||||
channel: socket.channel,
|
||||
nick: data.nick
|
||||
});
|
||||
|
||||
// server indicates the user was not found
|
||||
if (!inviteSent) {
|
||||
|
@ -48,6 +53,8 @@ exports.run = async (core, server, socket, data) => {
|
|||
// reply with common channel
|
||||
server.reply({
|
||||
cmd: 'info',
|
||||
type: 'invite',
|
||||
invite: channel,
|
||||
text: `You invited ${data.nick} to ?${channel}`
|
||||
}, socket);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ exports.parseNickname = (core, data) => {
|
|||
}
|
||||
|
||||
let password = nickArray[1];
|
||||
|
||||
|
||||
if (hash(password + core.config.tripSalt) === core.config.adminTrip) {
|
||||
userInfo.uType = 'admin';
|
||||
userInfo.trip = 'Admin';
|
||||
|
|
|
@ -85,13 +85,14 @@ exports.whisperCheck = (core, server, socket, payload) => {
|
|||
|
||||
if (payload.text.startsWith('/whisper')) {
|
||||
let input = payload.text.split(' ');
|
||||
|
||||
// If there is no nickname target parameter
|
||||
if (input[1] === undefined) {
|
||||
server.reply({
|
||||
cmd: 'warn',
|
||||
text: 'Refer to `/help whisper` for instructions on how to use this command.'
|
||||
}, socket);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user