diff --git a/server/bot/commands/api.ts b/server/bot/commands/api.ts index 1557752..c139e6b 100644 --- a/server/bot/commands/api.ts +++ b/server/bot/commands/api.ts @@ -85,9 +85,9 @@ export const handleRobohash: Command = { name: 'robohash', aliases: ['robo', 'rh'], opts: { - description: 'Take some text, make it a robot/monster/head/cat.', + description: 'Take some text, make it a robot/monster/head/cat/human.', fullDescription: 'Takes some text and hashes it in the form of an image :P', - usage: '/robohash ', + usage: '/robohash ', example: '/robohash cat voldemort#6931' }, generator: (message, args) => { @@ -112,8 +112,12 @@ export const handleRobohash: Command = { return { embed: { image: { url: `https://robohash.org/${text}.png?set=set4` }, color } } + } else if (target === 'human') { + return { + embed: { image: { url: `https://robohash.org/${text}.png?set=set5` }, color }, content: '🤔' + } } else { - return 'Proper usage: /robohash ' + return 'Proper usage: /robohash ' } } } @@ -362,13 +366,13 @@ type Weather = { cod: string, coord: { lon: number, lat: number }, weather: Arra clouds: { all: number }, rain: { '3h': number }, snow: { '3h': number } } type Categories = Array<{ - lexicalCategory: string, + lexicalCategory: { id: string, text: string }, entries: Array<{ senses: Array<{ definitions: Array, - short_definitions: Array, + shortDefinitions?: Array, examples: Array<{ text: string }>, - registers: Array + registers: Array<{ id: string, text: string }> }> }> }> /* eslint-enable */ @@ -459,15 +463,19 @@ export const handleDefine: Command = { // Search for the word, destructure for results, and then pass them on to our second request. try { const r = await (await fetch( - `https://od-api.oxforddictionaries.com/api/v1/inflections/en/${args.join(' ')}`, { headers } + `https://od-api.oxforddictionaries.com/api/v2/lemmas/en/${args.join(' ')}`, { headers } )).json() + // If the word doesn't exist in the Oxford Dictionary.. + if (r.error === 'No entries were found for a given inflected word') { + return 'Did you enter a valid word? 👾' + } try { // Here we get the dictionary entries for the specified word. const { results } = await (await fetch( - `https://od-api.oxforddictionaries.com/api/v1/entries/en/${r.results[0].id}`, { headers } + `https://od-api.oxforddictionaries.com/api/v2/entries/en/${r.results[0].id}` + + '?strictMatch=false&fields=definitions%2Cexamples', + { headers } )).json() - // Our super filter to remove what we don't need. - const categories: Categories = results[0].lexicalEntries // Now we create an embed based on the 1st entry. const fields: Array<{ name: string, value: string, inline?: boolean }> = [] // Function to check for maximum number of fields in an embed, then push. @@ -475,38 +483,42 @@ export const handleDefine: Command = { if (fields.length < 24) fields.push(object) else if (fields.length === 24) fields.push({ name: '...too many definitions.', value: zeroWidthSpace }) } - categories.forEach( - // The function run on each category. - category => { - // If our field doesn't have the category name, we push the category name to it. - if (!fields.includes({ - name: '**' + category.lexicalCategory + '**', value: zeroWidthSpace - })) { - // We don't push an empty field for the first element, else we do. - if (fields.length !== 0) safePush({ name: zeroWidthSpace, value: zeroWidthSpace }) - safePush({ name: '**' + category.lexicalCategory + '**', value: zeroWidthSpace }) - } - // Here we add every definition and example to the fields. - category.entries.forEach(({ senses }) => { - // Iterate over every definition. - senses.forEach((sense, i) => { - // Check if there is a definition. - if (!sense.short_definitions && !sense.definitions) return - // Then safely push the definition to the array. - const a = i + 1 // Index for the definition. - safePush({ - name: sense.short_definitions - ? (sense.registers ? `**${a}.** (${sense.registers[0]}) ` : `**${a}.** `) + - sense.short_definitions[0] - : (sense.registers ? `**${a}.** (${sense.registers[0]}) ` : `**${a}.** `) + - sense.definitions[0], - value: sense.examples && sense.examples[0].text - ? `e.g. ${sense.examples[0].text}` : 'No example is available.' + for (let i = 0; i < results.length; i++) { + // Our super filter to remove what we don't need. + const categories: Categories = results[i].lexicalEntries + categories.forEach( + // The function run on each category. + category => { + // If our field doesn't have the category name, we push the category name to it. + if (!fields.includes({ + name: '**' + category.lexicalCategory.text + '**', value: zeroWidthSpace + })) { + // We don't push an empty field for the first element, else we do. + if (fields.length !== 0) safePush({ name: zeroWidthSpace, value: zeroWidthSpace }) + safePush({ name: '**' + category.lexicalCategory.text + '**', value: zeroWidthSpace }) + } + // Here we add every definition and example to the fields. + let a = 1 // Index for the definition. + category.entries.forEach(({ senses }) => { + // Iterate over every definition. + senses.forEach((sense) => { + // Check if there is a definition. + if (!sense.shortDefinitions && !sense.definitions) return + // Then safely push the definition to the array. + safePush({ + name: `**${a}.** ` + (sense.registers ? `(${sense.registers[0].text}) ` : '') + ( + (sense.shortDefinitions || sense.definitions)[0] + ), + value: sense.examples && sense.examples[0].text + ? `e.g. ${sense.examples[0].text}` : 'No example is available.' + }) + // Add 1 to the index. + a += 1 }) }) - }) - } - ) + } + ) + } return { content: `📕 **|** Definition of **${args.join(' ')}**:`, embed: { diff --git a/server/bot/commands/utilities.ts b/server/bot/commands/utilities.ts index ff4b0b4..afe5eb9 100644 --- a/server/bot/commands/utilities.ts +++ b/server/bot/commands/utilities.ts @@ -22,11 +22,17 @@ export const handleServerinfo: Command = { generator: async (message, args, { client }) => { // Check if a guild was specified. let guild = args.length ? client.guilds.find( - i => i.members.find(f => f.id === message.author.id) && i.id === args[0] + i => i.members.has(message.author.id) && i.id === args[0] ) : message.member.guild if (!guild) return `Specify a valid mutual guild, ${getInsult()}.` // Owner. const owner = guild.members.get(guild.ownerID) + // Nitro Boosting support. + const boost = guild.premiumTier ? [{ + name: '<:boost:602100826214760452> Boost Status', + value: `Level ${guild.premiumTier} with ${guild.premiumSuscriptionCount} Boosts`, + inline: true + }] : [] // Display information. return { content: `⌨ **Server info on ${guild.name}:**`, @@ -37,6 +43,7 @@ export const handleServerinfo: Command = { footer: { text: `ID: ${guild.id}` }, timestamp: new Date().toISOString(), fields: [ + ...boost, { name: 'Owner', value: `${owner.username}#${owner.discriminator}`, inline: true }, { name: 'Owner ID', value: guild.ownerID, inline: true }, { name: 'Region', value: guild.region, inline: true },