Fixes Lookup/Linked data mapping
Adds Airtable Fields Config
This commit is contained in:
58
src/main.js
58
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,20 +195,22 @@ 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();
|
||||
@@ -215,6 +223,32 @@ async function getCodMLoadOut(message, args) {
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user