mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-16 17:45:28 +10:00
discord js (#1)
* clear out fluxer.net * basic discord.js bot with ping, and echo * added creation of webhook * simplifying webhook logic * sending messages as webhook * deleting orignal message * adding sequelize file * commented out pgadmin part while it's not working * adding member sort of working * changing names of values * updating names of values and adding new method in memberHelper * renamed messagehelper function * deleted proxyhelper * passed only channel id into webhook helper methods * added new functions and got update working * changed message match to better reducer * adjusted webhook helper to use actual data * refactored bot.js and removed unused methods
This commit is contained in:
37
helpers/messageHelper.js
Normal file
37
helpers/messageHelper.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import {memberHelper} from "./memberHelper.js";
|
||||
|
||||
const msgh = {};
|
||||
|
||||
msgh.prefix = "pf;"
|
||||
|
||||
msgh.parse_command_args = function(text, command_name) {
|
||||
const message = text.slice(msgh.prefix.length + command_name.length).trim();
|
||||
// slices up message arguments including retaining quoted strings
|
||||
return message.match(/\\?.|^$/g).reduce((accumulator, chara) => {
|
||||
if (chara === '"') {
|
||||
// checks whether string is within quotes or not
|
||||
accumulator.quote ^= 1;
|
||||
} else if (!accumulator.quote && chara === ' '){
|
||||
// if not currently in quoted string, push empty string to start word
|
||||
accumulator.array.push('');
|
||||
} else {
|
||||
// accumulates characters to the last string in the array and removes escape characters
|
||||
accumulator.array[accumulator.array.length-1] += chara.replace(/\\(.)/,"$1");
|
||||
}
|
||||
return accumulator;
|
||||
}, {array: ['']}).array // initial array with empty string for the reducer
|
||||
}
|
||||
|
||||
msgh.parse_proxy_tags = async function (author_id, text){
|
||||
const members = await memberHelper.get_members_by_author(author_id);
|
||||
const proxyMessage = {}
|
||||
members.forEach(member => {
|
||||
if (text.startsWith(member.proxy) && text.length > member.proxy.length) {
|
||||
proxyMessage.proxy = member.proxy;
|
||||
proxyMessage.message = text.slice(member.proxy.length).trim();
|
||||
}
|
||||
})
|
||||
return proxyMessage;
|
||||
}
|
||||
|
||||
export const messageHelper = msgh;
|
||||
Reference in New Issue
Block a user