Fixes Lookup/Linked data mapping
Adds Airtable Fields Config
This commit is contained in:
56
src/main.js
56
src/main.js
@@ -13,6 +13,12 @@ const base = Airtable.base('appppieGLc8loZp5H');
|
|||||||
const client = new Client();
|
const client = new Client();
|
||||||
const CMD_PREFIX = "!";
|
const CMD_PREFIX = "!";
|
||||||
const dayToMilliS = 60 * 60 * 24 * 1000;
|
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) => {
|
client.on('message', (message) => {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
@@ -85,7 +91,7 @@ function parseCMD(message) {
|
|||||||
case 'jokes': randomJokes(message); return {};
|
case 'jokes': randomJokes(message); return {};
|
||||||
case 'play': playMusik(message, args); return {};
|
case 'play': playMusik(message, args); return {};
|
||||||
case 'stop': stopMusik(message); return {};
|
case 'stop': stopMusik(message); return {};
|
||||||
case 'loadout': getCodMLoadOut(message, args); return{};
|
case 'loadout': getCodMLoadOut(message, args); return {};
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,11 +164,11 @@ async function playMusik(message, args) {
|
|||||||
|
|
||||||
if (video) {
|
if (video) {
|
||||||
const youtubeStream = ytdl(video.url, { filter: 'audioonly' });
|
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 })
|
connection.play(youtubeStream, { seek: 0, volume: 1 })
|
||||||
.on('finish', () => {
|
.on('finish', () => {
|
||||||
voiceChannel.leave();
|
voiceChannel.leave();
|
||||||
client.user.setPresence({activity: {name: ` `}});
|
client.user.setPresence({ activity: { name: ` ` } });
|
||||||
});
|
});
|
||||||
await message.reply(`Now Playing ${video.title}...`);
|
await message.reply(`Now Playing ${video.title}...`);
|
||||||
} else {
|
} else {
|
||||||
@@ -179,7 +185,7 @@ async function stopMusik(message) {
|
|||||||
|
|
||||||
await voiceChannel.leave();
|
await voiceChannel.leave();
|
||||||
await message.channel.send("Stoping Music... Baye Baye.... 😅");
|
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) {
|
async function searchVideo(query) {
|
||||||
@@ -189,19 +195,21 @@ async function searchVideo(query) {
|
|||||||
|
|
||||||
async function getCodMLoadOut(message, args) {
|
async function getCodMLoadOut(message, args) {
|
||||||
const codUserName = args[0];
|
const codUserName = args[0];
|
||||||
if(!codUserName) return;
|
if (!codUserName) return;
|
||||||
base('cod_loadout').select({
|
base('cod_loadout').select({
|
||||||
maxRecords: 2,
|
maxRecords: 2,
|
||||||
view: "Grid view",
|
view: "Grid view",
|
||||||
filterByFormula: `({cod_username} = '${args[0]}')`
|
filterByFormula: `({cod_username} = '${args[0]}')`
|
||||||
}).eachPage(function page(records, fetchNextPage) {
|
}).eachPage((records, fetchNextPage) => {
|
||||||
if (records && records.length > 0) {
|
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()
|
const loadOutMessage = new MessageEmbed()
|
||||||
.setTitle(`Loadout of ${codUserName} : ${record.get('cod_match_type')}`)
|
.setTitle(`Loadout of ${codUserName} : ${record.get(AirTableFields.MATCH_TYPE)}`)
|
||||||
.addField('Weapon Name', record.get('cod_weapon_name'),true)
|
.addField('Weapon Name', weaponName, true)
|
||||||
.addField('Weapon Type', record.get('cod_weapon_type'),true)
|
.addField('Weapon Type', weaponType, true)
|
||||||
.addField('Attachments', record.get('cod_weapon_attachments'),true)
|
.addField('Attachments', record.get(AirTableFields.ATTACHMENTS), true)
|
||||||
.setColor("RANDOM");
|
.setColor("RANDOM");
|
||||||
message.channel.send(loadOutMessage);
|
message.channel.send(loadOutMessage);
|
||||||
});
|
});
|
||||||
@@ -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)
|
client.login(process.env.LUL_BOT_TKN)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
intervalJokes();
|
intervalJokes();
|
||||||
|
|||||||
Reference in New Issue
Block a user