summaryrefslogtreecommitdiff
path: root/handler.js
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-05-06 12:44:50 +0200
committerRaindropsSys <contact@minteck.org>2023-05-06 12:44:50 +0200
commit2e5b62c056e5aafcb6460b1c6e5b7dba6e8e0582 (patch)
treeda0e364ce1c51fdb7f619337159fa3593dfcc5db /handler.js
downloadbutterscotch-2e5b62c056e5aafcb6460b1c6e5b7dba6e8e0582.tar.gz
butterscotch-2e5b62c056e5aafcb6460b1c6e5b7dba6e8e0582.tar.bz2
butterscotch-2e5b62c056e5aafcb6460b1c6e5b7dba6e8e0582.zip
Initial commit
Diffstat (limited to 'handler.js')
-rw-r--r--handler.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/handler.js b/handler.js
new file mode 100644
index 0000000..fa27f9e
--- /dev/null
+++ b/handler.js
@@ -0,0 +1,80 @@
+const fs = require("fs");
+const { AttachmentBuilder } = require('discord.js');
+
+module.exports = (config) => {
+ let command = config['command'];
+ let parameter = config['parameter'];
+ let wrapper = {};
+
+ if (config['source'] === "matrix") {
+ wrapper.send = (message) => {
+ matrixSend(config['room'].roomId, message);
+ }
+
+ wrapper.image = async (buffer, imgConfig, text) => {
+ let upload = await config['client'].uploadContent(buffer);
+
+ config['client'].sendEvent(config['room'].roomId, "m.room.message", {
+ ...{
+ msgtype: "m.image",
+ url: upload.content_uri
+ },
+ ...imgConfig
+ }, "");
+
+ matrixSend(config['room'].roomId, text);
+ }
+
+ wrapper.id = config['room'].roomId;
+ wrapper.sender = config['event'].event.sender;
+ wrapper.platform = "matrix";
+ wrapper.ping = new Date().getTime() - config['event'].event.origin_server_ts;
+ wrapper.nsfw = true;
+ }
+
+ if (config['source'] === "discord") {
+ wrapper.send = (message) => {
+ config['channel'].send({
+ embeds: [
+ {
+ description: message
+ }
+ ]
+ });
+ }
+
+ wrapper.image = async (buffer, imgConfig, text) => {
+ config['channel'].send({
+ embeds: [
+ {
+ description: text,
+ image: {
+ url: "attachment://" + imgConfig.body
+ }
+ }
+ ],
+ files: [new AttachmentBuilder(buffer, {
+ name: imgConfig.body
+ })]
+ });
+ }
+
+ wrapper.id = config['channel'].id;
+ wrapper.sender = config['message'].author.id;
+ wrapper.platform = "discord";
+ wrapper.ping = new Date().getTime() - config['message'].createdTimestamp;
+ wrapper.nsfw = config['channel'].nsfw;
+ }
+
+ if (fs.existsSync("./commands/" + command + ".js")) {
+ require("./commands/" + command + ".js")(parameter, wrapper);
+ } else if (aliases[command]) {
+ require("./commands/" + aliases[command] + ".js")(parameter, wrapper);
+ } else {
+ if (config['source'] === "matrix") {
+ matrixSend(config['room'].roomId, "🚫 `." + command + "` is not a valid command.");
+ } else if (config['source'] === "discord") {
+ config['channel'].send("🚫 `." + command + "` is not a valid command.");
+ }
+ }
+} \ No newline at end of file