diff --git a/README.md b/README.md index 4ae2fdb1..951604dd 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,12 @@ You can invite the bot to your server using Be sure to also join the [home server](https://discord.gg/sbMe32W) for information and support. -## Commands (293) +## Commands (294) ### Utility: * **prefix**: Shows or sets the command prefix. * **eval**: Executes JavaScript code. +* **changelog**: Responds with Xiao's latest 10 commits. * **donate**: Responds with Xiao's donation links. * **help**: Displays a list of available commands, or detailed information for a specific command. * **info**: Responds with detailed bot information. diff --git a/commands/util/changelog.js b/commands/util/changelog.js new file mode 100644 index 00000000..3e1d1f95 --- /dev/null +++ b/commands/util/changelog.js @@ -0,0 +1,34 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { shorten, base64 } = require('../../util/Util'); +const { GITHUB_USERNAME, GITHUB_PASSWORD, GITHUB_REPO_USERNAME, GITHUB_REPO_NAME } = process.env; + +module.exports = class ChangelogCommand extends Command { + constructor(client) { + super(client, { + name: 'changelog', + aliases: ['updates', 'commits'], + group: 'util', + memberName: 'changelog', + description: 'Responds with Xiao\'s latest 10 commits.', + guarded: true + }); + } + + async run(msg) { + const { body } = await request + .get(`https://api.github.com/repos/${GITHUB_REPO_USERNAME}/${GITHUB_REPO_NAME}/commits`) + .set({ Authorization: `Basic ${base64(`${GITHUB_USERNAME}:${GITHUB_PASSWORD}`)}` }); + const commits = body.slice(0, 10); + const embed = new MessageEmbed() + .setTitle('[xiao:master] Latest 10 commits') + .setColor(0x7289DA) + .setURL(`https://github.com/${GITHUB_REPO_USERNAME}/${GITHUB_REPO_NAME}/commits/master`) + .setDescription(commits.map(commit => { + const hash = `[\`${commit.sha.slice(0, 7)}\`](${commit.html_url})`; + return `${hash} ${shorten(commit.commit.message, 50)} - ${commit.author.login}`; + }).join('\n')); + return msg.embed(embed); + } +}; diff --git a/package.json b/package.json index 89052f7a..137ab149 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "84.3.2", + "version": "84.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {