Mayuri Bot
Description:
Mayuri is a Discord bot that was created to manage messages, attachments, and voice channels. Over time, it gained features such as playing music in voice channels, retrieving data about the game Black Desert, and voice conversations with AI. However, some of these features were removed due to new Discord features, discontinued libraries, and associated costs. The bot retains its primary purpose: looking up information about game releases and free games to notify users in the server's text channels.
Technologies:
Typescript
Axios
Prism
Canvas
Discord
ffmpeg
I18n
Lodash
Moment
ESLint
Bot
Like other bots, Mayuri works in response to server events: when an event occurs, the Discord library sends it to the application through a WebSocket. The application processes it accordingly. For Discord commands, the application identifies the command and forwards the request to the corresponding code file for processing.
commands.ts
export class Commands extends ModuleBase {
private readonly commands: CommandBase[]
constructor(client: Client) {
super(client)
this.commands = listCommands()
this.commands.forEach((value) => (value.data = value.create(new SlashCommandBuilder())))
}
private async handlerCommands(interaction: Interaction) {
if (!interaction.isChatInputCommand()) return
const command = this.commands.find((value) => value.check(interaction.commandName))
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`)
const commandInstance: CommandBase = Object.create(command)
commandInstance.i18n = i18next.cloneInstance({
lng: interaction.guildLocale || interaction.locale || undefined,
})
try {
if (commandInstance.condition(interaction))
await transaction(async (prisma) => {
await commandInstance.execute(prisma, interaction)
})
else await interaction.reply(commandInstance.i18n.t('modules.discord.commands.noPermissionCommand'))
} catch (error) {
console.error(error)
try {
if (interaction.replied) {
await interaction.followUp({
content: commandInstance.i18n.t('modules.discord.commands.notFeelingWell'),
ephemeral: true,
})
} else if (interaction.deferred) {
await interaction.editReply({
content: commandInstance.i18n.t('modules.discord.commands.notFeelingWell'),
})
} else {
await interaction.reply({
content: commandInstance.i18n.t('modules.discord.commands.notFeelingWell'),
ephemeral: true,
})
}
} catch (error) {
console.error(error)
}
}
}
}IGDB
IGDB is a collaborative video game database platform. You can browse its website or retrieve data through its API. We use the API to find information about games, such as upcoming releases and free games. It provides a query language called Apicalypse, similar to GraphQL, which enables more complex queries to list the content that will be published on the Discord server.
igdbEndpoint.ts
export default class IgdbEndpoint extends IgdbBase {
public async fetchUpcomingGames(): Promise<IgdbGameType[]> {
return this.fetchAll<IgdbGameType>(async (offset) => {
const apicalypse = await this.getApicalypse({
method: 'POST',
})
this.buildGameFields(apicalypse)
apicalypse.where([
'version_parent = null',
'game_status.id != (5,6,7,8)',
`(release_dates.date >= ${moment().utc().unix()} | release_dates.date_format.format = "TBD")`,
`(hypes >= ${minHypes} | collection.games.hypes >= ${minHypes} | collections.games.hypes >= ${minHypes})`,
])
apicalypse.limit(limit)
apicalypse.offset(offset)
const response = await apicalypse.request('/games')
return response.data
}, limit)
}
}