Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit f13e42021355b90cb56e8766055fec379b9f044f
parent 53646f4061d258e8daa9da016decee9400f9b2f1
Author: Demonstrandum <moi@knutsen.co>
Date:   Sun, 17 May 2020 23:57:24 +0100

Fix !git command.

Diffstat:
Agit.js | 23+++++++++++++++++++++++
Mlib/commands/git.ts | 14++++++++------
Mpackage.json | 1+
Myarn.lock | 2+-
4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/git.js b/git.js @@ -0,0 +1,23 @@ +const git = require('nodegit'); +const path = require('path'); + +const info = async dir => { + const repo = await git.Repository.open(dir); + const master = await repo.getMasterCommit(); + const history = master.history(git.Revwalk.SORT.TIME); + + let count = 0; + history.on("commit", commit => { + if (count++ >= Infinity) return; + console.log(`\`${commit.sha().slice(0, 7)}\` — ` + + `${commit.message().trim()}` + + ` (by ${commit.author().name()})`); + }); + console.log('Start history:'); + history.start(); + history.on("end", () => { + console.log('hi'); + }); +}; + +info(path.resolve(process.cwd(), "./.git")); diff --git a/lib/commands/git.ts b/lib/commands/git.ts @@ -1,4 +1,4 @@ -import * as git from 'nodegit'; +import git from 'nodegit'; import fetch from 'node-fetch'; import path from 'path'; @@ -25,7 +25,7 @@ const get_history = (max: number): Promise<History[]> => let count = 0; const hist_array: History[] = []; history.on("commit", commit => { - if (++count >= max) return res(hist_array); + if (count++ >= max) return; const entry: History = { hash: commit.sha().toString().slice(0, 7), message: commit.message().trim(), @@ -33,6 +33,7 @@ const get_history = (max: number): Promise<History[]> => }; hist_array.push(entry); }); + history.on("end", () => res(hist_array)); history.start(); }); @@ -74,19 +75,20 @@ export default async (homescope : HomeScope) => { return message.channel.send(str); } - if (args[0].startsWith('contr')) { + if (args[0].startsWith('cont')) { const breakdown = await shortlog(); return message.channel.send("**Contributors:**\n" - + Object.keys(breakdown).join("\n")); + + Object.keys(breakdown).map(e => ` - ${e}`).join("\n")); } - if (args[0] === 'breakdown') { + if (args[0].startsWith('break')) { const breakdown = await shortlog(); const pad = Object.values(breakdown).reduce((acc, e) => e.toString().length > acc ? e.toString().length : acc, 1); const formatted = Object.keys(breakdown).map(e => `\`${breakdown[e].toString().padStart(pad)}\`: ${e}`); - return message.channel.send(formatted.join("\n")); + return message.channel.send("**Commits per Contributor:**\n" + + formatted.join("\n")); } const res = await fetch(GITHUB_API); diff --git a/package.json b/package.json @@ -50,6 +50,7 @@ "jimp": "^0.9.6", "node-fetch": "^2.6.0", "nodegit": "^0.26.5", + "request": "^2.34", "scrape-youtube": "^0.0.5", "tslib": "^1.11.1", "typescript": "^3.8.3", diff --git a/yarn.lock b/yarn.lock @@ -2077,7 +2077,7 @@ request-promise-native@^1.0.5: stealthy-require "^1.1.1" tough-cookie "^2.3.3" -request@>=2.51.0, request@^2.87.0, request@^2.88.0: +request@>=2.51.0, request@^2.34, request@^2.87.0, request@^2.88.0: version "2.88.2" resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==