forked from PluralFlux/PluralFlux
renamed stuff to be camel case since apparently I got that convention wrong
This commit is contained in:
30
bot.js
30
bot.js
@@ -27,39 +27,39 @@ const gateway = new WebSocketManager({
|
|||||||
|
|
||||||
export const client = new Client({ rest, gateway });
|
export const client = new Client({ rest, gateway });
|
||||||
|
|
||||||
let plural_flux_name = "";
|
let pluralFluxName = "";
|
||||||
let plural_flux_discriminator = "";
|
let pluralFluxDiscriminator = "";
|
||||||
|
|
||||||
client.on(GatewayDispatchEvents.MessageCreate, async ({ api, data }) => {
|
client.on(GatewayDispatchEvents.MessageCreate, async ({ api, data }) => {
|
||||||
if (data.webhook_id) {
|
if (data.webhook_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (data.author.username === plural_flux_name && data.author.discriminator === plural_flux_discriminator) {
|
else if (data.author.username === pluralFluxName && data.author.discriminator === pluralFluxDiscriminator) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (!data.content.startsWith(messageHelper.prefix)) {
|
else if (!data.content.startsWith(messageHelper.prefix)) {
|
||||||
const proxyMatch = await messageHelper.parse_proxy_tags(data.author.id, data.content);
|
const proxyMatch = await messageHelper.parseProxyTags(data.author.id, data.content);
|
||||||
if (!proxyMatch.proxy) {
|
if (!proxyMatch.proxy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const member = await memberHelper.get_member_by_proxy(data.author.id, proxyMatch.proxy);
|
const member = await memberHelper.getMemberByProxy(data.author.id, proxyMatch.proxy);
|
||||||
await webhookHelper.replace_message(api, data, proxyMatch.message, member);
|
await webhookHelper.replaceMessage(api, data, proxyMatch.message, member);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
const command_name = data.content.slice(messageHelper.prefix.length).split(" ")[0];
|
||||||
const command_name = data.content.slice(messageHelper.prefix.length).split(" ")[0];
|
const args = messageHelper.parseCommandArgs(data.content, command_name);
|
||||||
const args = messageHelper.parse_command_args(data.content, command_name);
|
|
||||||
|
|
||||||
if (command_name === "member" || command_name === "m") {
|
if (command_name === "member" || command_name === "m") {
|
||||||
const reply = await memberHelper.parse_member_command(data.author.id, args);
|
const reply = await memberHelper.parseMemberCommand(data.author.id, args);
|
||||||
await api.channels.createMessage(data.channel_id, {content: reply});
|
await api.channels.createMessage(data.channel_id, {content: reply});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(GatewayDispatchEvents.Ready, async ({data}) => {
|
client.on(GatewayDispatchEvents.Ready, async ({data}) => {
|
||||||
console.log(`Logged in as ${data.user.username}#${data.user.discriminator}`);
|
console.log(`Logged in as ${data.user.username}#${data.user.discriminator}`);
|
||||||
plural_flux_name = data.user.username;
|
pluralFluxName = data.user.username;
|
||||||
plural_flux_discriminator = data.user.discriminator;
|
pluralFluxDiscriminator = data.user.discriminator;
|
||||||
await db.check_connection();
|
await db.check_connection();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const msgh = {};
|
|||||||
|
|
||||||
msgh.prefix = "pf;"
|
msgh.prefix = "pf;"
|
||||||
|
|
||||||
msgh.parse_command_args = function(text, command_name) {
|
msgh.parseCommandArgs = function(text, command_name) {
|
||||||
const message = text.slice(msgh.prefix.length + command_name.length).trim();
|
const message = text.slice(msgh.prefix.length + command_name.length).trim();
|
||||||
// slices up message arguments including retaining quoted strings
|
// slices up message arguments including retaining quoted strings
|
||||||
return message.match(/\\?.|^$/g).reduce((accumulator, chara) => {
|
return message.match(/\\?.|^$/g).reduce((accumulator, chara) => {
|
||||||
@@ -22,8 +22,8 @@ msgh.parse_command_args = function(text, command_name) {
|
|||||||
}, {array: ['']}).array // initial array with empty string for the reducer
|
}, {array: ['']}).array // initial array with empty string for the reducer
|
||||||
}
|
}
|
||||||
|
|
||||||
msgh.parse_proxy_tags = async function (author_id, text){
|
msgh.parseProxyTags = async function (author_id, text){
|
||||||
const members = await memberHelper.get_members_by_author(author_id);
|
const members = await memberHelper.getMembersByAuthor(author_id);
|
||||||
const proxyMessage = {}
|
const proxyMessage = {}
|
||||||
members.forEach(member => {
|
members.forEach(member => {
|
||||||
if (text.startsWith(member.proxy) && text.length > member.proxy.length) {
|
if (text.startsWith(member.proxy) && text.length > member.proxy.length) {
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
const wh = {};
|
const wh = {};
|
||||||
|
|
||||||
wh.get_or_create_webhook = async function (api, channel_id) {
|
wh.getOrCreateWebhook = async function (api, channelId) {
|
||||||
const name = 'PluralFlux Proxy Webhook';
|
const name = 'PluralFlux Proxy Webhook';
|
||||||
let webhook = await get_webhook(api, channel_id, name);
|
let webhook = await getWebhook(api, channelId, name);
|
||||||
if (webhook === undefined) {
|
if (webhook === undefined) {
|
||||||
webhook = await api.channels.createWebhook(channel_id, {name: name});
|
webhook = await api.channels.createWebhook(channelId, {name: name});
|
||||||
}
|
}
|
||||||
return webhook;
|
return webhook;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get_webhook(api, channel_id, name) {
|
async function getWebhook(api, channelId, name) {
|
||||||
const all_webhooks = await api.channels.getWebhooks(channel_id);
|
const allWebhooks = await api.channels.getWebhooks(channelId);
|
||||||
if (all_webhooks.length === 0) {
|
if (allWebhooks.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let pf_webhook;
|
let pf_webhook;
|
||||||
all_webhooks.forEach((webhook) => {
|
allWebhooks.forEach((webhook) => {
|
||||||
if (webhook.name === name) {
|
if (webhook.name === name) {
|
||||||
pf_webhook = webhook;
|
pf_webhook = webhook;
|
||||||
}
|
}
|
||||||
@@ -23,9 +23,9 @@ async function get_webhook(api, channel_id, name) {
|
|||||||
return pf_webhook;
|
return pf_webhook;
|
||||||
}
|
}
|
||||||
|
|
||||||
wh.replace_message = async function (api, data, text, member) {
|
wh.replaceMessage = async function (api, data, text, member) {
|
||||||
if (text.length > 0) {
|
if (text.length > 0) {
|
||||||
const webhook = await wh.get_or_create_webhook(api, data.channel_id);
|
const webhook = await wh.getOrCreateWebhook(api, data.channel_id);
|
||||||
await api.webhooks.execute(webhook.id, webhook.token, {content: text, username: member.displayname ?? member.name, propic: member.propic});
|
await api.webhooks.execute(webhook.id, webhook.token, {content: text, username: member.displayname ?? member.name, propic: member.propic});
|
||||||
await api.channels.deleteMessage(data.channel_id, data.id);
|
await api.channels.deleteMessage(data.channel_id, data.id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user