This will show Server, Users, Upvote and view count as an image the same as the bot.gg stats. There are 2 ways to use this, either !botstats <bot-name> or !botstats sv <bot-name> to see only server and user count. Features error message if the user inputs the bot's name incorrectly
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const jimp = require('jimp');
let event = context.params.event;
let option = context.params.event.content.split(' ')[1];
const kFormatter = (num) => {
return Math.abs(num) > 999
? Math.sign(num) * (Math.abs(num) / 1000).toFixed(1) + 'k'
: Math.sign(num) * Math.abs(num);
};
try {
if (option == 'sv') {
let svbotName = context.params.event.content.split(' ')[2];
console.log(svbotName);
let botgg = await lib.botgg.bots['@0.0.3'].retrieve({
bot_slug: `${svbotName}`,
});
const svid = option;
const svs = {
sv: {
serv: botgg.server_count,
users: botgg.member_count,
},
};
const sv = svs[svid];
const svbanner =
'https://cdn.discordapp.com/attachments/984056876155170886/987378009906479144/ServUsersExample.png';
let serverC = kFormatter(botgg.server_count);
let memberC = kFormatter(botgg.member_count);
let svimg = await jimp.read(svbanner);
svimg.resize(255, 161);
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
svimg.print(
font,
40,
80,
{
text: `${serverC}`,
},
500,
500
);
});
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
svimg.print(
font,
170,
80,
{
text: `${memberC}`,
},
100,
100
);
});
let svbuffer = await svimg.getBufferAsync(jimp.MIME_PNG);
return lib.discord.channels['@0.1.1'].messages.create({
channel_id: event.channel_id,
content: `**${botgg.bot_username}'s Global Server & User count**`,
filename: `${botgg.bot_username}botstats.png`,
file: svbuffer,
});
} else {
let botName = context.params.event.content.split(' ')[1];
let botgg = await lib.botgg.bots['@0.0.3'].retrieve({
bot_slug: `${botName}`,
});
const banner =
'https://cdn.discordapp.com/attachments/984056876155170886/987323259638915132/BotStatsMarker.png';
let serverC = kFormatter(botgg.server_count);
let memberC = kFormatter(botgg.member_count);
let upvoteC = kFormatter(botgg.upvotes_count);
let viewC = kFormatter(botgg.views_count);
let img = await jimp.read(banner);
img.resize(539, 161);
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
img.print(
font,
40,
80,
{
text: `${serverC}`,
},
500,
500
);
});
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
img.print(
font,
170,
80,
{
text: `${memberC}`,
},
100,
100
);
});
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
img.print(
font,
320,
80,
{
text: `${upvoteC}`,
},
100,
100
);
});
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
img.print(
font,
450,
80,
{
text: `${viewC}`,
},
100,
100
);
});
let buffer = await img.getBufferAsync(jimp.MIME_PNG);
return lib.discord.channels['@0.1.1'].messages.create({
channel_id: event.channel_id,
content: `**${botgg.bot_username}'s Global Server & User count | bot.gg Upvotes & views**`,
filename: `${botgg.bot_username}botstats.png`,
file: buffer,
});
}
} catch (e) {
return lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `> **Couldn't find bot name**
- Use lowercase.
- Use the exact bot name.
- When spacing do **\`name-name\`** not **\`name name\`**`,
});
}