[refactory] extract function send_message
This commit is contained in:
parent
1abd6ecc2d
commit
19f7274e4b
@ -25,6 +25,14 @@ function unmask_room_name(name: string) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function send_message({ msg, sender }: { msg: string; sender: string; }, io: SocketServer, socket: Socket) {
|
||||||
|
io.in(Array.from(socket.rooms)).emit('new message', {
|
||||||
|
type: 'text-message',
|
||||||
|
data: msg,
|
||||||
|
sender: sender,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function run_command(cmd_raw: string, uid: string, users: Map<string, User>, io: SocketServer, silent: boolean = false) {
|
export function run_command(cmd_raw: string, uid: string, users: Map<string, User>, io: SocketServer, silent: boolean = false) {
|
||||||
const cmd = cmd_raw.replace(/(^\s*)|(\s*$)/, '');
|
const cmd = cmd_raw.replace(/(^\s*)|(\s*$)/, '');
|
||||||
|
|
||||||
@ -172,11 +180,7 @@ export function run_command(cmd_raw: string, uid: string, users: Map<string, Use
|
|||||||
});
|
});
|
||||||
|
|
||||||
command_map.set('anon', () => {
|
command_map.set('anon', () => {
|
||||||
io.in(Array.from(socket.rooms)).emit('new message', {
|
send_message({ msg: msg, sender: 'Anonymous User'}, io, socket);
|
||||||
type: 'text-message',
|
|
||||||
data: msg,
|
|
||||||
sender: 'Anonymous User',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user.is_administrator) {
|
if (user.is_administrator) {
|
||||||
|
@ -4,7 +4,7 @@ import http_server = require('http');
|
|||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
|
||||||
import { kill_username, register_username, User } from './user';
|
import { kill_username, register_username, User } from './user';
|
||||||
import { is_command, run_command } from './command';
|
import { is_command, run_command, send_message } from './command';
|
||||||
|
|
||||||
const app = Express();
|
const app = Express();
|
||||||
const http = new http_server.Server(app);
|
const http = new http_server.Server(app);
|
||||||
@ -28,11 +28,10 @@ io.on('connection', socket => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.in(Array.from(socket.rooms)).emit('new message', {
|
send_message({
|
||||||
type: 'text-message',
|
msg: msg,
|
||||||
data: msg,
|
|
||||||
sender: user.name,
|
sender: user.name,
|
||||||
});
|
}, io, socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('set-name', name => {
|
socket.on('set-name', name => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user