mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
implemented motd, locklevel and initial channels
Delete public channels from the config.json, then do: npm run config
This commit is contained in:
parent
08e5062241
commit
bbb5c7eeb3
|
@ -15,9 +15,11 @@ import {
|
|||
import {
|
||||
canJoinChannel,
|
||||
socketInChannel,
|
||||
getChannelSettings,
|
||||
} from '../utility/_Channels.js';
|
||||
import {
|
||||
Errors,
|
||||
SystemMOTDs,
|
||||
} from '../utility/_Constants.js';
|
||||
import {
|
||||
upgradeLegacyJoin,
|
||||
|
@ -93,6 +95,17 @@ export async function run({
|
|||
// get trip and level
|
||||
const { trip, level } = getUserPerms(pass, core.saltKey, core.appConfig.data, channel);
|
||||
|
||||
const channelSettings = getChannelSettings(core.appConfig.data, channel);
|
||||
|
||||
if (level < channelSettings.lockLevel) {
|
||||
return server.reply({
|
||||
cmd: 'warn',
|
||||
text: 'You may not join that channel.',
|
||||
// id: Errors.Join., // @todo Add numeric error code as `id`
|
||||
channel: false, // @todo Multichannel, false for global event
|
||||
}, socket);
|
||||
}
|
||||
|
||||
// store the user values
|
||||
const userInfo = {
|
||||
nick,
|
||||
|
@ -168,6 +181,17 @@ export async function run({
|
|||
channel, // @todo Multichannel (?)
|
||||
}, socket);
|
||||
|
||||
var motd = channelSettings.motd;
|
||||
if (motd === '') {
|
||||
motd = SystemMOTDs[Math.floor(Math.random() * SystemMOTDs.length)];
|
||||
}
|
||||
|
||||
server.reply({
|
||||
cmd: 'info',
|
||||
text: motd,
|
||||
channel,
|
||||
}, socket);
|
||||
|
||||
// update client with new session info
|
||||
server.reply({
|
||||
cmd: 'session',
|
||||
|
|
|
@ -104,24 +104,25 @@ export function getChannelSettings(config, channel) {
|
|||
const channelHash = getChannelHash(channel);
|
||||
|
||||
if (typeof config.permissions[channelHash] === 'undefined') {
|
||||
const configPath = `../../channels/${channelHash[0]}/${channelHash}.json`;
|
||||
const configPath = `./channels/${channelHash[0]}/${channelHash}.json`;
|
||||
|
||||
if (!existsSync(configPath)) {
|
||||
return DefaultChannelSettings;
|
||||
config.permissions[channelHash] = {
|
||||
...DefaultChannelSettings,
|
||||
};
|
||||
} else {
|
||||
try {
|
||||
config.permissions[channelHash] = JSON.parse(readFileSync(configPath, 'utf8'));
|
||||
} catch (e) {
|
||||
console.log(`Corrupted channel config: ${configPath}`);
|
||||
|
||||
config.permissions[channelHash] = {
|
||||
...DefaultChannelSettings,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let configData;
|
||||
try {
|
||||
configData = JSON.parse(readFileSync(configPath, 'utf8'));
|
||||
} catch (e) {
|
||||
console.log(`Corrupted channel config: ${configPath}`);
|
||||
|
||||
return DefaultChannelSettings;
|
||||
}
|
||||
|
||||
// Check last access date here, if too old; delete file and return DefaultChannelSettings
|
||||
|
||||
config.permissions[channelHash] = configData;
|
||||
// @todo Check last access date here, if too old; delete file and use DefaultChannelSettings
|
||||
}
|
||||
|
||||
config.permissions[channelHash].lastAccessed = new Date();
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* Internal version, used mainly for debugging
|
||||
* @typedef {object} CodebaseVersion
|
||||
*/
|
||||
export const CodebaseVersion = '2.2.21b';
|
||||
export const CodebaseVersion = '2.2.23b';
|
||||
|
||||
/* Base error ranges */
|
||||
const GlobalErrors = 10;
|
||||
|
@ -71,8 +71,8 @@ export const DefaultChannelSettings = {
|
|||
* @typedef {object} SystemMOTDs
|
||||
*/
|
||||
export const SystemMOTDs = [
|
||||
'Protip: Using any hex color code, you can change your name color- for example: /color #FFFFFF`',
|
||||
'Protip: You can easily change your name with a command: /nick bob`',
|
||||
'Protip: Using any hex color code, you can change your name color- for example: /color #FFFFFF',
|
||||
'Protip: You can easily change your name with a command: /nick bob',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,12 @@ import {
|
|||
} from 'lowdb';
|
||||
import crypto from 'crypto';
|
||||
import enquirerPkg from 'enquirer';
|
||||
import {
|
||||
getChannelHash,
|
||||
} from '../commands/utility/_Channels.js';
|
||||
import {
|
||||
DefaultChannelSettings,
|
||||
} from '../commands/utility/_Constants.js';
|
||||
|
||||
const {
|
||||
Select,
|
||||
|
@ -150,8 +156,6 @@ const setupChannels = async () => {
|
|||
|
||||
if (mode === standardMode) {
|
||||
config.data.publicChannels = defaultChannels;
|
||||
|
||||
await config.write();
|
||||
} else {
|
||||
const channels = [];
|
||||
let newChannel = '';
|
||||
|
@ -168,9 +172,31 @@ const setupChannels = async () => {
|
|||
}
|
||||
|
||||
config.data.publicChannels = channels;
|
||||
|
||||
await config.write();
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const expirationDate = new Date();
|
||||
expirationDate.setDate(expirationDate.getDate() + 1825);
|
||||
const channelSettings = {
|
||||
...DefaultChannelSettings,
|
||||
...{
|
||||
owned: true,
|
||||
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]);
|
||||
const configPath = `./channels/${channelHash[0]}/${channelHash}.json`;
|
||||
|
||||
console.log(`Storing ${config.data.publicChannels[i]} -> ${configPath}`);
|
||||
|
||||
writeFileSync(configPath, JSON.stringify(channelSettings));
|
||||
}
|
||||
|
||||
await config.write();
|
||||
};
|
||||
|
||||
// check if pulic channels have been initialized
|
||||
|
|
Loading…
Reference in New Issue
Block a user