channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
/**
|
|
|
|
* @author Marzavec ( https://github.com/marzavec )
|
|
|
|
* @summary Change user level
|
|
|
|
* @version 1.0.0
|
|
|
|
* @description Alter the permission level a trip is allowed within current channel
|
|
|
|
* @module setlevel
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
|
|
|
levels,
|
|
|
|
isChannelModerator,
|
|
|
|
getUserDetails,
|
2024-01-18 01:19:06 +08:00
|
|
|
getAppearance,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
} from '../utility/_UAC.js';
|
|
|
|
import {
|
|
|
|
setChannelTripLevel,
|
|
|
|
} from '../utility/_Channels.js';
|
2024-01-09 03:09:59 +08:00
|
|
|
import {
|
|
|
|
Errors,
|
|
|
|
} from '../utility/_Constants.js';
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically executes once after server is ready
|
|
|
|
* @param {Object} core - Reference to core environment object
|
|
|
|
* @public
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
export async function init(core) {
|
|
|
|
core.levelLabels = Object.keys(levels);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes when invoked by a remote client
|
|
|
|
* @param {Object} env - Environment object with references to core, server, socket & payload
|
|
|
|
* @public
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
export async function run({
|
|
|
|
core, server, socket, payload,
|
|
|
|
}) {
|
|
|
|
// increase rate limit chance and ignore if not channel mod or better
|
|
|
|
if (!isChannelModerator(socket.level)) {
|
|
|
|
return server.police.frisk(socket, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof payload.trip !== 'string' || payload.trip.length !== 6) {
|
|
|
|
return server.reply({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'warn',
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
text: 'Failed to set level: Invalid trip. Refer to `/help setlevel` for instructions on how to use this command.',
|
2024-01-09 03:09:59 +08:00
|
|
|
id: Errors.SetLevel.BAD_TRIP,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, socket);
|
|
|
|
}
|
|
|
|
|
2024-01-06 02:38:54 +08:00
|
|
|
if (typeof payload.level !== 'string' || core.levelLabels.indexOf(payload.level) === -1) {
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
return server.reply({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'warn',
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
text: `Failed to set level: Invalid level label; choices are case sensitive: ${core.levelLabels.join(', ')}`,
|
2024-01-09 03:09:59 +08:00
|
|
|
id: Errors.SetLevel.BAD_LABEL,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
const newLevel = levels[payload.level];
|
|
|
|
|
|
|
|
if (newLevel >= socket.level) {
|
|
|
|
return server.reply({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'warn',
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
text: 'Failed to set level: New level may not be the same or greater than your own.',
|
2024-01-09 03:09:59 +08:00
|
|
|
id: Errors.SetLevel.BAD_LEVEL,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
const setError = setChannelTripLevel(core.appConfig.data, socket.channel, payload.trip, newLevel);
|
|
|
|
|
|
|
|
if (setError !== '') {
|
|
|
|
return server.reply({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'warn',
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
text: `Failed to set level: ${setError}`,
|
2024-01-09 03:09:59 +08:00
|
|
|
id: Errors.SetLevel.APPLY_ERROR,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
const targetClients = server.findSockets({
|
|
|
|
channel: socket.channel,
|
|
|
|
trip: payload.trip,
|
|
|
|
});
|
|
|
|
|
2024-01-12 03:14:15 +08:00
|
|
|
const { color, flair } = getAppearance(newLevel);
|
|
|
|
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
for (let i = 0, j = targetClients.length; i < j; i += 1) {
|
2024-01-12 03:14:15 +08:00
|
|
|
targetClients[i].color = color;
|
|
|
|
targetClients[i].flair = flair;
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
targetClients[i].level = newLevel;
|
|
|
|
|
|
|
|
server.broadcast({
|
|
|
|
...getUserDetails(targetClients[i]),
|
|
|
|
...{
|
|
|
|
cmd: 'updateUser',
|
|
|
|
channel: socket.channel,
|
|
|
|
},
|
|
|
|
}, { channel: socket.channel });
|
|
|
|
}
|
|
|
|
|
|
|
|
server.broadcast({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'info', // @todo Add numeric info code as `id`
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
text: `Changed permission level of "${payload.trip}" to "${payload.level}"`,
|
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, { channel: socket.channel });
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically executes once after server is ready to register this modules hooks
|
|
|
|
* @param {Object} server - Reference to server environment object
|
|
|
|
* @public
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
export function initHooks(server) {
|
|
|
|
server.registerHook('in', 'chat', this.setlevelCheck.bind(this), 29);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes every time an incoming chat command is invoked
|
|
|
|
* @param {Object} env - Environment object with references to core, server, socket & payload
|
|
|
|
* @public
|
|
|
|
* @return {(Object|boolean|string)} Object = same/altered payload,
|
|
|
|
* false = suppress action,
|
|
|
|
* string = error
|
|
|
|
*/
|
|
|
|
export function setlevelCheck({
|
|
|
|
core, server, socket, payload,
|
|
|
|
}) {
|
|
|
|
if (typeof payload.text !== 'string') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (payload.text.startsWith('/setlevel')) {
|
|
|
|
const input = payload.text.split(' ');
|
|
|
|
|
|
|
|
// If there is no trip parameter
|
|
|
|
if (!input[1]) {
|
|
|
|
server.reply({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'warn',
|
2024-01-06 02:38:54 +08:00
|
|
|
text: 'Failed to set level: Missing trip. Refer to `/help setlevel` for instructions on how to use this command.',
|
2024-01-09 03:09:59 +08:00
|
|
|
id: Errors.SetLevel.BAD_TRIP,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, socket);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no level parameter
|
|
|
|
if (!input[2]) {
|
|
|
|
server.reply({
|
2024-01-09 03:09:59 +08:00
|
|
|
cmd: 'warn',
|
2024-01-06 02:38:54 +08:00
|
|
|
text: 'Failed to set level: Missing level label. Refer to `/help setlevel` for instructions on how to use this command.',
|
2024-01-09 03:09:59 +08:00
|
|
|
id: Errors.SetLevel.BAD_LABEL,
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
|
|
|
}, socket);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.run({
|
|
|
|
core,
|
|
|
|
server,
|
|
|
|
socket,
|
|
|
|
payload: {
|
|
|
|
cmd: 'setlevel',
|
|
|
|
trip: input[1],
|
|
|
|
level: input[2],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The following payload properties are required to invoke this module:
|
|
|
|
* "trip", "level"
|
|
|
|
* @public
|
|
|
|
* @typedef {Array} setlevel/requiredData
|
|
|
|
*/
|
|
|
|
export const requiredData = ['trip', 'level'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module meta information
|
|
|
|
* @public
|
|
|
|
* @typedef {Object} setlevel/info
|
|
|
|
* @property {string} name - Module command name
|
|
|
|
* @property {string} category - Module category name
|
|
|
|
* @property {string} description - Information about module
|
|
|
|
* @property {string} usage - Information about module usage
|
|
|
|
*/
|
|
|
|
export const info = {
|
|
|
|
name: 'setlevel',
|
|
|
|
category: 'channels',
|
|
|
|
description: 'Alter the permission level a trip is allowed within current channel',
|
|
|
|
usage: `
|
|
|
|
API: { cmd: 'setlevel', trip: '[target trip]', level: '[level label]' }
|
|
|
|
Text: /setlevel <trip> <level label>`,
|
|
|
|
};
|