diff options
author | Indrajith K L | 2021-03-27 17:03:16 +0530 |
---|---|---|
committer | Indrajith K L | 2021-03-27 17:03:16 +0530 |
commit | 6f07b57b89ff39d47279bc2ce451493701314212 (patch) | |
tree | 8c9018ed75582d2508029532867840bbdd0e9f39 | |
parent | 965412619a87969c0e62236049880a39611917bd (diff) | |
download | lul-bot-6f07b57b89ff39d47279bc2ce451493701314212.tar.gz lul-bot-6f07b57b89ff39d47279bc2ce451493701314212.tar.bz2 lul-bot-6f07b57b89ff39d47279bc2ce451493701314212.zip |
Integrates AirTable
Adds New Command Weapons Loadout
-rw-r--r-- | package-lock.json | 22 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/main.js | 34 |
3 files changed, 57 insertions, 0 deletions
diff --git a/package-lock.json b/package-lock.json index 16bdf79..79185b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,6 +73,11 @@ "event-target-shim": "^5.0.0" } }, + "abortcontroller-polyfill": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.1.tgz", + "integrity": "sha512-yml9NiDEH4M4p0G4AcPkg8AAa4mF3nfYF28VQxaokpO67j9H7gWgmsVWJ/f1Rn+PzsnDYvzJzWIQzCqDKRvWlA==" + }, "agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -96,6 +101,18 @@ } } }, + "airtable": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/airtable/-/airtable-0.10.1.tgz", + "integrity": "sha512-obFW+R3ly2mKtCj0D/xto0ggUvYwdM0RJT3VJ9wvgqoxDkzqg2mNtkuTNfYjF6wWQA0GvoHG9guqzgBBqFjItw==", + "requires": { + "@types/node": ">=8.0.0 <15", + "abort-controller": "^3.0.0", + "abortcontroller-polyfill": "^1.4.0", + "lodash": "^4.17.19", + "node-fetch": "^2.6.1" + } + }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -673,6 +690,11 @@ "resolved": "https://registry.npmjs.org/keypress/-/keypress-0.2.1.tgz", "integrity": "sha1-HoBFQlABjbrUw/6USX1uZ7YmnHc=" }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "lodash.assignin": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.assignin/-/lodash.assignin-4.2.0.tgz", diff --git a/package.json b/package.json index 5f7fc8b..923ed0b 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "license": "ISC", "dependencies": { "@discordjs/opus": "^0.4.0", + "airtable": "^0.10.1", "discord.js": "^12.5.1", "dotenv": "^8.2.0", "ffmpeg-static": "^4.2.7", diff --git a/src/main.js b/src/main.js index 3648b2d..f1df54b 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,12 @@ const { Client, MessageEmbed, Collection } = require('discord.js'); const fetch = require('node-fetch'); const ytdl = require('ytdl-core'); const ytSearch = require('yt-search'); +const Airtable = require('airtable'); +Airtable.configure({ + endpointUrl: 'https://api.airtable.com', + apiKey: process.env.AIRTABLE_KEY +}); +const base = Airtable.base('appppieGLc8loZp5H'); const client = new Client(); const CMD_PREFIX = "!"; @@ -79,6 +85,7 @@ function parseCMD(message) { case 'jokes': randomJokes(message); return {}; case 'play': playMusik(message, args); return {}; case 'stop': stopMusik(message); return {}; + case 'loadout': getCodMLoadOut(message, args); return{}; default: return null; } } @@ -151,9 +158,11 @@ async function playMusik(message, args) { if (video) { const youtubeStream = ytdl(video.url, { filter: 'audioonly' }); + client.user.setPresence({activity: {name: `${video.title}`, type: 'LISTENING'}}); connection.play(youtubeStream, { seek: 0, volume: 1 }) .on('finish', () => { voiceChannel.leave(); + client.user.setPresence({activity: {name: ` `}}); }); await message.reply(`Now Playing ${video.title}...`); } else { @@ -170,6 +179,7 @@ async function stopMusik(message) { await voiceChannel.leave(); await message.channel.send("Stoping Music... Baye Baye.... 😅"); + client.user.setPresence({activity: {name: `COMMANDS`, type: 'LISTENING'}}); } async function searchVideo(query) { @@ -177,6 +187,30 @@ async function searchVideo(query) { return (searchResult.videos.length > 1) ? searchResult.videos[0] : null; } +async function getCodMLoadOut(message, args) { + const codUserName = args[0]; + if(!codUserName) return; + base('cod_loadout').select({ + maxRecords: 2, + view: "Grid view", + filterByFormula: `({cod_username} = '${args[0]}')` + }).eachPage(function page(records, fetchNextPage) { + records.forEach((record) => { + const loadOutMessage = new MessageEmbed() + .setTitle(`Loadout of ${codUserName} : ${record.get('cod_match_type')}`) + .addField('Weapon Name', record.get('cod_weapon_name'),true) + .addField('Weapon Type', record.get('cod_weapon_type'),true) + .addField('Attachments', record.get('cod_weapon_attachments'),true) + .setColor("RANDOM"); + message.channel.send(loadOutMessage); + }); + fetchNextPage(); + + }, function done(err) { + if (err) { console.error(err); return; } + }); +} + client.login(process.env.LUL_BOT_TKN) .then(() => { intervalJokes(); |