From d974365f8452cb9633814a199785300cfbc6b0b5 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 26 Jun 2021 17:38:18 -0400 Subject: [PATCH] v1 Code Base --- index.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 5 ++++ package.json | 3 ++- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e69de29..ab9e628 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,66 @@ +/* eslint-disable brace-style */ +// Variable Assignment +const dotenv = require('dotenv'); +const Discord = require('discord.js'); +const client = new Discord.Client(); +const giphy = require('giphy-api')(process.env.giphyAPIKey); +let owner; + +dotenv.config(); + +async function getUser(id) { + const user = await client.users.fetch(id).catch(err,() {}); + return user.data; +} + +client.once('ready', () => { + console.log('Ready'); + owner = getUser(process.env.ownerID); + console.log(owner); +}); + +client.login(process.env.TOKEN); + +client.on('message', message => { + const pre = message.content.slice(0, -4); + const ext = message.content.slice(-4); + + switch (ext) { + case '.gif': + try { + const results = giphy.search(pre, function(err, res) { + if (res.data[0] != undefined) { + message.channel.send(res.data[0].embed_url); + } else { + message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.'); + } + if (err) { + console.log(err); + } + }); + } catch (error) { + console.log(error); + } + break; + // Admin Commands + case '.adm': + if (message.member.id == process.env.ownerID) { + switch (pre) { + case 'kill': + client.destroy(); + process.exit(); + break; + default: + break; + } + } + break; + case '.req': + message.channel.send('Feedback Submitted: ' + pre); + owner.send('Feedback/Request ' + pre); + console.log(owner); + break; + default: + break; + } +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4a579d2..6922b89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -548,6 +548,11 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "giphy-api": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/giphy-api/-/giphy-api-2.0.1.tgz", + "integrity": "sha512-6FKx6y26W1OqPtEOohvr3MOqCcYWajmz/svrjWm6XW2eP9mHvcQoi4aFg5afCakVF2b7zVllP0aNF45CGHZn+A==" + }, "glob": { "version": "7.1.7", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", diff --git a/package.json b/package.json index 90b522c..3f33b23 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "dependencies": { "discord.js": "^12.5.3", - "dotenv": "^10.0.0" + "dotenv": "^10.0.0", + "giphy-api": "^2.0.1" }, "devDependencies": { "eslint": "^7.29.0"