Merge branch 'develop' into 'master'

Develop

Closes #4

See merge request knotteye/satyr!10
merge-requests/11/merge
knotteye 2020-07-04 08:16:29 +00:00
commit 94bcecfd0a
2 changed files with 43 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "satyr", "name": "satyr",
"version": "0.7.0", "version": "0.7.1",
"description": "A livestreaming server.", "description": "A livestreaming server.",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"author": "knotteye", "author": "knotteye",

View File

@ -18,11 +18,11 @@ async function init() {
if(config['chat']['discord']['enabled']){ if(config['chat']['discord']['enabled']){
discordClient = new discord.Client(); discordClient = new discord.Client();
discordClient.once('ready', ()=>{ console.log('Discord bot ready')}); discordClient.once('ready', ()=>{ console.log('Discord bot ready')});
discordClient.on('message', (msg) => { discordClient.on('message', async (msg) => {
if(msg['author']['bot']) return; if(msg['author']['bot']) return;
var lu = getUsr(msg['channel']['name'], 'discord') var lu = getUsr(msg['channel']['name'], 'discord')
for(var i=0;i<lu.length;i++){ for(var i=0;i<lu.length;i++){
sendAll(lu[i], [msg['author']['username'], msg['content']], "discord") sendAll(lu[i], [msg['author']['username'], await normalizeDiscordMsg(msg)], "discord");
} }
}); });
discordClient.login(config['chat']['discord']['token']); discordClient.login(config['chat']['discord']['token']);
@ -184,4 +184,44 @@ async function updateTwitchChan() {
} }
} }
async function normalizeDiscordMsg(msg): Promise<string>{
var nmsg: string=msg['content'];
//normalize user mentions
var uarray = await msg['mentions']['users'].array();
var karray = await msg['mentions']['users'].keyArray();
for(var i=0;i<karray.length;i++){
var usr = uarray[i];
nmsg = nmsg.replace(new RegExp('<@!'+karray[i]+'>', 'g'), '@'+usr['username']);
}
//normalize emoji
var e = nmsg.match(new RegExp('<:\\w+:[0-9]+>', 'g'));
//<:.+:.+>
if(e !== null)
for (var i=0;i<e.length;i++){
nmsg = nmsg.replace(e[i], e[i].match(new RegExp(':\\w+:', 'g'))[0]);
}
//in 10 minutes, I will have forgot what all of this regex does.
//normalize role mentions
var uarray = await msg['mentions']['roles'].array();
var karray = await msg['mentions']['roles'].keyArray();
for(var i=0;i<karray.length;i++){
var role = uarray[i];
nmsg = nmsg.replace(new RegExp('<@&'+karray[i]+'>', 'g'), '@'+role['name']);
}
//normalize channel mentions
var c = nmsg.match(new RegExp('<#[0-9]+>', 'g'));
if(c !== null)
for(var i=0;i<c.length;i++){
nmsg = nmsg.replace(c[i], '#'+discordClient.channels.get(c[i].match(new RegExp('[0-9]+', 'g'))[0])['name']);
}
//fuck me this better work
return nmsg;
}
export { init, sendAll }; export { init, sendAll };