Emoji only mode WIP:
Fix emojis regexp. The RCPE2 library can't handle long regexp, so we switch to Oniguruma.
This commit is contained in:
parent
1a75b30c50
commit
5db4f46421
@ -10,12 +10,12 @@ set -euo pipefail
|
|||||||
# This script download the Prosody AppImage from the https://github.com/JohnXLivingston/prosody-appimage project.
|
# This script download the Prosody AppImage from the https://github.com/JohnXLivingston/prosody-appimage project.
|
||||||
|
|
||||||
repo_base_url='https://github.com/JohnXLivingston/prosody-appimage/releases/download'
|
repo_base_url='https://github.com/JohnXLivingston/prosody-appimage/releases/download'
|
||||||
wanted_release='v0.12.4-2'
|
wanted_release='v0.12.4-3'
|
||||||
|
|
||||||
x86_64_filename='prosody-x86_64.AppImage'
|
x86_64_filename='prosody-x86_64.AppImage'
|
||||||
x86_64_sha256sum='664d9f3b1ea6dc5fdbe29ef8e8b4c0655abdff697e8c94bfecc894ef2c2fea08'
|
x86_64_sha256sum='83a583ac7036387514bed17afab257dab4161ccdd0ab7453818c78b51f830357'
|
||||||
aarch64_filename='prosody-aarch64.AppImage'
|
aarch64_filename='prosody-aarch64.AppImage'
|
||||||
aarch64_sha256sum='9911c0d581a92a817e9795a7944773a07e85151127233a2e551eb07dc4c44fb5'
|
aarch64_sha256sum='7b7e6bf30d4498fc99a40022232c3065707ee4f4df24dc17947b007621634304'
|
||||||
|
|
||||||
download_dir="$(pwd)/vendor/prosody-appimage"
|
download_dir="$(pwd)/vendor/prosody-appimage"
|
||||||
dist_dir="$(pwd)/dist/server/prosody"
|
dist_dir="$(pwd)/dist/server/prosody"
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
local st = require "util.stanza";
|
local st = require "util.stanza";
|
||||||
local jid_bare = require "util.jid".bare;
|
local jid_bare = require "util.jid".bare;
|
||||||
|
|
||||||
local rex = require "rex_pcre2"; -- We are using PCRE2 (Perl Compatible Regular Expression)
|
local rex = require "rex_onig"; -- We are using Oniguruma because PCRE2 does not handle long regexp.
|
||||||
|
rex.setdefaultsyntax ("PERL");
|
||||||
|
|
||||||
-- Plugin dependencies
|
-- Plugin dependencies
|
||||||
local mod_muc = module:depends "muc";
|
local mod_muc = module:depends "muc";
|
||||||
@ -87,7 +88,7 @@ function handle_groupchat(event)
|
|||||||
if (r == nil) then
|
if (r == nil) then
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
room.x_peertubelivechat_emoji_only_compiled_regexp = rex.new(r, "i");
|
room.x_peertubelivechat_emoji_only_compiled_regexp = rex.new(r, "i", "UTF8");
|
||||||
end
|
end
|
||||||
|
|
||||||
-- only consider messages with body (ie: ignore chatstate and other non-text xmpp messages)
|
-- only consider messages with body (ie: ignore chatstate and other non-text xmpp messages)
|
||||||
|
@ -403,6 +403,7 @@ export class Emojis {
|
|||||||
*/
|
*/
|
||||||
public async getChannelEmojisOnlyRegexp (channelId: number): Promise<string | undefined> {
|
public async getChannelEmojisOnlyRegexp (channelId: number): Promise<string | undefined> {
|
||||||
const parts = [...this.commonEmojisCodes]
|
const parts = [...this.commonEmojisCodes]
|
||||||
|
|
||||||
if (await this.channelHasCustomEmojis(channelId)) {
|
if (await this.channelHasCustomEmojis(channelId)) {
|
||||||
const def = await this.channelCustomEmojisDefinition(channelId)
|
const def = await this.channelCustomEmojisDefinition(channelId)
|
||||||
if (def) {
|
if (def) {
|
||||||
@ -411,19 +412,8 @@ export class Emojis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Note: validShortName should ensure we won't put special chars.
|
// Note: validShortName should ensure we won't put special chars.
|
||||||
// And for the common emojis, we assume that there is no special regexp chars (other that +, which will be escaped).
|
// And for the common emojis, we assume that there is no special regexp chars
|
||||||
const regexp = '^\\s*(?:(?:' + parts.map((s) => s.replace(/[+]/g, '\\$&')).join('|') + ')\\s*)+\\s*$'
|
const regexp = '^\\s*(?:(?:' + parts.join('|') + ')\\s*)+\\s*$'
|
||||||
|
|
||||||
// As a safety net, we check if it is a valid javascript regexp.
|
|
||||||
try {
|
|
||||||
const s = new RegExp(regexp)
|
|
||||||
if (!s) {
|
|
||||||
throw new Error('Can\'t create the RegExp from ' + regexp)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
this.logger.error('Invalid Emoji Only regexp for channel ' + channelId.toString() + ': ' + regexp)
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
return regexp
|
return regexp
|
||||||
}
|
}
|
||||||
@ -489,7 +479,7 @@ async function _getConverseEmojiCodes (options: RegisterServerOptions): Promise<
|
|||||||
if (key === 'custom') { continue } // These are not used.
|
if (key === 'custom') { continue } // These are not used.
|
||||||
r.push(
|
r.push(
|
||||||
...Object.values(block)
|
...Object.values(block)
|
||||||
.map((d: any) => d.cp ? _convert(d.cp) : d.sn)
|
.map((d: any) => d.cp ? _emojiCpToRegexp(d.cp) : d.sn)
|
||||||
.filter((sn: string) => sn && sn !== '')
|
.filter((sn: string) => sn && sn !== '')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -503,38 +493,19 @@ async function _getConverseEmojiCodes (options: RegisterServerOptions): Promise<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts unicode code points and code pairs to their respective characters.
|
* Converts unicode code points and code pairs to the corresponding Regexp class.
|
||||||
* See ConverseJS emoji/utils.js for more info.
|
* See ConverseJS emoji/utils.js for more info.
|
||||||
* @param {string} unicode
|
* @param {string} unicode
|
||||||
*/
|
*/
|
||||||
function _convert (unicode: string): string {
|
function _emojiCpToRegexp (unicode: string): string {
|
||||||
if (unicode.includes('-')) {
|
if (unicode.includes('-')) {
|
||||||
const parts = []
|
const parts = []
|
||||||
const s = unicode.split('-')
|
const s = unicode.split('-')
|
||||||
|
|
||||||
for (let i = 0; i < s.length; i++) {
|
for (let i = 0; i < s.length; i++) {
|
||||||
const part = parseInt(s[i], 16)
|
parts.push('\\x{' + s[i] + '}')
|
||||||
if (part >= 0x10000 && part <= 0x10FFFF) {
|
|
||||||
const hi = Math.floor((part - 0x10000) / 0x400) + 0xD800
|
|
||||||
const lo = ((part - 0x10000) % 0x400) + 0xDC00
|
|
||||||
parts.push(String.fromCharCode(hi) + String.fromCharCode(lo))
|
|
||||||
} else {
|
|
||||||
parts.push(String.fromCharCode(part))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return parts.join('')
|
return parts.join('')
|
||||||
}
|
}
|
||||||
return _fromCodePoint(unicode)
|
return '\\x{' + unicode + '}'
|
||||||
}
|
|
||||||
|
|
||||||
function _fromCodePoint (codepoint: string): string {
|
|
||||||
let code = typeof codepoint === 'string' ? parseInt(codepoint, 16) : codepoint
|
|
||||||
if (code < 0x10000) {
|
|
||||||
return String.fromCharCode(code)
|
|
||||||
}
|
|
||||||
code -= 0x10000
|
|
||||||
return String.fromCharCode(
|
|
||||||
0xD800 + (code >> 10),
|
|
||||||
0xDC00 + (code & 0x3FF)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ async function updateProsodyRoom (
|
|||||||
apiData.removeAffiliationsFor = data.removeAffiliationsFor
|
apiData.removeAffiliationsFor = data.removeAffiliationsFor
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug('Calling update room API on url: ' + apiUrl + ', with data: ' + JSON.stringify(apiData))
|
logger.debug('Calling update room API on url: ' + apiUrl)
|
||||||
const result = await got(apiUrl, {
|
const result = await got(apiUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
Loading…
Reference in New Issue
Block a user