diff options
author | Indrajith K L | 2021-03-27 20:13:09 +0530 |
---|---|---|
committer | Indrajith K L | 2021-03-27 20:13:09 +0530 |
commit | 6048206733b3d6bb9ffbacb3e54f4bef88777585 (patch) | |
tree | d99888f20285c37dbf7787016a162f13270ecff7 | |
parent | f4be8d32c80d2b975b8ea59e3488cd1084269856 (diff) | |
download | lul-bot-6048206733b3d6bb9ffbacb3e54f4bef88777585.tar.gz lul-bot-6048206733b3d6bb9ffbacb3e54f4bef88777585.tar.bz2 lul-bot-6048206733b3d6bb9ffbacb3e54f4bef88777585.zip |
Fixes Lookup/Linked data mapping
Adds Airtable Fields Config
-rw-r--r-- | src/main.js | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/main.js b/src/main.js index 5d0f95e..f99bd5a 100644 --- a/src/main.js +++ b/src/main.js @@ -13,6 +13,12 @@ const base = Airtable.base('appppieGLc8loZp5H'); const client = new Client(); const CMD_PREFIX = "!"; const dayToMilliS = 60 * 60 * 24 * 1000; +const AirTableFields = { + WEAPON_TYPE: 'cod_weapon_type', + WEAPON_NAME: 'cod_weapon_name', + MATCH_TYPE: 'cod_match_type', + ATTACHMENTS: 'cod_weapon_attachments' +}; client.on('message', (message) => { if (message.author.bot) return; @@ -85,7 +91,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{}; + case 'loadout': getCodMLoadOut(message, args); return {}; default: return null; } } @@ -158,11 +164,11 @@ async function playMusik(message, args) { if (video) { const youtubeStream = ytdl(video.url, { filter: 'audioonly' }); - client.user.setPresence({activity: {name: `${video.title}`, type: 'LISTENING'}}); + 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: ` `}}); + client.user.setPresence({ activity: { name: ` ` } }); }); await message.reply(`Now Playing ${video.title}...`); } else { @@ -179,7 +185,7 @@ async function stopMusik(message) { await voiceChannel.leave(); await message.channel.send("Stoping Music... Baye Baye.... 😅"); - client.user.setPresence({activity: {name: `COMMANDS`, type: 'LISTENING'}}); + client.user.setPresence({ activity: { name: `COMMANDS`, type: 'LISTENING' } }); } async function searchVideo(query) { @@ -189,32 +195,60 @@ async function searchVideo(query) { async function getCodMLoadOut(message, args) { const codUserName = args[0]; - if(!codUserName) return; + if (!codUserName) return; base('cod_loadout').select({ maxRecords: 2, view: "Grid view", filterByFormula: `({cod_username} = '${args[0]}')` - }).eachPage(function page(records, fetchNextPage) { + }).eachPage((records, fetchNextPage) => { if (records && records.length > 0) { - records.forEach((record) => { + records.forEach(async (record) => { + const weaponType = await getWeaponType(record.get(AirTableFields.WEAPON_TYPE)); + const weaponName = await getWeaponName(record.get(AirTableFields.WEAPON_NAME)); 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"); + .setTitle(`Loadout of ${codUserName} : ${record.get(AirTableFields.MATCH_TYPE)}`) + .addField('Weapon Name', weaponName, true) + .addField('Weapon Type', weaponType, true) + .addField('Attachments', record.get(AirTableFields.ATTACHMENTS), true) + .setColor("RANDOM"); message.channel.send(loadOutMessage); }); fetchNextPage(); } else { message.channel.send(`No Loadout found for ***${codUserName}***`); } - + }, function done(err) { if (err) { console.error(err); return; } }); } +async function getWeaponType(weaponType) { + return new Promise((resolve, reject) => { + base('Weapon Types').find(weaponType, (error, record) => { + if (error) { + console.log(error); + reject(); + } else { + resolve(record.get(AirTableFields.WEAPON_TYPE)); + } + }); + }) +} + +async function getWeaponName(weaponName) { + return new Promise((resolve, reject) => { + base('Weapons').find(weaponName, (error, record) => { + if (error) { + console.log(error); + reject(); + } else { + resolve(record.get(AirTableFields.WEAPON_NAME)); + } + }); + }) +} + client.login(process.env.LUL_BOT_TKN) .then(() => { intervalJokes(); |