mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
const Command = require('../../framework/Command');
|
|
const { EmbedBuilder } = require('discord.js');
|
|
const request = require('node-superfetch');
|
|
const { shorten, embedURL } = require('../../util/Util');
|
|
const { GITHUB_ACCESS_TOKEN } = process.env;
|
|
const XIAO_GITHUB_REPO_USERNAME = process.env.XIAO_GITHUB_REPO_USERNAME || 'xiaobotdev';
|
|
const XIAO_GITHUB_REPO_NAME = process.env.XIAO_GITHUB_REPO_NAME || 'xiao';
|
|
|
|
module.exports = class ChangelogCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'changelog',
|
|
aliases: ['updates', 'commits'],
|
|
group: 'util-public',
|
|
description: 'Responds with the bot\'s latest 10 commits.',
|
|
guarded: true,
|
|
credit: [
|
|
{
|
|
name: 'GitHub',
|
|
url: 'https://github.com/',
|
|
reason: 'API',
|
|
reasonURL: 'https://developer.github.com/v3/'
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg) {
|
|
const { body } = await request
|
|
.get(`https://api.github.com/repos/${XIAO_GITHUB_REPO_USERNAME}/${XIAO_GITHUB_REPO_NAME}/commits`)
|
|
.set({ Authorization: `token ${GITHUB_ACCESS_TOKEN}` });
|
|
const commits = body.slice(0, 10);
|
|
const embed = new EmbedBuilder()
|
|
.setTitle(`[${XIAO_GITHUB_REPO_NAME}:master] Latest 10 commits`)
|
|
.setColor(0x7289DA)
|
|
.setURL(`https://github.com/${XIAO_GITHUB_REPO_USERNAME}/${XIAO_GITHUB_REPO_NAME}/commits/master`)
|
|
.setDescription(commits.map(commit => {
|
|
const hash = embedURL(`\`${commit.sha.slice(0, 7)}\``, commit.html_url, false);
|
|
return `${hash} ${shorten(commit.commit.message.split('\n')[0], 50)} - ${commit.author.login}`;
|
|
}).join('\n'));
|
|
return msg.embed(embed);
|
|
}
|
|
};
|