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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,9 @@ import {
import { import {
setChannelTripLevel, setChannelTripLevel,
} from '../utility/_Channels.js'; } from '../utility/_Channels.js';
import {
Errors,
} from '../utility/_Constants.js';
/** /**
* Automatically executes once after server is ready * Automatically executes once after server is ready
@ -41,16 +44,18 @@ export async function run({
if (typeof payload.trip !== 'string' || payload.trip.length !== 6) { if (typeof payload.trip !== 'string' || payload.trip.length !== 6) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
if (typeof payload.level !== 'string' || core.levelLabels.indexOf(payload.level) === -1) { if (typeof payload.level !== 'string' || core.levelLabels.indexOf(payload.level) === -1) {
return server.reply({ 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(', ')}`, 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -59,8 +64,9 @@ export async function run({
if (newLevel >= socket.level) { if (newLevel >= socket.level) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -69,8 +75,9 @@ export async function run({
if (setError !== '') { if (setError !== '') {
return server.reply({ return server.reply({
cmd: 'warn', // @todo Add numeric error code as `id` cmd: 'warn',
text: `Failed to set level: ${setError}`, text: `Failed to set level: ${setError}`,
id: Errors.SetLevel.APPLY_ERROR,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -93,7 +100,7 @@ export async function run({
} }
server.broadcast({ 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}"`, text: `Changed permission level of "${payload.trip}" to "${payload.level}"`,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, { channel: socket.channel }); }, { channel: socket.channel });
@ -132,8 +139,9 @@ export function setlevelCheck({
// If there is no trip parameter // If there is no trip parameter
if (!input[1]) { if (!input[1]) {
server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
@ -143,8 +151,9 @@ export function setlevelCheck({
// If there is no level parameter // If there is no level parameter
if (!input[2]) { if (!input[2]) {
server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);

View File

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

View File

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

View File

@ -9,6 +9,9 @@
import { import {
getUserDetails, getUserDetails,
} from '../utility/_UAC.js'; } from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/** /**
* Validate a string as a valid hex color string * Validate a string as a valid hex color string
@ -32,8 +35,9 @@ export async function run({
if (server.police.frisk(socket, 1)) { if (server.police.frisk(socket, 1)) {
return server.reply({ 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.', text: 'You are changing colors too fast. Wait a moment before trying again.',
id: Errors.Global.RATELIMIT,
channel, // @todo Multichannel channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -49,6 +53,7 @@ export async function run({
return server.reply({ return server.reply({
cmd: 'warn', cmd: 'warn',
text: 'Invalid color! Color must be in hex value', text: 'Invalid color! Color must be in hex value',
id: Errors.ChangeColor.INVALID_COLOR,
channel, // @todo Multichannel channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -107,7 +112,8 @@ export function colorCheck({
if (input[1] === undefined) { if (input[1] === undefined) {
server.reply({ server.reply({
cmd: 'warn', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);

View File

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

View File

@ -13,6 +13,9 @@ import {
isAdmin, isAdmin,
isModerator, isModerator,
} from '../utility/_UAC.js'; } from '../utility/_UAC.js';
import {
Errors,
} from '../utility/_Constants.js';
/** /**
* Maximum length of the customId property * Maximum length of the customId property
@ -95,8 +98,9 @@ export async function run({
const score = text.length / 83 / 4; const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) { if (server.police.frisk(socket, score)) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -172,7 +176,7 @@ export function commandCheckIn({ server, socket, payload }) {
if (payload.text.startsWith('/myhash')) { if (payload.text.startsWith('/myhash')) {
server.reply({ server.reply({
cmd: 'info', cmd: 'info', // @todo Add numeric info code as `id`
text: `Your hash: ${socket.hash}`, text: `Your hash: ${socket.hash}`,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
@ -208,8 +212,9 @@ export function finalCmdCheck({ server, socket, payload }) {
} }
server.reply({ server.reply({
cmd: 'warn', // @todo Add numeric error code as `id` cmd: 'warn',
text: `Unknown command: ${payload.text}`, text: `Unknown command: ${payload.text}`,
id: Errors.Global.UNKNOWN_CMD,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);

View File

@ -6,6 +6,10 @@
* @module emote * @module emote
*/ */
import {
Errors,
} from '../utility/_Constants.js';
/** /**
* Check and trim string provided by remote client * Check and trim string provided by remote client
* @param {string} text - Subject string * @param {string} text - Subject string
@ -48,8 +52,9 @@ export async function run({ server, socket, payload }) {
const score = text.length / 83 / 4; const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) { if (server.police.frisk(socket, score)) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -108,8 +113,9 @@ export function emoteCheck({
// If there is no emote target parameter // If there is no emote target parameter
if (input[1] === undefined) { if (input[1] === undefined) {
server.reply({ 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.', text: 'Refer to `/help emote` for instructions on how to use this command.',
id: Errors.Emote.MISSING_TEXT,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);

View File

@ -8,6 +8,7 @@
import { import {
CodebaseVersion, CodebaseVersion,
Errors,
} from '../utility/_Constants.js'; } from '../utility/_Constants.js';
/** /**
@ -22,8 +23,9 @@ export async function run({
// check for spam // check for spam
if (server.police.frisk(socket, 2)) { if (server.police.frisk(socket, 2)) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -68,7 +70,7 @@ export async function run({
// output reply // output reply
server.reply({ server.reply({
cmd: 'info', cmd: 'info', // @todo Add numeric info code as `id`
text: reply, text: reply,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);

View File

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

View File

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

View File

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

View File

@ -66,8 +66,9 @@ export async function run({ server, socket, payload }) {
const score = text.length / 83 / 4; const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) { if (server.police.frisk(socket, score)) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }
@ -141,8 +142,9 @@ export function whisperCheck({
// If there is no nickname target parameter // If there is no nickname target parameter
if (!input[1]) { if (!input[1]) {
server.reply({ 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.', text: 'Refer to `/help whisper` for instructions on how to use this command.',
id: Errors.Whisper.MISSING_NICK,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
@ -171,8 +173,9 @@ export function whisperCheck({
if (payload.text.startsWith('/reply ') || payload.text.startsWith('/r ')) { if (payload.text.startsWith('/reply ') || payload.text.startsWith('/r ')) {
if (typeof socket.whisperReply === 'undefined') { if (typeof socket.whisperReply === 'undefined') {
server.reply({ server.reply({
cmd: 'warn', // @todo Add numeric error code as `id` cmd: 'warn',
text: 'Cannot reply to nobody', text: 'Cannot reply to nobody',
id: Errors.Whisper.NO_REPLY,
channel: socket.channel, // @todo Multichannel channel: socket.channel, // @todo Multichannel
}, socket); }, socket);

View File

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

View File

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

View File

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

View File

@ -130,7 +130,7 @@ export async function run({
// notify mods // notify mods
server.broadcast({ 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}`, text: `${socket.nick}#${socket.trip} muzzled ${targetUser.nick} in ${payload.channel}, userhash: ${targetUser.hash}`,
channel: false, // @todo Multichannel, false for global channel: false, // @todo Multichannel, false for global
}, { level: isModerator }); }, { level: isModerator });
@ -315,8 +315,9 @@ export function whisperCheck({
const score = text.length / 83 / 4; const score = text.length / 83 / 4;
if (server.police.frisk(socket, score)) { if (server.police.frisk(socket, score)) {
return server.reply({ 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.', 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 channel: socket.channel, // @todo Multichannel
}, socket); }, socket);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,14 +10,28 @@
* Internal version, used mainly for debugging * Internal version, used mainly for debugging
* @typedef {object} CodebaseVersion * @typedef {object} CodebaseVersion
*/ */
export const CodebaseVersion = '2.2.23b'; export const CodebaseVersion = '2.2.24b';
/* Base error ranges */ /* Base error ranges */
const GlobalErrors = 10; const GlobalErrors = 10;
const JoinErrors = 20; const CaptchaNotif = GlobalErrors + 10;
const ChannelErrors = 30; const JoinErrors = CaptchaNotif + 10;
const InviteErrors = 40; const ChannelErrors = JoinErrors + 10;
const SessionErrors = 50; 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 * Holds the numeric id values for each error type
@ -28,6 +42,13 @@ export const Errors = {
RATELIMIT: GlobalErrors + 1, RATELIMIT: GlobalErrors + 1,
UNKNOWN_USER: GlobalErrors + 2, UNKNOWN_USER: GlobalErrors + 2,
PERMISSION: GlobalErrors + 3, PERMISSION: GlobalErrors + 3,
INTERNAL_ERROR: GlobalErrors + 4,
MISSING_TRIPCODE: GlobalErrors + 5,
UNKNOWN_CMD: GlobalErrors + 6,
},
Captcha: {
MUST_SOLVE: CaptchaNotif + 1,
}, },
Join: { Join: {
@ -35,6 +56,7 @@ export const Errors = {
INVALID_NICK: JoinErrors + 2, INVALID_NICK: JoinErrors + 2,
ALREADY_JOINED: JoinErrors + 3, ALREADY_JOINED: JoinErrors + 3,
NAME_TAKEN: JoinErrors + 4, NAME_TAKEN: JoinErrors + 4,
CHANNEL_LOCKED: JoinErrors + 5,
}, },
Channel: { Channel: {
@ -50,6 +72,68 @@ export const Errors = {
Session: { Session: {
BAD_SESSION: SessionErrors + 1, 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', ownerTrip: 'Admin',
lastAccessed: now, lastAccessed: now,
claimExpires: expirationDate, claimExpires: expirationDate,
} },
} };
for (let i = 0, j = config.data.publicChannels.length; i < j; i += 1) { for (let i = 0, j = config.data.publicChannels.length; i < j; i += 1) {
const channelHash = getChannelHash(config.data.publicChannels[i]); const channelHash = getChannelHash(config.data.publicChannels[i]);