Display Sock Chat protocol errors are dialog boxes.
This commit is contained in:
parent
5b35595fea
commit
4a619312eb
3 changed files with 74 additions and 26 deletions
|
@ -3,6 +3,7 @@
|
|||
#include messages.js
|
||||
#include parsing.js
|
||||
#include users.js
|
||||
#include sockchat/modal.js
|
||||
#include ui/baka.jsx
|
||||
#include ui/emotes.js
|
||||
#include ui/markup.js
|
||||
|
@ -23,6 +24,7 @@ const MamiSockChatHandlers = function(ctx, client, setLoadingOverlay, sockChatRe
|
|||
if(!(pingToggle instanceof Element))
|
||||
throw 'pingToggle must be an instance of Element';
|
||||
|
||||
const modals = new MamiSockChatModals(ctx.settings, ctx.msgbox, ctx.sound);
|
||||
const handlers = {};
|
||||
let dumpEvents = false;
|
||||
|
||||
|
@ -345,6 +347,11 @@ const MamiSockChatHandlers = function(ctx, client, setLoadingOverlay, sockChatRe
|
|||
}
|
||||
|
||||
if(typeof type !== 'string') {
|
||||
if(modals.handled(botInfo.type)) {
|
||||
modals.show(botInfo.type, botInfo.args);
|
||||
return;
|
||||
}
|
||||
|
||||
type = `legacy:${botInfo.type}`;
|
||||
detail = {
|
||||
error: botInfo.isError,
|
||||
|
|
67
src/mami.js/sockchat/modal.js
Normal file
67
src/mami.js/sockchat/modal.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
const MamiSockChatModals = function(settings, msgbox, sound) {
|
||||
const strings = {
|
||||
'crchan': { text: 'Channel %0 has been created.' },
|
||||
'delchan': { text: 'Channel %0 has been deleted.' },
|
||||
'cpwdchan': { text: 'Channel password has been changed.' },
|
||||
'cprivchan': { text: 'Channel access level has been changed.' },
|
||||
'flwarn': { text: 'You are about to hit the flood limit! If you continue you will be kicked.' },
|
||||
'unban': { text: '%0 is no longer banned.', sound: ['unban', 'server'] },
|
||||
|
||||
'generr': { text: 'Something unexpected happened.', error: true },
|
||||
'delerr': { text: 'You are not allowed to delete this message.', error: true },
|
||||
'notban': { text: '%0 is not banned.', error: true },
|
||||
'whoerr': { text: '%0 does not exist.', error: true },
|
||||
'cmdna': { text: 'You are not allowed to use %0.', error: true },
|
||||
'nocmd': { text: 'Command %0 does not exist.', error: true },
|
||||
'cmderr': { text: 'You did not use that command correctly.', error: true },
|
||||
'usernf': { text: '%0 is not logged in right now!', error: true },
|
||||
'kickna': { text: 'You are not allowed to kick %0.', error: true },
|
||||
'samechan': { text: 'You are already in channel %0.', error: true },
|
||||
'ipchan': { text: 'You are not allowed to join channel %0.', error: true },
|
||||
'nochan': { text: 'Channel %0 does not exist.', error: true },
|
||||
'nopwchan': { text: 'Channel %0 requires a password. Use /join %0 <password>', error: true },
|
||||
'ipwchan': { text: 'Wrong password for channel %0.', error: true },
|
||||
'inchan': { text: 'Channel name contains invalid characters.', error: true },
|
||||
'nischan': { text: 'A channel with the name %0 already exists.', error: true },
|
||||
'ndchan': { text: 'You are not allowed to deleted channel %0.', error: true },
|
||||
'namchan': { text: 'You are not allowed to edit channel %0.', error: true },
|
||||
'nameinuse': { text: 'Someone else is already using the name %0.', error: true },
|
||||
'rankerr': { text: 'You cannot set the access level of a channel higher than that of your own.', error: true },
|
||||
};
|
||||
|
||||
const formatTemplate = (template, args) => {
|
||||
if(typeof template !== 'string')
|
||||
template = '';
|
||||
|
||||
if(Array.isArray(args))
|
||||
for(let i = 0; i < args.length; ++i) {
|
||||
const arg = args[i] === undefined || args[i] === null ? '' : args[i].toString();
|
||||
template = template.replace(new RegExp(`%${i}`, 'g'), arg);
|
||||
}
|
||||
|
||||
return template;
|
||||
};
|
||||
|
||||
return {
|
||||
handled: type => type in strings,
|
||||
show: async (type, args) => {
|
||||
if(!(type in strings))
|
||||
throw 'type is not a registered string';
|
||||
|
||||
const info = strings[type];
|
||||
const message = formatTemplate(info.text, args);
|
||||
|
||||
if(settings.get(info.error ? 'soundEnableError' : 'soundEnableServer')) {
|
||||
let soundName;
|
||||
if('sound' in info)
|
||||
soundName = sound.pack.getEventSound(info.sound);
|
||||
if(soundName === undefined)
|
||||
soundName = sound.pack.getEventSound(info.error ? 'error' : 'server');
|
||||
|
||||
sound.library.play(soundName);
|
||||
}
|
||||
|
||||
await msgbox.show({ body: [message] });
|
||||
},
|
||||
};
|
||||
};
|
|
@ -31,12 +31,6 @@ Umi.UI.Messages = (function() {
|
|||
|
||||
const botMsgs = {
|
||||
'say': { text: '%0' },
|
||||
'generr': { text: 'Something unexpected happened.' },
|
||||
'flwarn': { text: 'You are about to hit the flood limit! If you continue you will be kicked.' },
|
||||
'unban': { text: '%0 is no longer banned.', sound: 'unban' },
|
||||
'delerr': { text: 'You are not allowed to delete this message.' },
|
||||
'notban': { text: '%0 is not banned.' },
|
||||
'whoerr': { text: '%0 does not exist.' },
|
||||
'join': { text: '%0 has joined.', action: 'has joined', sound: 'join' },
|
||||
'leave': { text: '%0 has disconnected.', action: 'has disconnected', avatar: 'greyscale', sound: 'leave' },
|
||||
'jchan': { text: '%0 has joined the channel.', action: 'has joined the channel', sound: 'join' },
|
||||
|
@ -45,27 +39,7 @@ Umi.UI.Messages = (function() {
|
|||
'flood': { text: '%0 got kicked for flood protection.', action: 'got kicked for flood protection', avatar: 'invert', sound: 'flood' },
|
||||
'timeout': { text: '%0 exploded.', action: 'exploded', avatar: 'greyscale', sound: 'timeout' },
|
||||
'nick': { text: '%0 changed their name to %1.', action: 'changed their name to %1' },
|
||||
'crchan': { text: 'Channel %0 has been created.' },
|
||||
'delchan': { text: 'Channel %0 has been deleted.' },
|
||||
'cpwdchan': { text: 'Channel password has been changed.' },
|
||||
'cprivchan': { text: 'Channel access level has been changed.' },
|
||||
'ipaddr': { text: 'IP address of %0 is %1.' },
|
||||
'cmdna': { text: 'You are not allowed to use %0.' },
|
||||
'nocmd': { text: 'Command %0 does not exist.' },
|
||||
'cmderr': { text: 'You did not use that command correctly.' },
|
||||
'usernf': { text: '%0 is not logged in right now!' },
|
||||
'kickna': { text: 'You are not allowed to kick %0.' },
|
||||
'samechan': { text: 'You are already in channel %0.' },
|
||||
'ipchan': { text: 'You are not allowed to join channel %0.' },
|
||||
'nochan': { text: 'Channel %0 does not exist.' },
|
||||
'nopwchan': { text: 'Channel %0 requires a password. Use /join %0 <password>' },
|
||||
'ipwchan': { text: 'Wrong password for channel %0.' },
|
||||
'inchan': { text: 'Channel name contains invalid characters.' },
|
||||
'nischan': { text: 'A channel with the name %0 already exists.' },
|
||||
'ndchan': { text: 'You are not allowed to deleted channel %0.' },
|
||||
'namchan': { text: 'You are not allowed to edit channel %0.' },
|
||||
'nameinuse': { text: 'Someone else is already using the name %0.' },
|
||||
'rankerr': { text: 'You cannot set the access level of a channel higher than that of your own.' },
|
||||
'banlist': {
|
||||
text: 'Banned: %0',
|
||||
filter: args => {
|
||||
|
|
Loading…
Reference in a new issue