diff --git a/package.json b/package.json index 737d48f..e6ffa45 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "node-cron": "3.0.2", "sequelize": "6.28.0", "sqlite3": "5.1.4", - "systeminformation": "5.17.3", + "systeminformation": "5.17.4", + "@octokit/rest": "19.0.7", "typescript": "4.9.4", "xml-js": "1.6.11" }, diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 41960c3..90c8a66 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -1,6 +1,7 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; import TClient from 'src/client'; import * as util from 'node:util'; +import { Octokit } from '@octokit/rest'; import {exec} from 'node:child_process'; import { readFileSync } from 'node:fs'; import path from 'node:path'; @@ -68,6 +69,10 @@ export default { interaction.reply(`Uptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot')) break case 'update': + var githubRepo = {owner: 'AnxietyisReal', repo: 'Daggerbot-TS', ref: 'HEAD'} + const octokit = new Octokit({timeZone: 'Australia/NSW', userAgent: 'Daggerbot'}) + const fetchCommitMsg = await octokit.repos.getCommit(githubRepo).then(x=>x.data.commit.message); + const fetchCommitAuthor = await octokit.repos.getCommit(githubRepo).then(x=>x.data.commit.author); const clarkson = await interaction.reply({content: 'Pulling from repository...', fetchReply: true}); exec('git pull',(err:Error,stdout)=>{ if (err){ @@ -75,7 +80,7 @@ export default { } else if (stdout.includes('Already up to date')){ clarkson.edit('Bot is already up to date with the repository, did you forgor to push the changes? :skull:') } else { - setTimeout(()=>{clarkson.edit(`Uptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot'))},650) + setTimeout(()=>{clarkson.edit(`Commit: **${fetchCommitMsg}**\nCommit author: **${fetchCommitAuthor}**\n\nUptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot'))},650) } }); break