Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Genshin Impact Commands #1347

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/apis/GenshinImpact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { APIWrapper } = require('../')
const axios = require('axios')

const API_URL = 'https://api.genshin.dev'

module.exports = class GenshinImpact extends APIWrapper {
constructor () {
super({
name: 'genshinimpact'
})

this.characters = []
}

load () {
this.request('characters', 'all').then(res => {
this.characters = res.data
})

return this
}

async getCharacter (character) {
return this.characters.find(char =>
char.name.toLowerCase().includes(character.toLowerCase())
)
}

async getCharacterId (character) {
const { data } = await this.request('characters')
return data.find(char =>
character.toLowerCase().includes(char.toLowerCase())
)
}

request (endpoint, query = '') {
return axios.get(encodeURI(`${API_URL}/${endpoint}/${query}`))
}
}
16 changes: 16 additions & 0 deletions src/commands/games/genshinimpact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { SubcommandListCommand } = require('../../')

module.exports = class GenshinImpact extends SubcommandListCommand {
constructor (client) {
super({
name: 'genshinimpact',
aliases: ['genshin'],
category: 'games',
requirements: { apis: ['genshinimpact'] },
authorString: 'commands:genshinimpact.gameName',
authorImage: 'https://i.imgur.com/z6h1q5R.jpg',
authorURL: 'https://genshin.mihoyo.com/en/',
embedColor: '#ffffff'
}, client)
}
}
130 changes: 130 additions & 0 deletions src/commands/games/genshinimpact/character.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
const {
Command,
SwitchbladeEmbed,
PaginatedEmbed,
CommandError,
Constants
} = require('../../../')

const moment = require('moment')

module.exports = class GenshinImpactCharacter extends Command {
constructor (client) {
super(
{
name: 'character',
aliases: ['char', 'c'],
parent: 'genshinimpact',
botPermissions: ['MANAGE_MESSAGES'],
parameters: [
{
type: 'string',
full: true,
missingError:
'commands:genshinimpact.subcommands.character.noCharacter'
}
]
},
client
)
}

async run ({ t, author, channel, language }, character) {
channel.startTyping()
moment.locale(language)

const {
embedColor,
authorString,
authorImage,
authorURL
} = this.parentCommand
try {
const {
name,
vision,
weapon,
birthday,
nation,
affiliation,
rarity,
constellation,
description,
skillTalents,
passiveTalents,
constellations
} = await this.client.apis.genshinimpact.getCharacter(character)
const characterId = await this.client.apis.genshinimpact.getCharacterId(
name
)

const paginatedEmbed = new PaginatedEmbed(t, author)

paginatedEmbed.addPage(
new SwitchbladeEmbed(author)
.setColor(embedColor)
.setAuthor(t(authorString), authorImage, authorURL)
.setTitle(`${name} ${'✦'.repeat(rarity)} | ${vision} • ${weapon}`)
.setDescriptionFromBlockArray([
[description || ''],
[
nation ? `**Nation**: ${nation}` : '',
affiliation ? `**Affiliation**: ${affiliation}` : '',
constellation ? `**Constellation**: ${constellation}` : '',
birthday
? `**Birthday**: ${moment(birthday).format('MMMM Do')}`
: ''
]
])
.setThumbnail(
`https://api.genshin.dev/characters/${characterId}/gacha-splash.png`
)
)

paginatedEmbed.addPage(
new SwitchbladeEmbed(author)
.setColor(embedColor)
.setAuthor(t(authorString), authorImage, authorURL)
.setTitle(`${name} - Skill Talents`)
.setDescriptionFromBlockArray([
skillTalents.map(s => {
return `**${s.name}** (${s.unlock})\n${s.description}\n`
})
])
)

if (passiveTalents) {
paginatedEmbed.addPage(
new SwitchbladeEmbed(author)
.setColor(embedColor)
.setAuthor(t(authorString), authorImage, authorURL)
.setTitle(`${name} - Passive Talents`)
.setDescriptionFromBlockArray([
passiveTalents.map(s => {
return `**${s.name}** (${s.unlock})\n${s.description}\n`
})
])
)
}

if (constellations) {
paginatedEmbed.addPage(
new SwitchbladeEmbed(author)
.setColor(embedColor)
.setAuthor(t(authorString), authorImage, authorURL)
.setTitle(`${name} - Constellations`)
.setDescriptionFromBlockArray([
constellations.map(s => {
return `**${s.name}** (${s.unlock})\n${s.description}\n`
})
])
)
}

paginatedEmbed.run(await channel.send(Constants.EMPTY_SPACE))
channel.stopTyping()
} catch (e) {
throw new CommandError(t('errors:generic'))
}
}
}
11 changes: 11 additions & 0 deletions src/locales/en-US/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,17 @@
"notLive": "I can't change livestreams' positions!",
"positionSet": "Player position set to `{{position}}`."
},
"genshinimpact": {
jaxxibae marked this conversation as resolved.
Show resolved Hide resolved
"commandDescription": "Shows information about Genshin Impact characters, artifacts, events and more.",
"commandUsage": "<type> <query>",
"gameName": "Genshin Impact ©️ miHoYo Co Ltd",
"subcommands": {
"character": {
"commandDescription": "Looks up a Genshin Impact character's information.",
"commandUsage": "<character name>"
}
}
},
"leagueoflegends": {
"commandDescription": "Shows the current issues of a League of Legends server or information about a champion.",
"commandUsage": "<type> <query>",
Expand Down