Skip to content

Commit

Permalink
Updated dependencies and used new features
Browse files Browse the repository at this point in the history
  • Loading branch information
HighCrit committed May 24, 2021
1 parent 6fe4908 commit 2e9a2dd
Show file tree
Hide file tree
Showing 8 changed files with 4,042 additions and 325 deletions.
4,009 changes: 3,828 additions & 181 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wynntils-bot",
"version": "2.0.0",
"version": "2.1.0",
"description": "Discord bot for the Wynntils Server",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -35,23 +35,23 @@
"homepage": "https://wynntils.com",
"dependencies": {
"bufferutil": "^4.0.3",
"consola": "^2.15.0",
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"consola": "^2.15.3",
"discord.js": "^12.5.3",
"dotenv": "^10.0.0",
"erlpack": "github:discord/erlpack",
"node-fetch": "^2.6.1",
"require-all": "^3.0.0",
"slash-create": "^1.3.0",
"utf-8-validate": "^5.0.4",
"slash-create": "^3.1.0",
"utf-8-validate": "^5.0.5",
"zlib-sync": "^0.1.7"
},
"devDependencies": {
"@types/node": "^14.14.21",
"@types/node-fetch": "^2.5.8",
"@types/require-all": "^3.0.1",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"eslint": "^7.18.0",
"typescript": "^4.1.3"
"@types/node": "^15.6.0",
"@types/node-fetch": "^2.5.10",
"@types/require-all": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@typescript-eslint/parser": "^4.24.0",
"eslint": "^7.27.0",
"typescript": "^4.2.4"
}
}
116 changes: 65 additions & 51 deletions src/commands/ConfigCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,70 +33,84 @@ export class ConfigCommand extends SlashCommand {
}
]
});

this.filePath = __filename;
}

hasPermission(ctx: CommandContext): boolean | string {
const { member } = ctx;
if (!member) {
return 'This command doesn\'t work in DMs';
}
return Staff.some(r => member.roles.includes(r));
}

async run(ctx: CommandContext): Promise<MessageOptions> {
if (Staff.some(r => ctx.member.roles.includes(r))) {
if (ctx.options.filename) {
const configFiles = await configService.get();
if (!configFiles.includes(ctx.options.filename.toString())) {
const embed = new MessageEmbed();
embed.setColor(7531934);
embed.setTitle('Invalid Config Name - Available Configs:');
embed.setDescription(`\`${configFiles.join('`\n`')}\``);
embed.setFooter(client.user?.username, client.user?.avatarURL() ?? client.user?.defaultAvatarURL);
return { embeds: [embed] };
}
const embed = new MessageEmbed();
embed.setFooter(client.user?.username, client.user?.avatarURL() ?? client.user?.defaultAvatarURL);

let response;
let data;

try {
response = await fetch('https://athena.wynntils.com/api/getUserConfig/' + process.env.ATHENA_API_KEY, {
method: 'POST',
body: JSON.stringify({
user: ctx.options.user,
configName: ctx.options.filename
})
});
data = await response.json();
} catch (err) {
consola.error(err);
return { content: 'Something went wrong when fetching the user\'s config', ephemeral: true };
}
if (ctx.options.filename) {
const configFiles = await configService.get();
if (!configFiles.includes(ctx.options.filename.toString())) {
embed.setColor(0xff5349)
.setTitle(':x: Invalid Config Name - Available Configs')
.setDescription(`\`${configFiles.join('`\n`')}\``);
return { embeds: [embed] };
}

if (response.ok) {
const embed = new MessageEmbed();
const configString = JSON.stringify(data.result, null, 2);
const part = ctx.options.part ? Number.parseInt(ctx.options.part.toString()) : 1;
const totalParts = Math.ceil(configString.length / 1800);
let response;
let data;

if (part > totalParts) {
return { content: `This config file does not have more than ${totalParts} parts.`, ephemeral: true };
}
try {
response = await fetch('https://athena.wynntils.com/api/getUserConfig/' + process.env.ATHENA_API_KEY, {
method: 'POST',
body: JSON.stringify({
user: ctx.options.user,
configName: ctx.options.filename
})
});
data = await response.json();
} catch (err) {
consola.error(err);
embed.setColor(0xff5349)
.setTitle(':x: Oops! Error D;')
.setDescription('Something went wrong when fetching the user\'s config.');

embed.setColor(7531934);
embed.setTitle(`${ctx.options.user.toString()} - ${ctx.options.filename} - (${part}/${totalParts})`);
embed.setDescription(`\`\`\`json\n${configString.substr((part - 1) * 1800, 1800)}\n\`\`\``);
return { embeds: [embed], ephemeral: true };
}

if (response.ok) {
const configString = JSON.stringify(data.result, null, 2);
const part = ctx.options.part ? Number.parseInt(ctx.options.part.toString()) : 1;
const totalParts = Math.ceil(configString.length / 1800);

embed.setFooter(client.user?.username, client.user?.avatarURL() ?? client.user?.defaultAvatarURL);
if (part > totalParts) {
embed.setColor(0xff5349)
.setTitle(':octagonal_sign: End of Config')
.setDescription(`This config file does not have more than ${totalParts} parts.`);

return { embeds: [embed] };
} else {
return data.message;
return { embeds: [embed], ephemeral: true };
}
} else {
const configFiles = await configService.get();
const embed = new MessageEmbed()
.setColor(7531934)
.setTitle('Available Configs:')
.setDescription(`\`${configFiles.join('`\n`')}\``)
.setFooter(client.user?.username, client.user?.avatarURL() ?? client.user?.defaultAvatarURL);

embed.setColor(0x72ed9e)
.setTitle(`${ctx.options.user.toString()} - ${ctx.options.filename} - (${part}/${totalParts})`)
.setDescription(`\`\`\`json\n${configString.substr((part - 1) * 1800, 1800)}\n\`\`\``);

return { embeds: [embed] };
}
} else {
return { content: 'This command is for staff members only!', ephemeral: true };

embed.setColor(0xff5349)
.setTitle(':x: Oops! Error D;')
.setDescription( data.message);

return { embeds: [embed], ephemeral: true };
}

const configFiles = await configService.get();
embed.setColor(0x72ed9e)
.setTitle('Available Configs')
.setDescription(`\`${configFiles.join('`\n`')}\``);

return { embeds: [embed] };
}
}
19 changes: 13 additions & 6 deletions src/commands/FaqCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,28 @@ export class FaqCommand extends SlashCommand {
}
]
});

this.filePath = __filename;
}

async run(ctx: CommandContext): Promise<MessageOptions> {
const faq = (await faqService.get()).get(ctx.options.value.toString());

const embed = new MessageEmbed();
embed.setFooter(`By: ${ctx.user.username}#${ctx.user.discriminator} - Please read #faq`);

if (faq) {
const embed = new MessageEmbed();
embed.setColor(7531934);
embed.setAuthor('Wynntils FAQ', client.user?.avatarURL() ?? client.user?.defaultAvatarURL);
embed.addField(faq.title, faq.value);
embed.setFooter(`By: ${ctx.member.user.username}#${ctx.member.user.discriminator} - Please read #faq`);
embed.setColor(0x72ed9e)
.setAuthor('Wynntils FAQ', client.user?.avatarURL() ?? client.user?.defaultAvatarURL)
.addField(faq.title, faq.value);

return { embeds: [embed] };
}

embed.setColor(0xff5349)
.setTitle(':x: Invalid Entry')
.setDescription(`Unable to find entry for ${ctx.options.value.toString()}.`);

return { content: `Unable to find entry for ${ctx.options.value.toString()}`, ephemeral: true };
return { embeds: [embed], ephemeral: true };
}
}
140 changes: 78 additions & 62 deletions src/commands/InfoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,74 +21,90 @@ export class InfoCommand extends SlashCommand {
}
]
});

this.filePath = __filename;
}

hasPermission(ctx: CommandContext): boolean | string {
const { member } = ctx;
if (!member) {
return 'This command doesn\'t work in DMs';
}
return Staff.some(r => member.roles.includes(r));
}

async run(ctx: CommandContext): Promise<MessageOptions> {
if (Staff.some(r => ctx.member.roles.includes(r))) {
let data;
let response;

try {
response = await fetch('https://athena.wynntils.com/api/getUser/' + process.env.ATHENA_API_KEY, {
method: 'POST',
body: JSON.stringify({ user: ctx.options.user.toString() })
});
data = await response.json();
} catch (err) {
consola.error(err);
return { content: 'Something went wrong when fetching the user info', ephemeral: true };
}
const embed = new MessageEmbed();
embed.setFooter(client.user?.username, client.user?.avatarURL() ?? client.user?.defaultAvatarURL);

if (response.ok) {
const userInfo = data.result as UserInfo;
const embed = new MessageEmbed();
let data;
let response;

try {
response = await fetch('https://athena.wynntils.com/api/getUser/' + process.env.ATHENA_API_KEY, {
method: 'POST',
body: JSON.stringify({ user: ctx.options.user.toString() })
});
data = await response.json();
} catch (err) {
consola.error(err);
embed.setColor(0xff5349)
.setTitle(':x: Oops! Error D;')
.setDescription('Something went wrong when fetching the user info.');

embed.setAuthor(userInfo.username, `https://minotar.net/helm/${userInfo.uuid}/100.png`);
embed.setColor(7531934);
embed.addFields(
{
name: 'UUID',
value: userInfo.uuid,
inline: true
},
{
name: 'Account Type',
value: userInfo.accountType,
inline: true
},
{
name: 'Latest Version',
value: userInfo.versions.latest,
inline: true
},
{
name: 'Last Online',
value: (new Date(Math.max(...Object.keys(userInfo.versions.used).map(k => userInfo.versions.used[k])))).toDateString(),
inline: true
},
{
name: 'Cape',
value: !userInfo.cosmetics.isElytra,
inline: true
},
{
name: 'Ears',
value: userInfo.cosmetics.parts.ears,
inline: true
},
{
name: 'Elytra',
value: userInfo.cosmetics.isElytra,
inline: true
}
);
embed.setFooter(client.user?.username, client.user?.avatarURL() ?? client.user?.defaultAvatarURL);
return { embeds: [embed] };
}
return data.message;
} else {
return { content: 'This command is for staff members only', ephemeral: true };
return { embeds: [embed], ephemeral: true };
}

if (response.ok) {
const userInfo = data.result as UserInfo;

embed.setAuthor(userInfo.username, `https://minotar.net/helm/${userInfo.uuid}/100.png`);
embed.setColor(0x72ed9e);
embed.addFields(
{
name: 'UUID',
value: userInfo.uuid,
inline: true
},
{
name: 'Account Type',
value: userInfo.accountType,
inline: true
},
{
name: 'Latest Version',
value: userInfo.versions.latest,
inline: true
},
{
name: 'Last Online',
value: (new Date(Math.max(...Object.keys(userInfo.versions.used).map(k => userInfo.versions.used[k])))).toDateString(),
inline: true
},
{
name: 'Cape',
value: !userInfo.cosmetics.isElytra,
inline: true
},
{
name: 'Ears',
value: userInfo.cosmetics.parts.ears,
inline: true
},
{
name: 'Elytra',
value: userInfo.cosmetics.isElytra,
inline: true
}
);

return { embeds: [embed] };
}

embed.setColor(0xff5349)
.setTitle(':x: Oops! Error D;')
.setDescription(data.message);

return { embeds: [embed], ephemeral: true };
}
}
1 change: 1 addition & 0 deletions src/commands/PingCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class PingCommand extends SlashCommand {
name: 'ping',
description: 'Command to check whether the bot is still operational'
});

this.filePath = __filename;
}

Expand Down
Loading

0 comments on commit 2e9a2dd

Please sign in to comment.