1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00

added missing warning id props

This commit is contained in:
marzavec 2024-01-08 11:09:59 -08:00
parent bbb5c7eeb3
commit ba7ae876ed
36 changed files with 296 additions and 121 deletions

View File

@ -50,7 +50,7 @@ export async function run({
// inform new mod
server.send({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'You are now a mod.',
channel: newMod[i].channel, // @todo Multichannel
}, newMod[i]);
@ -67,14 +67,14 @@ export async function run({
// return success message
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Added mod trip: ${payload.trip}, remember to run 'saveconfig' to make it permanent`,
channel: socket.channel, // @todo Multichannel
}, socket);
// notify all mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Added mod: ${payload.trip}`,
channel: false, // @todo Multichannel, false for global info
}, { level: isModerator });

View File

@ -51,7 +51,7 @@ export async function run({ server, socket }) {
// send reply
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: lines.join('\n'),
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -45,7 +45,7 @@ export async function run({
// send results to moderators (which the user using this command is higher than)
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: loadResult,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });

View File

@ -53,7 +53,7 @@ export async function run({
// inform ex-mod
server.send({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'You are now a user.',
channel: targetMod[i].channel, // @todo Multichannel
}, targetMod[i]);
@ -70,7 +70,7 @@ export async function run({
// return success message
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Removed mod trip: ${
payload.trip
}, remember to run 'saveconfig' to make it permanent`,
@ -79,7 +79,7 @@ export async function run({
// notify all mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Removed mod: ${payload.trip}`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });

View File

@ -10,6 +10,9 @@ import {
isAdmin,
isModerator,
} from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Executes when invoked by a remote client
@ -28,15 +31,16 @@ export async function run({ core, server, socket }) {
await core.appConfig.write();
} catch (err) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to save config, check logs.',
id: Errors.SaveConfig.GENERAL_FAILURE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
// return success message to moderators and admins
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Config saved!',
channel: false, // @todo Multichannel
}, { level: isModerator });

View File

@ -24,7 +24,7 @@ export async function run({ server, socket, payload }) {
// send text to all channels
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Server Notice: ${payload.text}`,
channel: false, // @todo Multichannel, false for global
}, {});

View File

@ -13,7 +13,7 @@ import {
levels,
} from '../utility/_UAC.js';
import {
// Errors,
Errors,
ClaimExpirationDays,
} from '../utility/_Constants.js';
import {
@ -37,16 +37,18 @@ export async function run({
if (!socket.trip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'Failed to take ownership: Missing trip code.',
cmd: 'warn',
text: 'Failed to run command: Missing trip code.',
id: Errors.Global.MISSING_TRIPCODE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (isModerator(socket.level)) {
return server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'warn',
text: "Failed to take ownership: You're already a global moderator; it's free real estate. . .",
id: Errors.ClaimChannel.MODS_CANT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -55,8 +57,11 @@ export async function run({
if (channelSettings.owned) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: `Failed to take ownership: This channel is already owned by the trip "${channelSettings.ownerTrip}", until ${channelSettings.claimExpires}`,
ownerTrip: channelSettings.ownerTrip,
claimExpires: channelSettings.claimExpires,
id: Errors.ClaimChannel.ALREADY_OWNED,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -68,6 +73,7 @@ export async function run({
server.reply({
cmd: 'warn',
text: 'Enter the following to take ownership (case-sensitive):',
id: Errors.Captcha.MUST_SOLVE,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -111,8 +117,11 @@ export function chatHook({
if (channelSettings.owned) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: `Failed to take ownership: This channel is already owned by the trip "${channelSettings.ownerTrip}", until ${channelSettings.claimExpires}`,
ownerTrip: channelSettings.ownerTrip,
claimExpires: channelSettings.claimExpires,
id: Errors.ClaimChannel.ALREADY_OWNED,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -126,7 +135,7 @@ export function chatHook({
updateChannelSettings(core.appConfig.data, socket.channel, channelSettings);
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Channel now owned by "${socket.trip}", until ${channelSettings.claimExpires}`,
channel: socket.channel,
}, { channel: socket.channel });

View File

@ -9,11 +9,9 @@
import {
isChannelOwner,
} from '../utility/_UAC.js';
/*
import {
Errors,
} from '../utility/_Constants.js';
*/
/**
* Executes when invoked by a remote client
@ -31,16 +29,18 @@ export async function run({
if (!socket.trip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'Failed to make channel private: Missing trip code.',
cmd: 'warn',
text: 'Failed to run command: Missing trip code.',
id: Errors.Global.MISSING_TRIPCODE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (!isChannelOwner(socket.level)) {
return server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to make channel private: You may not do that',
id: Errors.MakePrivate.MISSING_PERMS,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -49,8 +49,9 @@ export async function run({
if (listingIndex === -1) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to make channel private: This channel is already private',
id: Errors.MakePrivate.ALREADY_PRIVATE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -58,7 +59,7 @@ export async function run({
core.appConfig.data.publicChannels.splice(listingIndex, 1);
server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'info', // @todo Add numeric info code as `id`
text: 'This channel has been removed from the list of public channels',
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -11,11 +11,9 @@ import {
isChannelOwner,
isModerator,
} from '../utility/_UAC.js';
/*
import {
Errors,
} from '../utility/_Constants.js';
*/
import {
getChannelSettings,
} from '../utility/_Channels.js';
@ -36,16 +34,18 @@ export async function run({
if (!socket.trip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'Failed to make channel public: Missing trip code.',
cmd: 'warn',
text: 'Failed to run command: Missing trip code.',
id: Errors.Global.MISSING_TRIPCODE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (isModerator(socket.level) || !isChannelOwner(socket.level)) {
return server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to make channel public: You may not do that',
id: Errors.MakePublic.MISSING_PERMS,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -57,6 +57,7 @@ export async function run({
server.reply({
cmd: 'warn',
text: 'Enter the following to make channel public (case-sensitive):',
id: Errors.Captcha.MUST_SOLVE,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -100,16 +101,18 @@ export function chatHook({
if (channelSettings.owned === false || socket.trip !== channelSettings.ownerTrip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to make channel public: You may not do that',
id: Errors.MakePublic.MISSING_PERMS,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (core.appConfig.data.publicChannels.indexOf(socket.channel) !== -1) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to make channel public: This channel is already public',
id: Errors.MakePublic.ALREADY_PUBLIC,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -117,13 +120,13 @@ export function chatHook({
core.appConfig.data.publicChannels.push(socket.channel);
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `A new channel has been made public: ?${socket.channel}`,
channel: socket.channel, // @todo Multichannel
}, { level: (level) => isModerator(level) });
server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'info', // @todo Add numeric info code as `id`
text: 'This channel has been added to the list of public channels',
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -11,7 +11,7 @@ import {
isModerator,
} from '../utility/_UAC.js';
import {
// Errors,
Errors,
ClaimExpirationDays,
} from '../utility/_Constants.js';
import {
@ -35,16 +35,18 @@ export async function run({
if (!socket.trip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'Failed to renew ownership: Missing trip code.',
cmd: 'warn',
text: 'Failed to run command: Missing trip code.',
id: Errors.Global.MISSING_TRIPCODE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (isModerator(socket.level)) {
return server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'warn',
text: "Failed to renew ownership: You're already a global moderator; it's free real estate. . .",
id: Errors.RenewClaim.MODS_CANT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -53,8 +55,9 @@ export async function run({
if (channelSettings.owned === false || socket.trip !== channelSettings.ownerTrip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to renew ownership: You may not do that',
id: Errors.RenewClaim.NOT_OWNER,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -62,9 +65,13 @@ export async function run({
const hoursLeft = Math.abs(channelSettings.claimExpires - new Date()) / (60 * 60 * 1000);
if (hoursLeft > 24) {
const timeLeft = hoursLeft - 24;
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: `Failed to renew ownership: You must wait. Hours until renewable: ${hoursLeft - 24}`,
cmd: 'warn',
text: `Failed to renew ownership: You must wait. Hours until renewable: ${timeLeft}`,
timeLeft,
id: Errors.RenewClaim.TOO_SOON,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -76,6 +83,7 @@ export async function run({
server.reply({
cmd: 'warn',
text: 'Enter the following to renew ownership (case-sensitive):',
id: Errors.Captcha.MUST_SOLVE,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -119,8 +127,9 @@ export function chatHook({
if (channelSettings.owned === false || socket.trip !== channelSettings.ownerTrip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to renew ownership: You may not do that',
id: Errors.RenewClaim.NOT_OWNER,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -132,7 +141,7 @@ export function chatHook({
updateChannelSettings(core.appConfig.data, socket.channel, channelSettings);
server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'info', // @todo Add numeric info code as `id`
text: `Your claim has been renewed until ${expirationDate}`,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -14,6 +14,9 @@ import {
import {
setChannelTripLevel,
} from '../utility/_Channels.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Automatically executes once after server is ready
@ -41,16 +44,18 @@ export async function run({
if (typeof payload.trip !== 'string' || payload.trip.length !== 6) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to set level: Invalid trip. Refer to `/help setlevel` for instructions on how to use this command.',
id: Errors.SetLevel.BAD_TRIP,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (typeof payload.level !== 'string' || core.levelLabels.indexOf(payload.level) === -1) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: `Failed to set level: Invalid level label; choices are case sensitive: ${core.levelLabels.join(', ')}`,
id: Errors.SetLevel.BAD_LABEL,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -59,8 +64,9 @@ export async function run({
if (newLevel >= socket.level) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to set level: New level may not be the same or greater than your own.',
id: Errors.SetLevel.BAD_LEVEL,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -69,8 +75,9 @@ export async function run({
if (setError !== '') {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: `Failed to set level: ${setError}`,
id: Errors.SetLevel.APPLY_ERROR,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -93,7 +100,7 @@ export async function run({
}
server.broadcast({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'info', // @todo Add numeric info code as `id`
text: `Changed permission level of "${payload.trip}" to "${payload.level}"`,
channel: socket.channel, // @todo Multichannel
}, { channel: socket.channel });
@ -132,8 +139,9 @@ export function setlevelCheck({
// If there is no trip parameter
if (!input[1]) {
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to set level: Missing trip. Refer to `/help setlevel` for instructions on how to use this command.',
id: Errors.SetLevel.BAD_TRIP,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -143,8 +151,9 @@ export function setlevelCheck({
// If there is no level parameter
if (!input[2]) {
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to set level: Missing level label. Refer to `/help setlevel` for instructions on how to use this command.',
id: Errors.SetLevel.BAD_LABEL,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -14,6 +14,7 @@ import {
updateChannelSettings,
} from '../utility/_Channels.js';
import {
Errors,
MaxMOTDLength,
} from '../utility/_Constants.js';
@ -28,8 +29,9 @@ export async function run({
}) {
if (server.police.frisk(socket, 6)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Issuing commands too quickly. Wait a moment before trying again.',
id: Errors.Global.RATELIMIT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -41,8 +43,10 @@ export async function run({
if (typeof payload.motd !== 'string' || payload.motd.length >= MaxMOTDLength) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: `Failed to set motd: Invalid motd, max length: ${MaxMOTDLength}`,
MaxLength: MaxMOTDLength,
id: Errors.SetMOTD.TOO_LONG,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -54,13 +58,13 @@ export async function run({
updateChannelSettings(core.appConfig.data, socket.channel, channelSettings);
server.broadcast({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'info', // @todo Add numeric info code as `id`
text: `MOTD changed by [${socket.trip}]${socket.nick}, new motd:`,
channel: socket.channel, // @todo Multichannel
}, { channel: socket.channel });
server.broadcast({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'info', // @todo Add numeric info code as `id`
text: channelSettings.motd,
channel: socket.channel, // @todo Multichannel
}, { channel: socket.channel });

View File

@ -12,7 +12,7 @@ import {
levels,
} from '../utility/_UAC.js';
import {
// Errors,
Errors,
DefaultChannelSettings,
} from '../utility/_Constants.js';
import {
@ -36,8 +36,9 @@ export async function run({
if (!socket.trip) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'Failed to release ownership: Missing trip code.',
cmd: 'warn',
text: 'Failed to run command: Missing trip code.',
id: Errors.Global.MISSING_TRIPCODE,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -46,16 +47,18 @@ export async function run({
if (channelSettings.owned === false) {
return server.reply({
cmd: 'info', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to release ownership: That which is not owned may not be unowned, and with strange aeons. . .',
id: Errors.UnclaimChannel.NOT_OWNED,
channel: socket.channel, // @todo Multichannel
}, socket);
}
if (channelSettings.ownerTrip !== socket.trip && !isModerator(socket.level)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Failed to release ownership: Wrong trip code.',
id: Errors.UnclaimChannel.FAKE_OWNER,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -63,7 +66,7 @@ export async function run({
updateChannelSettings(core.appConfig.data, socket.channel, DefaultChannelSettings);
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Channel ownership has been removed and the channel settings have been reset',
channel: socket.channel,
}, { channel: socket.channel });

View File

@ -9,6 +9,9 @@
import {
getUserDetails,
} from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Validate a string as a valid hex color string
@ -32,8 +35,9 @@ export async function run({
if (server.police.frisk(socket, 1)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are changing colors too fast. Wait a moment before trying again.',
id: Errors.Global.RATELIMIT,
channel, // @todo Multichannel
}, socket);
}
@ -49,6 +53,7 @@ export async function run({
return server.reply({
cmd: 'warn',
text: 'Invalid color! Color must be in hex value',
id: Errors.ChangeColor.INVALID_COLOR,
channel, // @todo Multichannel
}, socket);
}
@ -107,7 +112,8 @@ export function colorCheck({
if (input[1] === undefined) {
server.reply({
cmd: 'warn',
text: 'Refer to `/help changecolor` for instructions on how to use this command.',
text: 'Invalid color! Color must be in hex value',
id: Errors.ChangeColor.INVALID_COLOR,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -12,6 +12,9 @@ import {
verifyNickname,
getUserDetails,
} from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Executes when invoked by a remote client
@ -26,8 +29,9 @@ export async function run({
if (server.police.frisk(socket, 6)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are changing nicknames too fast. Wait a moment before trying again.',
id: Errors.Global.RATELIMIT,
channel, // @todo Multichannel
}, socket);
}
@ -43,16 +47,18 @@ export async function run({
const newNick = payload.nick.trim();
if (!verifyNickname(newNick)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Nickname must consist of up to 24 letters, numbers, and underscores',
id: Errors.Join.INVALID_NICK,
channel, // @todo Multichannel
}, socket);
}
if (newNick == previousNick) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'You already have that name',
cmd: 'warn',
text: 'Nickname taken',
id: Errors.Join.NAME_TAKEN,
channel, // @todo Multichannel
}, socket);
}
@ -69,8 +75,9 @@ export async function run({
if (userExists.length > 0) {
// That nickname is already in that channel
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Nickname taken',
id: Errors.Join.NAME_TAKEN,
channel, // @todo Multichannel
}, socket);
}
@ -118,7 +125,7 @@ export async function run({
// notify channel that the user has changed their name
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick} is now ${newNick}`,
channel, // @todo Multichannel
}, { channel });
@ -160,8 +167,9 @@ export function nickCheck({
// If there is no nickname target parameter
if (!input[1]) {
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
text: 'Refer to `/help nick` for instructions on how to use this command.',
cmd: 'warn',
text: 'Nickname must consist of up to 24 letters, numbers, and underscores',
id: Errors.Join.INVALID_NICK,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -13,6 +13,9 @@ import {
isAdmin,
isModerator,
} from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Maximum length of the customId property
@ -95,8 +98,9 @@ export async function run({
const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
id: Errors.Global.RATELIMIT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -172,7 +176,7 @@ export function commandCheckIn({ server, socket, payload }) {
if (payload.text.startsWith('/myhash')) {
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Your hash: ${socket.hash}`,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -208,8 +212,9 @@ export function finalCmdCheck({ server, socket, payload }) {
}
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: `Unknown command: ${payload.text}`,
id: Errors.Global.UNKNOWN_CMD,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -6,6 +6,10 @@
* @module emote
*/
import {
Errors,
} from '../utility/_Constants.js';
/**
* Check and trim string provided by remote client
* @param {string} text - Subject string
@ -48,8 +52,9 @@ export async function run({ server, socket, payload }) {
const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
id: Errors.Global.RATELIMIT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -108,8 +113,9 @@ export function emoteCheck({
// If there is no emote target parameter
if (input[1] === undefined) {
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Refer to `/help emote` for instructions on how to use this command.',
id: Errors.Emote.MISSING_TEXT,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -8,6 +8,7 @@
import {
CodebaseVersion,
Errors,
} from '../utility/_Constants.js';
/**
@ -22,8 +23,9 @@ export async function run({
// check for spam
if (server.police.frisk(socket, 2)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
id: Errors.Global.RATELIMIT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -68,7 +70,7 @@ export async function run({
// output reply
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: reply,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -74,7 +74,7 @@ export async function run({
// @todo multichannel update, will remove
if (typeof socket.channel !== 'undefined') {
return server.reply({
cmd: 'warn', // @todo Remove this
cmd: 'warn',
text: 'Joining more than one channel is not currently supported',
id: Errors.Join.ALREADY_JOINED,
channel: false, // @todo Multichannel, false for global event
@ -101,7 +101,7 @@ export async function run({
return server.reply({
cmd: 'warn',
text: 'You may not join that channel.',
// id: Errors.Join., // @todo Add numeric error code as `id`
id: Errors.Join.CHANNEL_LOCKED,
channel: false, // @todo Multichannel, false for global event
}, socket);
}
@ -181,13 +181,13 @@ export async function run({
channel, // @todo Multichannel (?)
}, socket);
var motd = channelSettings.motd;
let { motd } = channelSettings;
if (motd === '') {
motd = SystemMOTDs[Math.floor(Math.random() * SystemMOTDs.length)];
}
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: motd,
channel,
}, socket);

View File

@ -74,7 +74,7 @@ export async function run({ core, server, socket }) {
// dispatch info
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
users: uniqueClientCount,
chans: uniqueChannels,
joins,

View File

@ -32,7 +32,7 @@ export async function run({ core, server, socket }) {
// dispatch info
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${uniqueClientCount} unique IPs in ${uniqueChannels} channels`,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -66,8 +66,9 @@ export async function run({ server, socket, payload }) {
const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
id: Errors.Global.RATELIMIT,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -141,8 +142,9 @@ export function whisperCheck({
// If there is no nickname target parameter
if (!input[1]) {
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Refer to `/help whisper` for instructions on how to use this command.',
id: Errors.Whisper.MISSING_NICK,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -171,8 +173,9 @@ export function whisperCheck({
if (payload.text.startsWith('/reply ') || payload.text.startsWith('/r ')) {
if (typeof socket.whisperReply === 'undefined') {
server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'Cannot reply to nobody',
id: Errors.Whisper.NO_REPLY,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -7,6 +7,10 @@
* @module socketreply
*/
import {
Errors,
} from '../utility/_Constants.js';
/**
* Executes when invoked by a remote client
* @param {Object} env - Environment object with references to core, server, socket & payload
@ -23,6 +27,8 @@ export async function run({ server, socket, payload }) {
return server.reply({
cmd: 'warn',
text: payload.text,
id: Errors.Global.INTERNAL_ERROR,
channel: false,
}, socket);
}

View File

@ -71,7 +71,7 @@ export async function run({
// notify normal users
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Banned ${targetNick}`,
user: getUserDetails(targetUser),
channel: socket.channel, // @todo Multichannel
@ -79,7 +79,7 @@ export async function run({
// notify mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick}#${socket.trip} banned ${targetNick} in ${payload.channel}, userhash: ${targetUser.hash}`,
channel: socket.channel, // @todo Multichannel
inChannel: payload.channel,

View File

@ -51,7 +51,7 @@ export async function run({
if (!core.captchas[targetChannel]) {
return server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Captcha is not enabled.',
channel: socket.channel, // @todo Multichannel
}, socket);
@ -60,7 +60,7 @@ export async function run({
core.captchas[targetChannel] = false;
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Captcha disabled on: ${targetChannel}`,
channel: false, // @todo Multichannel, false for global info
}, { channel: targetChannel, level: isModerator });

View File

@ -130,7 +130,7 @@ export async function run({
// notify mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick}#${socket.trip} muzzled ${targetUser.nick} in ${payload.channel}, userhash: ${targetUser.hash}`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });
@ -315,8 +315,9 @@ export function whisperCheck({
const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
id: Errors.Global.RATELIMIT,
channel: socket.channel, // @todo Multichannel
}, socket);
}

View File

@ -68,7 +68,7 @@ export async function run({
if (core.captchas[targetChannel]) {
return server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Captcha is already enabled.',
channel: socket.channel, // @todo Multichannel
}, socket);
@ -77,7 +77,7 @@ export async function run({
core.captchas[targetChannel] = true;
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Captcha enabled on: ${targetChannel}`,
channel: socket.channel, // @todo Multichannel, false for global info
}, { channel: socket.channel, level: isModerator });
@ -192,7 +192,7 @@ export function joinCheck({
// @todo multichannel update, will remove
if (typeof socket.channel !== 'undefined') {
return server.reply({
cmd: 'warn', // @todo Remove this
cmd: 'warn',
text: 'Joining more than one channel is not currently supported',
id: Errors.Join.ALREADY_JOINED,
channel: false, // @todo Multichannel, false for global event
@ -240,6 +240,7 @@ export function joinCheck({
server.reply({
cmd: 'warn',
text: 'Enter the following to join (case-sensitive):',
id: Errors.Captcha.MUST_SOLVE,
channel: payload.channel, // @todo Multichannel
}, socket);

View File

@ -60,6 +60,7 @@ export async function run({
return server.reply({
cmd: 'warn',
text: 'Invalid color! Color must be in hex value',
id: Errors.ChangeColor.INVALID_COLOR,
channel, // @todo Multichannel
}, socket);
}
@ -137,6 +138,7 @@ export function colorCheck({
server.reply({
cmd: 'warn',
text: 'Refer to `/help forcecolor` for instructions on how to use this command.',
id: Errors.ForceColor.MISSING_NICK,
channel: socket.channel, // @todo Multichannel
}, socket);
@ -146,7 +148,8 @@ export function colorCheck({
if (input[2] === undefined) {
server.reply({
cmd: 'warn',
text: 'Refer to `/help forcecolor` for instructions on how to use this command.',
text: 'Invalid color! Color must be in hex value',
id: Errors.ChangeColor.INVALID_COLOR,
channel: socket.channel, // @todo Multichannel
}, socket);

View File

@ -102,7 +102,7 @@ export async function run({
kicked[i].channel = destChannel;
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${kicked[i].nick} was banished to ?${destChannel}`,
channel: socket.channel, // @todo Multichannel
}, { channel: socket.channel, level: isModerator });
@ -122,7 +122,7 @@ export async function run({
// publicly broadcast kick event
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Kicked ${kicked.map((k) => k.nick).join(', ')}`,
channel: socket.channel, // @todo Multichannel
}, { channel: socket.channel, level: (level) => isModerator(level) });

View File

@ -88,7 +88,7 @@ export async function run({
if (core.locked[targetChannel]) {
return server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Channel is already locked.',
channel: socket.channel, // @todo Multichannel
}, socket);
@ -99,7 +99,7 @@ export async function run({
// inform mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Channel: ?${targetChannel} lock enabled by [${socket.trip}]${socket.nick}`,
channel: false, // @todo Multichannel, false for global info
}, { level: isModerator });
@ -243,7 +243,7 @@ export function joinCheck({
// @todo multichannel update, will remove
if (typeof socket.channel !== 'undefined') {
return server.reply({
cmd: 'warn', // @todo Remove this
cmd: 'warn',
text: 'Joining more than one channel is not currently supported',
id: Errors.Join.ALREADY_JOINED,
channel: false, // @todo Multichannel, false for global event
@ -296,14 +296,14 @@ export function joinCheck({
setTimeout(() => {
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: danteQuotes[Math.floor(Math.random() * danteQuotes.length)],
channel: 'purgatory', // @todo Multichannel
}, socket);
}, 100);
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${payload.nick} is: ${origNick}\ntrip: ${userInfo.trip || 'none'}\ntried to join: ?${origChannel}\nhash: ${userInfo.hash}`,
channel: 'purgatory', // @todo Multichannel, false for global info
}, { channel: 'purgatory', level: isModerator });

View File

@ -11,6 +11,9 @@
import {
isModerator,
} from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Automatically executes once after server is ready
@ -41,8 +44,9 @@ export async function run({
// check user input
if (typeof payload.ip !== 'string' && typeof payload.hash !== 'string') {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: "hash:'targethash' or ip:'1.2.3.4' is required",
id: Errors.Users.BAD_HASH_OR_IP,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -52,7 +56,7 @@ export async function run({
core.muzzledHashes = {};
return server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick} unmuzzled all users`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });
@ -61,7 +65,7 @@ export async function run({
core.muzzledHashes = {};
return server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick} unmuzzled all users`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });
@ -79,7 +83,7 @@ export async function run({
// notify mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick}#${socket.trip} unmuzzled : ${target}`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });

View File

@ -9,6 +9,9 @@
import {
isModerator,
} from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/**
* Executes when invoked by a remote client
@ -27,8 +30,9 @@ export async function run({
// check user input
if (typeof payload.ip !== 'string' && typeof payload.hash !== 'string') {
return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id`
cmd: 'warn',
text: "hash:'targethash' or ip:'1.2.3.4' is required",
id: Errors.Users.BAD_HASH_OR_IP,
channel: socket.channel, // @todo Multichannel
}, socket);
}
@ -55,14 +59,14 @@ export async function run({
// reply with success
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Unbanned ${target}`,
channel: socket.channel, // @todo Multichannel
}, socket);
// notify mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick}#${socket.trip} unbanned: ${target}`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });

View File

@ -31,14 +31,14 @@ export async function run({ core, server, socket }) {
// reply with success
server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Unbanned all ip addresses',
channel: socket.channel, // @todo Multichannel
}, socket);
// notify mods
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `${socket.nick}#${socket.trip} unbanned all ip addresses`,
channel: false, // @todo Multichannel, false for global
}, { level: isModerator });

View File

@ -52,7 +52,7 @@ export async function run({
if (!core.locked[targetChannel]) {
return server.reply({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: 'Channel is not locked.',
channel: socket.channel, // @todo Multichannel
}, socket);
@ -61,7 +61,7 @@ export async function run({
core.locked[targetChannel] = false;
server.broadcast({
cmd: 'info',
cmd: 'info', // @todo Add numeric info code as `id`
text: `Channel: ?${targetChannel} unlocked by [${socket.trip}]${socket.nick}`,
channel: targetChannel, // @todo Multichannel, false for global info
}, { channel: targetChannel, level: isModerator });

View File

@ -10,14 +10,28 @@
* Internal version, used mainly for debugging
* @typedef {object} CodebaseVersion
*/
export const CodebaseVersion = '2.2.23b';
export const CodebaseVersion = '2.2.24b';
/* Base error ranges */
const GlobalErrors = 10;
const JoinErrors = 20;
const ChannelErrors = 30;
const InviteErrors = 40;
const SessionErrors = 50;
const CaptchaNotif = GlobalErrors + 10;
const JoinErrors = CaptchaNotif + 10;
const ChannelErrors = JoinErrors + 10;
const InviteErrors = ChannelErrors + 10;
const SessionErrors = InviteErrors + 10;
const SaveConfigErrors = SessionErrors + 10;
const ClaimChannelErrors = SaveConfigErrors + 10;
const MakePrivateErrors = ClaimChannelErrors + 10;
const MakePublicErrors = MakePrivateErrors + 10;
const RenewClaimErrors = MakePublicErrors + 10;
const SetLevelErrors = RenewClaimErrors + 10;
const SetMOTDErrors = SetLevelErrors + 10;
const UnclaimChannelErrors = SetMOTDErrors + 10;
const ChangeColorErrors = UnclaimChannelErrors + 10;
const EmoteErrors = ChangeColorErrors + 10;
const WhisperErrors = EmoteErrors + 10;
const ForceColorErrors = WhisperErrors + 10;
const UsersErrors = ForceColorErrors + 10;
/**
* Holds the numeric id values for each error type
@ -28,6 +42,13 @@ export const Errors = {
RATELIMIT: GlobalErrors + 1,
UNKNOWN_USER: GlobalErrors + 2,
PERMISSION: GlobalErrors + 3,
INTERNAL_ERROR: GlobalErrors + 4,
MISSING_TRIPCODE: GlobalErrors + 5,
UNKNOWN_CMD: GlobalErrors + 6,
},
Captcha: {
MUST_SOLVE: CaptchaNotif + 1,
},
Join: {
@ -35,6 +56,7 @@ export const Errors = {
INVALID_NICK: JoinErrors + 2,
ALREADY_JOINED: JoinErrors + 3,
NAME_TAKEN: JoinErrors + 4,
CHANNEL_LOCKED: JoinErrors + 5,
},
Channel: {
@ -50,6 +72,68 @@ export const Errors = {
Session: {
BAD_SESSION: SessionErrors + 1,
},
SaveConfig: {
GENERAL_FAILURE: SaveConfigErrors + 1,
},
ClaimChannel: {
MODS_CANT: ClaimChannelErrors + 1,
ALREADY_OWNED: ClaimChannelErrors + 2,
},
MakePrivate: {
MISSING_PERMS: MakePrivateErrors + 1,
ALREADY_PRIVATE: MakePrivateErrors + 2,
},
MakePublic: {
MISSING_PERMS: MakePublicErrors + 1,
ALREADY_PUBLIC: MakePublicErrors + 2,
},
RenewClaim: {
MODS_CANT: RenewClaimErrors + 1,
NOT_OWNER: RenewClaimErrors + 2,
TOO_SOON: RenewClaimErrors + 3,
},
SetLevel: {
BAD_TRIP: SetLevelErrors + 1,
BAD_LABEL: SetLevelErrors + 2,
BAD_LEVEL: SetLevelErrors + 3,
APPLY_ERROR: SetLevelErrors + 4,
},
SetMOTD: {
TOO_LONG: SetMOTDErrors + 1,
},
UnclaimChannel: {
NOT_OWNED: UnclaimChannelErrors + 1,
FAKE_OWNER: UnclaimChannelErrors + 2,
},
ChangeColor: {
INVALID_COLOR: ChangeColorErrors + 1,
},
Emote: {
MISSING_TEXT: EmoteErrors + 1,
},
Whisper: {
MISSING_NICK: WhisperErrors + 1,
NO_REPLY: WhisperErrors + 2,
},
ForceColor: {
MISSING_NICK: ForceColorErrors + 1,
},
Users: {
BAD_HASH_OR_IP: UsersErrors + 1,
},
};
/**

View File

@ -184,8 +184,8 @@ const setupChannels = async () => {
ownerTrip: 'Admin',
lastAccessed: now,
claimExpires: expirationDate,
}
}
},
};
for (let i = 0, j = config.data.publicChannels.length; i < j; i += 1) {
const channelHash = getChannelHash(config.data.publicChannels[i]);