feat:! codewatcher !partial

This commit is contained in:
Saahil 2024-11-05 22:17:27 -05:00
parent b5f612674a
commit 4fa3c26b06
No known key found for this signature in database
GPG key ID: 8A8B64515254CFC6
6 changed files with 84 additions and 6 deletions

View file

@ -12,6 +12,7 @@
"body-parser": "latest",
"dotenv": "^16.4.5",
"eventsource": "latest",
"ms": "^2.1.3",
"node-cron": "^3.0.3",
"node-ical": "^0.20.1",
"simple-json-db": "^2.0.0",

View file

@ -0,0 +1,45 @@
import { App } from "@slack/bolt";
import { Command, onlyForMe } from "../modules/BaseCommand";
import { ModifiedApp } from "../modules/slackapp";
export default class codewatcher implements Command {
name: string;
description: string;
constructor() {
this.name = `/codewatcher`;
this.description = `Pings zeon`;
}
run(app: ModifiedApp) {
// app.command()
app.command(this.name, async ({ command, ack, respond }) => {
await ack();
if (!onlyForMe(command.user_id))
return respond(`:x: You cannot use this command.`);
const subcmd = command.text.split(" ")[1];
switch (subcmd) {
case "start":
app.client.chat.postMessage({
channel: command.channel_id,
text: `Starting Code Watcher`,
});
break;
case "stop":
let d = app.db.get('git_session') || [];
// d = d.filter(e=>e.active);
d[d.indexOf(d.find(e=>e.active))].active = false;
app.db.set('git_session', d);
app.client.chat.postEphemeral({
channel: command.channel_id,
user: command.user_id,
text: `Stopping Code Watcher`,
});
break;
default:
respond(`Unknown subcmd \`${subcmd}\``);
break;
}
});
}
}

View file

@ -12,8 +12,10 @@ import { getResponse } from "./modules/randomResponseSystem";
import * as utils from "./modules/index";
import howWasYourDay from "./modules/howWasYourDay";
import { PrivateDNS } from "./modules/nextdns";
import { attachDB } from "./modules/projectWaterydo";
const db = new JSONdb("data.json");
attachDB(db);
app.start(process.env.PORT || 3000).then(async (d) => {
console.log(`App is UP (please help)`);
setInterval(() => {

View file

@ -0,0 +1,26 @@
import { App } from "@slack/bolt";
import JSONdb from "simple-json-db";
interface GitBody {
commit_id: string;
commit_url: string;
repo_name: string;
}
export function handleGitRequest(body: GitBody, app: App) {
if(!db) return;
if(!db.get('git_session')) return;
const session = (db.get('git_session') || []).find(e=>e.active);
if(session.repo_name !== body.repo_name) return;
app.client.chat.postMessage({
channel: session.channel,
thread_ts: session.thread_ts,
text: body.commit_url
})
}
export let db: null | JSONdb = null;
export function attachDB(d: JSONdb) {
db = d;
}
// export function handleStartup() {
// }

View file

@ -3,6 +3,7 @@
import { App } from "@slack/bolt";
import { StringIndexed } from "@slack/bolt/dist/types/helpers";
import JSONdb from "simple-json-db";
import { handleGitRequest } from "./projectWaterydo";
export interface ModifiedApp extends App<StringIndexed> {
db: JSONdb;
utils: typeof import("./index");
@ -80,6 +81,9 @@ export const app = new App({
res.writeHead(400).end();
return;
}
//@ts-ignore
handleGitRequest(req.body, app);
res.writeHead(200).end();
})
);
}

View file

@ -659,12 +659,7 @@ eventemitter3@^5:
resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz"
integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==
eventsource@^2.0.2:
version "2.0.2"
resolved "https://registry.npmjs.org/eventsource/-/eventsource-2.0.2.tgz"
integrity sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==
eventsource@latest:
eventsource@^2.0.2, eventsource@latest:
version "2.0.2"
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-2.0.2.tgz#76dfcc02930fb2ff339520b6d290da573a9e8508"
integrity sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==
@ -1162,6 +1157,11 @@ ms@2.1.3, ms@^2.1.1:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
negotiator@0.6.3:
version "0.6.3"
resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz"