mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Start hushing notifs
This commit is contained in:
parent
3b2dff5d42
commit
c090974f07
@ -61,6 +61,7 @@
|
||||
"mime": "^3.0.0",
|
||||
"node-emoji": "^1.11.0",
|
||||
"nyc": "^15.1.0",
|
||||
"parse-duration": "^1.0.2",
|
||||
"prom-client": "^14.0.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rss-parser": "^3.12.0",
|
||||
|
@ -26,6 +26,7 @@ import { ApiError, ErrCode, ValidatorApiError } from "../api";
|
||||
import { PermissionCheckFn } from ".";
|
||||
import { MinimalGitHubIssue, MinimalGitHubRepo } from "../libRs";
|
||||
import Ajv, { JSONSchemaType } from "ajv";
|
||||
import parseDuration from 'parse-duration';
|
||||
|
||||
const log = new Logger("GitHubRepoConnection");
|
||||
const md = new markdown();
|
||||
@ -273,6 +274,14 @@ export interface GitHubTargetFilter {
|
||||
perPage?: number;
|
||||
}
|
||||
|
||||
interface SilencedHook {
|
||||
eventNames: AllowedEventsNames[];
|
||||
filters?: {
|
||||
by?: string;
|
||||
};
|
||||
until: Date,
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles rooms connected to a GitHub repo.
|
||||
*/
|
||||
@ -431,6 +440,8 @@ export class GitHubRepoConnection extends CommandConnection<GitHubRepoConnection
|
||||
|
||||
public debounceOnIssueLabeled = new Map<number, {labels: Set<string>, timeout: NodeJS.Timeout}>();
|
||||
|
||||
public tempSilencedHooks: SilencedHook[] = [];
|
||||
|
||||
constructor(roomId: string,
|
||||
private readonly as: Appservice,
|
||||
state: GitHubRepoConnectionState,
|
||||
@ -712,6 +723,32 @@ export class GitHubRepoConnection extends CommandConnection<GitHubRepoConnection
|
||||
await this.as.botIntent.sendText(this.roomId, `Workflow started.`, "m.notice");
|
||||
}
|
||||
|
||||
@botCommand("hush", "Hush an event for a period of time", ["eventNames"], ["filters", "time"], true)
|
||||
public async onHush(userId: string, eventNamesStr: string, filters?: string, time?: string) {
|
||||
if (!await this.as.botClient.userHasPowerLevelFor(userId, this.roomId, "", true)) {
|
||||
throw new CommandError("not-configured", "You must be able to set state in a room ('Change settings') in order to hush notifications.");
|
||||
}
|
||||
const eventNames = eventNamesStr.split(',');
|
||||
const invalidEventNames = eventNames.filter(s => s in AllowedEvents === false)
|
||||
if (invalidEventNames.length) {
|
||||
throw new CommandError(`${invalidEventNames.join(', ')} are not valid event names`);
|
||||
}
|
||||
const filterSet: Record<string, string> = {};
|
||||
filters?.split(',').forEach(s => {
|
||||
const [key,value] = s.toLowerCase().split(':');
|
||||
filterSet[key] = value;
|
||||
});
|
||||
// One hour
|
||||
const until = new Date(Date.now() + (time ? parseDuration(time) : 1000 * 60 * 60));
|
||||
this.tempSilencedHooks.push({
|
||||
until,
|
||||
filters: {
|
||||
by: filterSet.by,
|
||||
},
|
||||
eventNames: eventNames as AllowedEventsNames[],
|
||||
})
|
||||
}
|
||||
|
||||
public async onIssueCreated(event: IssuesOpenedEvent) {
|
||||
if (this.shouldSkipHook('issue.created', 'issue') || !this.matchesLabelFilter(event.issue)) {
|
||||
return;
|
||||
|
@ -4823,6 +4823,11 @@ parent-module@^1.0.0:
|
||||
dependencies:
|
||||
callsites "^3.0.0"
|
||||
|
||||
parse-duration@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-1.0.2.tgz#b9aa7d3a1363cc7e8845bea8fd3baf8a11df5805"
|
||||
integrity sha512-Dg27N6mfok+ow1a2rj/nRjtCfaKrHUZV2SJpEn/s8GaVUSlf4GGRCRP1c13Hj+wfPKVMrFDqLMLITkYKgKxyyg==
|
||||
|
||||
parse-srcset@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/parse-srcset/-/parse-srcset-1.0.2.tgz#f2bd221f6cc970a938d88556abc589caaaa2bde1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user