Use the parseMessageForCommands
hook to also parse MUC commands
Also fix issue where `model.getAllowedCommands()` prevents 3rd party implementations.
This commit is contained in:
parent
003a90c71c
commit
7c51147023
@ -162,11 +162,6 @@ export default class MessageForm extends ElementView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseMessageForCommands (text) {
|
|
||||||
// Wrap util so that we can override in the MUC message-form component
|
|
||||||
return await parseMessageForCommands(this.model, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
async onFormSubmitted (ev) {
|
async onFormSubmitted (ev) {
|
||||||
ev?.preventDefault?.();
|
ev?.preventDefault?.();
|
||||||
|
|
||||||
@ -194,7 +189,7 @@ export default class MessageForm extends ElementView {
|
|||||||
textarea.setAttribute('disabled', 'disabled');
|
textarea.setAttribute('disabled', 'disabled');
|
||||||
this.querySelector('converse-emoji-dropdown')?.hideMenu();
|
this.querySelector('converse-emoji-dropdown')?.hideMenu();
|
||||||
|
|
||||||
const is_command = await this.parseMessageForCommands(message_text);
|
const is_command = await parseMessageForCommands(this.model, message_text);
|
||||||
const message = is_command ? null : await this.model.sendMessage({'body': message_text, spoiler_hint});
|
const message = is_command ? null : await this.model.sendMessage({'body': message_text, spoiler_hint});
|
||||||
if (is_command || message) {
|
if (is_command || message) {
|
||||||
hint_el.value = '';
|
hint_el.value = '';
|
||||||
|
@ -40,6 +40,9 @@ export async function clearMessages (chat) {
|
|||||||
|
|
||||||
|
|
||||||
export async function parseMessageForCommands (chat, text) {
|
export async function parseMessageForCommands (chat, text) {
|
||||||
|
const match = text.replace(/^\s*/, '').match(/^\/(.*)\s*$/);
|
||||||
|
if (match) {
|
||||||
|
let handled = false;
|
||||||
/**
|
/**
|
||||||
* *Hook* which allows plugins to add more commands to a chat's textbox.
|
* *Hook* which allows plugins to add more commands to a chat's textbox.
|
||||||
* Data provided is the chatbox model and the text typed - {model, text}.
|
* Data provided is the chatbox model and the text typed - {model, text}.
|
||||||
@ -54,9 +57,6 @@ export async function parseMessageForCommands (chat, text) {
|
|||||||
* return handled;
|
* return handled;
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
const match = text.replace(/^\s*/, '').match(/^\/(.*)\s*$/);
|
|
||||||
if (match) {
|
|
||||||
let handled = false;
|
|
||||||
handled = await api.hook('parseMessageForCommands', {model: chat, text}, handled);
|
handled = await api.hook('parseMessageForCommands', {model: chat, text}, handled);
|
||||||
if (handled) {
|
if (handled) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,6 +6,12 @@ import { getAutoCompleteListItem, parseMessageForMUCCommands } from './utils.js'
|
|||||||
|
|
||||||
export default class MUCMessageForm extends MessageForm {
|
export default class MUCMessageForm extends MessageForm {
|
||||||
|
|
||||||
|
async connectedCallback () {
|
||||||
|
super.connectedCallback();
|
||||||
|
await this.model.initialized;
|
||||||
|
api.listen.on('parseMessageForCommands', parseMessageForMUCCommands);
|
||||||
|
}
|
||||||
|
|
||||||
toHTML () {
|
toHTML () {
|
||||||
return tpl_muc_message_form(
|
return tpl_muc_message_form(
|
||||||
Object.assign(this.model.toJSON(), {
|
Object.assign(this.model.toJSON(), {
|
||||||
@ -47,13 +53,6 @@ export default class MUCMessageForm extends MessageForm {
|
|||||||
this.mention_auto_complete.on('suggestion-box-selectcomplete', () => (this.auto_completing = false));
|
this.mention_auto_complete.on('suggestion-box-selectcomplete', () => (this.auto_completing = false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @async
|
|
||||||
*/
|
|
||||||
parseMessageForCommands (text) {
|
|
||||||
return parseMessageForMUCCommands(this.model, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
getAutoCompleteList () {
|
getAutoCompleteList () {
|
||||||
return this.model.getAllKnownNicknames().map(nick => ({ 'label': nick, 'value': `@${nick}` }));
|
return this.model.getAllKnownNicknames().map(nick => ({ 'label': nick, 'value': `@${nick}` }));
|
||||||
}
|
}
|
||||||
|
@ -2499,8 +2499,7 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
expect(_converse.connection.send).toHaveBeenCalled();
|
await u.waitUntil(() => Strophe.serialize(sent_stanza) ===
|
||||||
expect(Strophe.serialize(sent_stanza)).toBe(
|
|
||||||
`<iq id="${sent_stanza.getAttribute('id')}" to="lounge@muc.montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${sent_stanza.getAttribute('id')}" to="lounge@muc.montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
||||||
`<item affiliation="member" jid="marc@montague.lit">`+
|
`<item affiliation="member" jid="marc@montague.lit">`+
|
||||||
@ -2593,10 +2592,6 @@ describe("Groupchats", function () {
|
|||||||
it("takes /topic to set the groupchat topic", mock.initConverse([], {}, async function (_converse) {
|
it("takes /topic to set the groupchat topic", mock.initConverse([], {}, async function (_converse) {
|
||||||
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
|
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
|
||||||
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
||||||
let sent_stanza;
|
|
||||||
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
|
||||||
sent_stanza = stanza;
|
|
||||||
});
|
|
||||||
// Check the alias /topic
|
// Check the alias /topic
|
||||||
const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
|
const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
|
||||||
textarea.value = '/topic This is the groupchat subject';
|
textarea.value = '/topic This is the groupchat subject';
|
||||||
@ -2606,8 +2601,8 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
expect(_converse.connection.send).toHaveBeenCalled();
|
const { sent_stanzas } = _converse.connection;
|
||||||
expect(sent_stanza.textContent.trim()).toBe('This is the groupchat subject');
|
await u.waitUntil(() => sent_stanzas.filter(s => s.textContent.trim() === 'This is the groupchat subject'));
|
||||||
|
|
||||||
// Check /subject
|
// Check /subject
|
||||||
textarea.value = '/subject This is a new subject';
|
textarea.value = '/subject This is a new subject';
|
||||||
@ -2617,7 +2612,7 @@ describe("Groupchats", function () {
|
|||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(sent_stanza.textContent.trim()).toBe('This is a new subject');
|
let sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.textContent.trim() === 'This is a new subject').pop());
|
||||||
expect(Strophe.serialize(sent_stanza).toLocaleString()).toBe(
|
expect(Strophe.serialize(sent_stanza).toLocaleString()).toBe(
|
||||||
'<message from="romeo@montague.lit/orchard" to="lounge@montague.lit" type="groupchat" xmlns="jabber:client">'+
|
'<message from="romeo@montague.lit/orchard" to="lounge@montague.lit" type="groupchat" xmlns="jabber:client">'+
|
||||||
'<subject xmlns="jabber:client">This is a new subject</subject>'+
|
'<subject xmlns="jabber:client">This is a new subject</subject>'+
|
||||||
@ -2630,12 +2625,15 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
expect(sent_stanza.textContent.trim()).toBe('This is yet another subject');
|
sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.textContent.trim() === 'This is yet another subject').pop());
|
||||||
expect(Strophe.serialize(sent_stanza).toLocaleString()).toBe(
|
expect(Strophe.serialize(sent_stanza).toLocaleString()).toBe(
|
||||||
'<message from="romeo@montague.lit/orchard" to="lounge@montague.lit" type="groupchat" xmlns="jabber:client">'+
|
'<message from="romeo@montague.lit/orchard" to="lounge@montague.lit" type="groupchat" xmlns="jabber:client">'+
|
||||||
'<subject xmlns="jabber:client">This is yet another subject</subject>'+
|
'<subject xmlns="jabber:client">This is yet another subject</subject>'+
|
||||||
'</message>');
|
'</message>');
|
||||||
|
|
||||||
|
while (sent_stanzas.length) {
|
||||||
|
sent_stanzas.pop();
|
||||||
|
}
|
||||||
// Check unsetting the topic
|
// Check unsetting the topic
|
||||||
textarea.value = '/topic';
|
textarea.value = '/topic';
|
||||||
message_form.onKeyDown({
|
message_form.onKeyDown({
|
||||||
@ -2643,6 +2641,7 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
|
sent_stanza = await u.waitUntil(() => sent_stanzas.pop());
|
||||||
expect(Strophe.serialize(sent_stanza).toLocaleString()).toBe(
|
expect(Strophe.serialize(sent_stanza).toLocaleString()).toBe(
|
||||||
'<message from="romeo@montague.lit/orchard" to="lounge@montague.lit" type="groupchat" xmlns="jabber:client">'+
|
'<message from="romeo@montague.lit/orchard" to="lounge@montague.lit" type="groupchat" xmlns="jabber:client">'+
|
||||||
'<subject xmlns="jabber:client"></subject>'+
|
'<subject xmlns="jabber:client"></subject>'+
|
||||||
@ -2698,7 +2697,7 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count());
|
||||||
const err_msg = await u.waitUntil(() => view.querySelector('.chat-error'));
|
const err_msg = await u.waitUntil(() => view.querySelector('.chat-error'));
|
||||||
expect(err_msg.textContent.trim()).toBe(
|
expect(err_msg.textContent.trim()).toBe(
|
||||||
"Error: the \"owner\" command takes two arguments, the user's nickname and optionally a reason.");
|
"Error: the \"owner\" command takes two arguments, the user's nickname and optionally a reason.");
|
||||||
@ -2725,7 +2724,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/owner annoyingGuy You\'re responsible';
|
textarea.value = '/owner annoyingGuy You\'re responsible';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(3);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 3);
|
||||||
// Check that the member list now gets updated
|
// Check that the member list now gets updated
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
@ -2787,7 +2786,7 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count());
|
||||||
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
||||||
"Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.");
|
"Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.");
|
||||||
|
|
||||||
@ -2802,7 +2801,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/ban annoyingGuy You\'re annoying';
|
textarea.value = '/ban annoyingGuy You\'re annoying';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(2);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 2);
|
||||||
// Check that the member list now gets updated
|
// Check that the member list now gets updated
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
@ -2886,7 +2885,7 @@ describe("Groupchats", function () {
|
|||||||
preventDefault: function preventDefault () {},
|
preventDefault: function preventDefault () {},
|
||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count());
|
||||||
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
||||||
"Error: the \"kick\" command takes two arguments, the user's nickname and optionally a reason.");
|
"Error: the \"kick\" command takes two arguments, the user's nickname and optionally a reason.");
|
||||||
expect(view.model.setRole).not.toHaveBeenCalled();
|
expect(view.model.setRole).not.toHaveBeenCalled();
|
||||||
@ -2897,7 +2896,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/kick @annoying guy You\'re annoying';
|
textarea.value = '/kick @annoying guy You\'re annoying';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(2);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 2);
|
||||||
expect(view.model.setRole).toHaveBeenCalled();
|
expect(view.model.setRole).toHaveBeenCalled();
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
@ -2988,7 +2987,7 @@ describe("Groupchats", function () {
|
|||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count());
|
||||||
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
||||||
"Error: the \"op\" command takes two arguments, the user's nickname and optionally a reason.");
|
"Error: the \"op\" command takes two arguments, the user's nickname and optionally a reason.");
|
||||||
|
|
||||||
@ -3000,7 +2999,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/op trustworthyguy You\'re trustworthy';
|
textarea.value = '/op trustworthyguy You\'re trustworthy';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(2);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 2);
|
||||||
expect(view.model.setRole).toHaveBeenCalled();
|
expect(view.model.setRole).toHaveBeenCalled();
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
@ -3044,7 +3043,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/deop trustworthyguy Perhaps not';
|
textarea.value = '/deop trustworthyguy Perhaps not';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(3);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 3);
|
||||||
expect(view.model.setRole).toHaveBeenCalled();
|
expect(view.model.setRole).toHaveBeenCalled();
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
@ -3127,7 +3126,7 @@ describe("Groupchats", function () {
|
|||||||
keyCode: 13
|
keyCode: 13
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs).toHaveBeenCalled();
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count());
|
||||||
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
await u.waitUntil(() => view.querySelector('.message:last-child')?.textContent?.trim() ===
|
||||||
"Error: the \"mute\" command takes two arguments, the user's nickname and optionally a reason.");
|
"Error: the \"mute\" command takes two arguments, the user's nickname and optionally a reason.");
|
||||||
expect(view.model.setRole).not.toHaveBeenCalled();
|
expect(view.model.setRole).not.toHaveBeenCalled();
|
||||||
@ -3138,7 +3137,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/mute annoyingGuy You\'re annoying';
|
textarea.value = '/mute annoyingGuy You\'re annoying';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(2);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 2)
|
||||||
expect(view.model.setRole).toHaveBeenCalled();
|
expect(view.model.setRole).toHaveBeenCalled();
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
@ -3179,7 +3178,7 @@ describe("Groupchats", function () {
|
|||||||
textarea.value = '/voice annoyingGuy Now you can talk again';
|
textarea.value = '/voice annoyingGuy Now you can talk again';
|
||||||
message_form.onFormSubmitted(new Event('submit'));
|
message_form.onFormSubmitted(new Event('submit'));
|
||||||
|
|
||||||
expect(view.model.validateRoleOrAffiliationChangeArgs.calls.count()).toBe(3);
|
await u.waitUntil(() => view.model.validateRoleOrAffiliationChangeArgs.calls.count() === 3);
|
||||||
expect(view.model.setRole).toHaveBeenCalled();
|
expect(view.model.setRole).toHaveBeenCalled();
|
||||||
expect(Strophe.serialize(sent_IQ)).toBe(
|
expect(Strophe.serialize(sent_IQ)).toBe(
|
||||||
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
`<iq id="${IQ_id}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
|
||||||
|
@ -298,117 +298,102 @@ export function showOccupantModal (ev, occupant) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function parseMessageForMUCCommands (muc, text) {
|
export function parseMessageForMUCCommands (data, handled) {
|
||||||
if (
|
if (handled || (
|
||||||
api.settings.get('muc_disable_slash_commands') &&
|
api.settings.get('muc_disable_slash_commands') &&
|
||||||
!Array.isArray(api.settings.get('muc_disable_slash_commands'))
|
!Array.isArray(api.settings.get('muc_disable_slash_commands'))
|
||||||
) {
|
)) {
|
||||||
return parseMessageForCommands(muc, text);
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let text = data.text;
|
||||||
text = text.replace(/^\s*/, '');
|
text = text.replace(/^\s*/, '');
|
||||||
const command = (text.match(/^\/([a-zA-Z]*) ?/) || ['']).pop().toLowerCase();
|
const command = (text.match(/^\/([a-zA-Z]*) ?/) || ['']).pop().toLowerCase();
|
||||||
if (!command) {
|
if (!command) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const model = data.model;
|
||||||
const args = text.slice(('/' + command).length + 1).trim();
|
const args = text.slice(('/' + command).length + 1).trim();
|
||||||
if (!muc.getAllowedCommands().includes(command)) {
|
const allowed_commands = model.getAllowedCommands() ?? [];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (command) {
|
if (command === 'admin' && allowed_commands.includes(command)) {
|
||||||
case 'admin': {
|
verifyAndSetAffiliation(model, command, args, ['owner']);
|
||||||
verifyAndSetAffiliation(muc, command, args, ['owner']);
|
return true;
|
||||||
break;
|
} else if (command === 'ban' && allowed_commands.includes(command)) {
|
||||||
}
|
verifyAndSetAffiliation(model, command, args, ['admin', 'owner']);
|
||||||
case 'ban': {
|
return true;
|
||||||
verifyAndSetAffiliation(muc, command, args, ['admin', 'owner']);
|
} else if (command === 'modtools' && allowed_commands.includes(command)) {
|
||||||
break;
|
showModeratorToolsModal(model, args);
|
||||||
}
|
return true;
|
||||||
case 'modtools': {
|
} else if (command === 'deop' && allowed_commands.includes(command)) {
|
||||||
showModeratorToolsModal(muc, args);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'deop': {
|
|
||||||
// FIXME: /deop only applies to setting a moderators
|
// FIXME: /deop only applies to setting a moderators
|
||||||
// role to "participant" (which only admin/owner can
|
// role to "participant" (which only admin/owner can
|
||||||
// do). Moderators can however set non-moderator's role
|
// do). Moderators can however set non-moderator's role
|
||||||
// to participant (e.g. visitor => participant).
|
// to participant (e.g. visitor => participant).
|
||||||
// Currently we don't distinguish between these two
|
// Currently we don't distinguish between these two
|
||||||
// cases.
|
// cases.
|
||||||
setRole(muc, command, args, ['admin', 'owner']);
|
setRole(model, command, args, ['admin', 'owner']);
|
||||||
break;
|
return true;
|
||||||
|
} else if (command === 'destroy' && allowed_commands.includes(command)) {
|
||||||
|
if (!model.verifyAffiliations(['owner'])) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
case 'destroy': {
|
destroyMUC(model).catch(e => model.onCommandError(e));
|
||||||
if (!muc.verifyAffiliations(['owner'])) {
|
return true;
|
||||||
break;
|
} else if (command === 'help' && allowed_commands.includes(command)) {
|
||||||
}
|
model.set({ 'show_help_messages': false }, { 'silent': true });
|
||||||
destroyMUC(muc).catch(e => muc.onCommandError(e));
|
model.set({ 'show_help_messages': true });
|
||||||
break;
|
return true;
|
||||||
}
|
} else if (command === 'kick' && allowed_commands.includes(command)) {
|
||||||
case 'help': {
|
setRole(model, command, args, [], ['moderator']);
|
||||||
muc.set({ 'show_help_messages': false }, { 'silent': true });
|
return true;
|
||||||
muc.set({ 'show_help_messages': true });
|
} else if (command === 'mute' && allowed_commands.includes(command)) {
|
||||||
break;
|
setRole(model, command, args, [], ['moderator']);
|
||||||
}
|
return true;
|
||||||
case 'kick': {
|
} else if (command === 'member' && allowed_commands.includes(command)) {
|
||||||
setRole(muc, command, args, [], ['moderator']);
|
verifyAndSetAffiliation(model, command, args, ['admin', 'owner']);
|
||||||
break;
|
return true;
|
||||||
}
|
} else if (command === 'nick' && allowed_commands.includes(command)) {
|
||||||
case 'mute': {
|
if (!model.verifyRoles(['visitor', 'participant', 'moderator'])) {
|
||||||
setRole(muc, command, args, [], ['moderator']);
|
return true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'member': {
|
|
||||||
verifyAndSetAffiliation(muc, command, args, ['admin', 'owner']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'nick': {
|
|
||||||
if (!muc.verifyRoles(['visitor', 'participant', 'moderator'])) {
|
|
||||||
break;
|
|
||||||
} else if (args.length === 0) {
|
} else if (args.length === 0) {
|
||||||
// e.g. Your nickname is "coolguy69"
|
// e.g. Your nickname is "coolguy69"
|
||||||
const message = __('Your nickname is "%1$s"', muc.get('nick'));
|
const message = __('Your nickname is "%1$s"', model.get('nick'));
|
||||||
muc.createMessage({ message, 'type': 'error' });
|
model.createMessage({ message, 'type': 'error' });
|
||||||
} else {
|
} else {
|
||||||
muc.setNickname(args);
|
model.setNickname(args);
|
||||||
}
|
}
|
||||||
break;
|
return true;
|
||||||
}
|
} else if (command === 'owner' && allowed_commands.includes(command)) {
|
||||||
case 'owner':
|
verifyAndSetAffiliation(model, command, args, ['owner']);
|
||||||
verifyAndSetAffiliation(muc, command, args, ['owner']);
|
return true;
|
||||||
break;
|
} else if (command === 'op' && allowed_commands.includes(command)) {
|
||||||
case 'op': {
|
setRole(model, command, args, ['admin', 'owner']);
|
||||||
setRole(muc, command, args, ['admin', 'owner']);
|
return true;
|
||||||
break;
|
} else if (command === 'register' && allowed_commands.includes(command)) {
|
||||||
}
|
|
||||||
case 'register': {
|
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
muc.createMessage({
|
model.createMessage({
|
||||||
'message': __('Error: invalid number of arguments'),
|
'message': __('Error: invalid number of arguments'),
|
||||||
'type': 'error'
|
'type': 'error'
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
muc.registerNickname().then(err_msg => {
|
model.registerNickname().then(err_msg => {
|
||||||
err_msg && muc.createMessage({ 'message': err_msg, 'type': 'error' });
|
err_msg && model.createMessage({ 'message': err_msg, 'type': 'error' });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'revoke': {
|
|
||||||
verifyAndSetAffiliation(muc, command, args, ['admin', 'owner']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'topic':
|
|
||||||
case 'subject':
|
|
||||||
muc.setSubject(args);
|
|
||||||
break;
|
|
||||||
case 'voice': {
|
|
||||||
setRole(muc, command, args, [], ['moderator']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return parseMessageForCommands(muc, text);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
} else if (command === 'revoke' && allowed_commands.includes(command)) {
|
||||||
|
verifyAndSetAffiliation(model, command, args, ['admin', 'owner']);
|
||||||
|
return true;
|
||||||
|
} else if (command === 'topic' && allowed_commands.includes(command) ||
|
||||||
|
command === 'subject' && allowed_commands.includes(command)) {
|
||||||
|
model.setSubject(args);
|
||||||
|
return true;
|
||||||
|
} else if (command === 'voice' && allowed_commands.includes(command)) {
|
||||||
|
setRole(model, command, args, [], ['moderator']);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user