2024-01-18 19:50:37 +00:00
|
|
|
#include server.js
|
|
|
|
|
2024-01-22 13:12:14 +00:00
|
|
|
const MamiCompat = (current, path, handler) => {
|
|
|
|
if(typeof path !== 'string')
|
|
|
|
throw 'path must be a string';
|
|
|
|
if(typeof handler !== 'function')
|
|
|
|
throw 'handler must be a function';
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-01-22 13:12:14 +00:00
|
|
|
path = path.split('.');
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-01-22 13:12:14 +00:00
|
|
|
const final = path.pop();
|
|
|
|
if(final === undefined)
|
|
|
|
throw 'invalid path';
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-01-22 13:12:14 +00:00
|
|
|
for(const part of path) {
|
|
|
|
if(!(part in current))
|
|
|
|
current[part] = {};
|
|
|
|
current = current[part];
|
|
|
|
}
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-01-22 13:12:14 +00:00
|
|
|
if(!(final in current))
|
|
|
|
current[final] = handler;
|
|
|
|
};
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-01-22 13:12:14 +00:00
|
|
|
// Backwards compat for scripts
|
|
|
|
// Keep in sync with <https://fii.moe/fp/13176> for as long as possible
|
|
|
|
MamiCompat(Umi, 'Server.SendMessage', Umi.Server.sendMessage.bind(Umi.Server));
|
|
|
|
MamiCompat(Umi, 'Protocol.SockLegacy.Protocol.Instance.SendMessage', Umi.Server.sendMessage.bind(Umi.Server));
|
|
|
|
MamiCompat(Umi, 'Parser.SockChatBBcode.EmbedStub', function() {}); // intentionally a no-op
|
|
|
|
MamiCompat(Umi, 'UI.View.SetText', function() { console.log('Umi.UI.View.SetText called'); });
|
|
|
|
MamiCompat(Umi, 'UI.Menus.Add', function() { console.log('Umi.UI.Menus.Add called'); });
|
|
|
|
MamiCompat(Umi, 'UI.Menus.Get', function() { console.log('Umi.UI.Menus.Get called'); });
|