Allow quick linking of PRs and issues
This commit is contained in:
@@ -6,6 +6,7 @@ RELEASE_SECRET=
|
|||||||
LINK_SECRET=super_secret_for_url_discord
|
LINK_SECRET=super_secret_for_url_discord
|
||||||
E621_BASE_URL=https://e621.net
|
E621_BASE_URL=https://e621.net
|
||||||
E926_BASE_URL=https://e926.net
|
E926_BASE_URL=https://e926.net
|
||||||
|
GIT_REPO_BASE_URL=https://github.com/e621ng/e621ng
|
||||||
REDIS_URL=localhost:6379
|
REDIS_URL=localhost:6379
|
||||||
PORT=8000
|
PORT=8000
|
||||||
DEBUG=false
|
DEBUG=false
|
||||||
+2
-1
@@ -2,7 +2,7 @@ import dotenv from 'dotenv';
|
|||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const { DISCORD_TOKEN, DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET, DISCORD_GUILD_ID, RELEASE_SECRET, LINK_SECRET, E621_BASE_URL, E926_BASE_URL, REDIS_URL, PORT, DEBUG } = process.env;
|
const { DISCORD_TOKEN, DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET, DISCORD_GUILD_ID, RELEASE_SECRET, LINK_SECRET, E621_BASE_URL, E926_BASE_URL, GIT_REPO_BASE_URL, REDIS_URL, PORT, DEBUG } = process.env;
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
DISCORD_TOKEN,
|
DISCORD_TOKEN,
|
||||||
@@ -13,6 +13,7 @@ export const config = {
|
|||||||
LINK_SECRET,
|
LINK_SECRET,
|
||||||
E621_BASE_URL,
|
E621_BASE_URL,
|
||||||
E926_BASE_URL,
|
E926_BASE_URL,
|
||||||
|
GIT_REPO_BASE_URL,
|
||||||
PORT: parseInt(PORT as string),
|
PORT: parseInt(PORT as string),
|
||||||
REDIS_URL,
|
REDIS_URL,
|
||||||
DEV_MODE: process.env.npm_lifecycle_event == 'dev',
|
DEV_MODE: process.env.npm_lifecycle_event == 'dev',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Message as DiscordMessage, GuildBasedChannel, GuildTextBasedChannel, Om
|
|||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { E621Post } from '../types';
|
import { E621Post } from '../types';
|
||||||
import { ALLOWED_MIMETYPES, artistIDRegex, blipIDRegex, calculateMD5FromURL, channelIgnoresLinks, channelIsInStaffCategory, channelIsSafe, commentIDRegex, forumTopicIDRegex, getE621Post, getE621PostByMd5, getPostUrl, isEdited, isInSpoilerTags, logDeletion, logEdit, poolIDRegex, PostAction, postIDRegex, recordIDRegex, searchLinkRegex, setIDRegex, spoilerOrBlacklist, takedownIDRegex, ticketIDRegex, userIDRegex, wikiLinkRegex } from '../utils';
|
import { ALLOWED_MIMETYPES, artistIDRegex, blipIDRegex, calculateMD5FromURL, channelIgnoresLinks, channelIsInStaffCategory, channelIsSafe, commentIDRegex, forumTopicIDRegex, getE621Post, getE621PostByMd5, getPostUrl, isEdited, isInSpoilerTags, issueRegex, logDeletion, logEdit, poolIDRegex, PostAction, postIDRegex, prRegex, recordIDRegex, searchLinkRegex, setIDRegex, spoilerOrBlacklist, takedownIDRegex, ticketIDRegex, userIDRegex, wikiLinkRegex } from '../utils';
|
||||||
|
|
||||||
export type Message<InGuild extends boolean = boolean> = OmitPartialGroupDMChannel<DiscordMessage<InGuild>>;
|
export type Message<InGuild extends boolean = boolean> = OmitPartialGroupDMChannel<DiscordMessage<InGuild>>;
|
||||||
export type Partial = OmitPartialGroupDMChannel<PartialMessage>;
|
export type Partial = OmitPartialGroupDMChannel<PartialMessage>;
|
||||||
@@ -39,7 +39,10 @@ const regexTesters = [
|
|||||||
{ runInDev: true, regex: ticketIDRegex, handler: idHandler.bind(null, 'tickets') },
|
{ runInDev: true, regex: ticketIDRegex, handler: idHandler.bind(null, 'tickets') },
|
||||||
{ runInDev: true, regex: artistIDRegex, handler: idHandler.bind(null, 'artists') },
|
{ runInDev: true, regex: artistIDRegex, handler: idHandler.bind(null, 'artists') },
|
||||||
{ runInDev: true, regex: wikiLinkRegex, handler: wikiPageHandler },
|
{ runInDev: true, regex: wikiLinkRegex, handler: wikiPageHandler },
|
||||||
{ runInDev: true, regex: searchLinkRegex, handler: searchHandler }
|
{ runInDev: true, regex: searchLinkRegex, handler: searchHandler },
|
||||||
|
|
||||||
|
{ runInDev: true, regex: prRegex, handler: githubPullRequestHandler },
|
||||||
|
{ runInDev: true, regex: issueRegex, handler: githubIssueHandler },
|
||||||
];
|
];
|
||||||
|
|
||||||
const uniqueRegexMatches = (g, i, a) => a.findIndex(v => v[1] == g[1]) == i;
|
const uniqueRegexMatches = (g, i, a) => a.findIndex(v => v[1] == g[1]) == i;
|
||||||
@@ -346,5 +349,37 @@ async function imageHandler(message: Message, matchedGroups: RegExpExecArray[]):
|
|||||||
|
|
||||||
if (content.trim().length > 0) return content.trim();
|
if (content.trim().length > 0) return content.trim();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function githubPullRequestHandler(message: Message, matchedGroups: RegExpExecArray[]): Promise<string | boolean> {
|
||||||
|
const skip = await channelIgnoresLinks(message.channel as GuildBasedChannel);
|
||||||
|
|
||||||
|
if (skip) return true;
|
||||||
|
|
||||||
|
let content = '';
|
||||||
|
|
||||||
|
for (const group of matchedGroups) {
|
||||||
|
content += `${config.GIT_REPO_BASE_URL}/pull/${group[1]}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.trim().length > 0) return content.trim();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function githubIssueHandler(message: Message, matchedGroups: RegExpExecArray[]): Promise<string | boolean> {
|
||||||
|
const skip = await channelIgnoresLinks(message.channel as GuildBasedChannel);
|
||||||
|
|
||||||
|
if (skip) return true;
|
||||||
|
|
||||||
|
let content = '';
|
||||||
|
|
||||||
|
for (const group of matchedGroups) {
|
||||||
|
content += `${config.GIT_REPO_BASE_URL}/issues/${group[1]}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.trim().length > 0) return content.trim();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -20,7 +20,7 @@ export * from './oauth2';
|
|||||||
export * from './private-help-utils';
|
export * from './private-help-utils';
|
||||||
export * from './record-utils';
|
export * from './record-utils';
|
||||||
export * from './refresh-commands';
|
export * from './refresh-commands';
|
||||||
export * from './search-regex';
|
export * from './message-matcher-regex';
|
||||||
export * from './string-utils';
|
export * from './string-utils';
|
||||||
export * from './ticket-events';
|
export * from './ticket-events';
|
||||||
export * from './ticket-utils';
|
export * from './ticket-utils';
|
||||||
|
|||||||
@@ -12,4 +12,7 @@ export const artistIDRegex = new RegExp('artist #([0-9]+)', 'gi');
|
|||||||
|
|
||||||
const tagSearchRegex = '(?:[\\S]| )+?';
|
const tagSearchRegex = '(?:[\\S]| )+?';
|
||||||
export const wikiLinkRegex = new RegExp(`\\[\\[(${tagSearchRegex})]]`, 'gi');
|
export const wikiLinkRegex = new RegExp(`\\[\\[(${tagSearchRegex})]]`, 'gi');
|
||||||
export const searchLinkRegex = new RegExp(`{{(${tagSearchRegex})}}`, 'gi');
|
export const searchLinkRegex = new RegExp(`{{(${tagSearchRegex})}}`, 'gi');
|
||||||
|
|
||||||
|
export const prRegex = new RegExp('pr #([0-9]+)', 'gi');
|
||||||
|
export const issueRegex = new RegExp('issue #([0-9]+)', 'gi');
|
||||||
@@ -3,7 +3,7 @@ import { config } from '../config';
|
|||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { Ticket, TicketPhrase, TicketUpdate } from '../types';
|
import { Ticket, TicketPhrase, TicketUpdate } from '../types';
|
||||||
import { PostAction, getE621Post, getE621User, spoilerOrBlacklist } from './e621-utils';
|
import { PostAction, getE621Post, getE621User, spoilerOrBlacklist } from './e621-utils';
|
||||||
import { blipIDRegex, commentIDRegex, forumTopicIDRegex, poolIDRegex, postIDRegex, recordIDRegex, searchLinkRegex, setIDRegex, takedownIDRegex, ticketIDRegex, userIDRegex, wikiLinkRegex } from './search-regex';
|
import { blipIDRegex, commentIDRegex, forumTopicIDRegex, poolIDRegex, postIDRegex, recordIDRegex, searchLinkRegex, setIDRegex, takedownIDRegex, ticketIDRegex, userIDRegex, wikiLinkRegex } from './message-matcher-regex';
|
||||||
import { humanizeCapitalization } from './string-utils';
|
import { humanizeCapitalization } from './string-utils';
|
||||||
import { shouldAlert } from './ticket-utils';
|
import { shouldAlert } from './ticket-utils';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user