From 4c8d717e9ab2ef0eaaf17b995e4de35a2265f496 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Thu, 11 Apr 2024 23:41:24 +0200 Subject: [PATCH] add ingest --- commands/interaction/slash/utils/emoji.js | 7 +++++++ commands/message/utils/emoji.js | 8 +++++++- labscore/client.js | 7 ++++++- labscore/logging.js | 10 ++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/commands/interaction/slash/utils/emoji.js b/commands/interaction/slash/utils/emoji.js index 2c48524..8e52553 100644 --- a/commands/interaction/slash/utils/emoji.js +++ b/commands/interaction/slash/utils/emoji.js @@ -8,6 +8,7 @@ const { icon, pill, iconPill, highlight, timestamp } = require("../../../../labs const { editOrReply } = require("../../../../labscore/utils/message"); const { STATICS } = require("../../../../labscore/utils/statics"); const { Components, Snowflake } = require("detritus-client/lib/utils"); +const { ingest } = require("../../../../labscore/logging"); const onlyEmoji = require('emoji-aware').onlyEmoji; @@ -34,6 +35,9 @@ function toCodePoint(unicodeSurrogates, sep) { module.exports = { name: 'emoji', description: 'Turn emoji into images. Supports both built-in and custom emoji.', + metadata: { + use_custom_ingest: true + }, contexts: [ 0, 1, @@ -59,6 +63,7 @@ module.exports = { ); embeds = [] if (matches.length) { + ingest("emoji_enlarge", "slash_command_ran"); let form = '.png' if(matches[0].animated) form = '.gif' @@ -83,6 +88,7 @@ module.exports = { // Emoji Mixing if(emoji.length >= 2){ + ingest("emoji_emojikitchen", "slash_command_ran"); try{ let em = await emojiKitchen(emoji) if(!em.body.results[0]){ @@ -105,6 +111,7 @@ module.exports = { } // Regular Emoji Handling + ingest("emoji_enlarge", "slash_command_ran"); if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge.")) let res; diff --git a/commands/message/utils/emoji.js b/commands/message/utils/emoji.js index 34c07f3..acc6ca6 100644 --- a/commands/message/utils/emoji.js +++ b/commands/message/utils/emoji.js @@ -9,6 +9,7 @@ const { editOrReply } = require("../../../labscore/utils/message"); const { STATICS } = require("../../../labscore/utils/statics"); const { Components, Snowflake } = require("detritus-client/lib/utils"); const { bold } = require("detritus-client/lib/utils/markup"); +const { ingest } = require("../../../labscore/logging"); const onlyEmoji = require('emoji-aware').onlyEmoji; @@ -41,7 +42,8 @@ module.exports = { description_short: 'Get emoji/sticker source images, mix two emoji together.', examples: ['e 😀', 'emojimix 🐱 🍞'], category: 'utils', - usage: 'emoji []' + usage: 'emoji []', + use_custom_ingest: true }, args: [ {name: 'type', default: 'twitter', type: 'string', help: `Emoji platform type`} @@ -57,6 +59,7 @@ module.exports = { // Stickers if(msg.stickerItems.length){ + ingest("emoji_sticker", "command_ran"); let s = msg.stickerItems.first() if(s.formatType == 3) return editOrReply(context, createEmbed("default", context, { description: `${iconPill("sticker", s.name)} ${highlight(`(${s.id})`)}\nhttps://cdn.discordapp.com/stickers/${s.id}.json`, @@ -76,6 +79,7 @@ module.exports = { ); embeds = [] if (matches.length) { + ingest("emoji_enlarge", "command_ran"); let form = '.png' if(matches[0].animated) form = '.gif' @@ -102,6 +106,7 @@ module.exports = { // Emoji Mixing if(emoji.length >= 2){ try{ + ingest("emoji_emojikitchen", "command_ran"); let em = await emojiKitchen(emoji) if(!em.body.results[0]){ for(const em of emoji){ @@ -120,6 +125,7 @@ module.exports = { } } + ingest("emoji_enlarge", "command_ran"); // Regular Emoji Handling if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge.")) diff --git a/labscore/client.js b/labscore/client.js index 975eaa6..c7c7a7b 100644 --- a/labscore/client.js +++ b/labscore/client.js @@ -57,11 +57,16 @@ const interactionClient = new InteractionCommandClient(cluster, { useClusterClient: true }) -const { maintower, basecamp } = require('./logging'); +const { maintower, basecamp, ingest } = require('./logging'); const { icon, highlight } = require('./utils/markdown'); const { editOrReply } = require('./utils/message'); const { createEmbed } = require('./utils/embed'); +const superagent = require('superagent'); + +// Analytics +commandClient.on('commandRan', ({ context, command }) => { if(!command.metadata.use_custom_ingest) ingest(command.name, "slash_command_ran")} ) +interactionClient.on('commandRan', ({ context, command }) => { if(!command.metadata.use_custom_ingest) ingest(command.name, "slash_command_ran")} ) // Handle missing permission errors commandClient.on('commandPermissionsFailClient', ({context, permissions}) => { diff --git a/labscore/logging.js b/labscore/logging.js index 1d5cdaf..4eeffcb 100644 --- a/labscore/logging.js +++ b/labscore/logging.js @@ -38,4 +38,14 @@ module.exports.basecamp = async function (log, content = ""){ console.log(e) throw "Basecamp request failed." } +} + +module.exports.ingest = async function (event, type = "generic"){ + try{ + let r = await superagent.get(`${process.env.INGEST_SERVICE_HOST}/d/${type}/${event}`) + .set("x-ingest-client", process.env.INGEST_SERVICE_CLIENT) + }catch(e){ + console.log(e) + console.log("ingest failed") + } } \ No newline at end of file