diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d336a52e..119377c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,27 +24,27 @@ jobs: run: yarn run build - name: lint run: yarn run lint - + - name: Set up Docker Buildx if: contains(github.ref, 'master') uses: docker/setup-buildx-action@v1 - + - name: Login to Github Container Registry if: contains(github.ref, 'master') uses: docker/login-action@v1 with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GHCR_TOKEN }} - + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_TOKEN }} + - name: Build and push if: contains(github.ref, 'master') uses: docker/build-push-action@v2 with: - context: . - file: ./Dockerfile - push: true - cache-from: type=registry,ref=ghcr.io/typescript-community/bot:latest - cache-to: type=inline - tags: | - ghcr.io/typescript-community/bot:latest + context: . + file: ./Dockerfile + push: true + cache-from: type=registry,ref=ghcr.io/typescript-community/bot:latest + cache-to: type=inline + tags: | + ghcr.io/typescript-community/bot:latest diff --git a/.gitignore b/.gitignore index f065006d..eba986a6 100644 --- a/.gitignore +++ b/.gitignore @@ -62,4 +62,4 @@ typings/ dist/ -.idea +.idea \ No newline at end of file diff --git a/src/modules/etc.ts b/src/modules/etc.ts index 361ccfaf..c867b8bf 100644 --- a/src/modules/etc.ts +++ b/src/modules/etc.ts @@ -4,6 +4,7 @@ import { Module, listener, } from 'cookiecord'; +import { pingPong, dontAskToAskURL, reactfcMsgIssueURL } from './msg'; import { Message, MessageReaction, GuildMember } from 'discord.js'; import { clearMessageOwnership, @@ -18,12 +19,12 @@ export class EtcModule extends Module { @command({ description: 'See if the bot is alive' }) async ping(msg: Message) { - await msg.channel.send('pong. :ping_pong:'); + await msg.channel.send(pingPong); } @command({ description: 'Sends a link to ' }) async ask(msg: Message) { - await msg.channel.send('https://dontasktoask.com/'); + await msg.channel.send(dontAskToAskURL); } @command({ @@ -31,9 +32,7 @@ export class EtcModule extends Module { 'Sends a link to ', }) async reactfc(msg: Message) { - await msg.channel.send( - 'https://github.com/facebook/create-react-app/pull/8177#issue-353062710', - ); + await msg.channel.send(reactfcMsgIssueURL); } @listener({ event: 'message' }) diff --git a/src/modules/helpchan.ts b/src/modules/helpchan.ts index aa3cf5a4..eae591e1 100644 --- a/src/modules/helpchan.ts +++ b/src/modules/helpchan.ts @@ -26,6 +26,7 @@ import { ongoingEmptyTimeout, } from '../env'; import { isTrustedMember } from '../util/inhibitors'; +import { beAskerToCloseChannel, onlyRunInHelp } from './msg'; const AVAILABLE_MESSAGE = ` **Send your question here to claim the channel** @@ -211,9 +212,7 @@ export class HelpChanModule extends Module { return; if (msg.channel.parentID !== categories.ongoing) { - return await msg.channel.send( - ':warning: you can only run this in ongoing help channels.', - ); + return await msg.channel.send(onlyRunInHelp); } const owner = await HelpUser.findOne({ @@ -226,9 +225,7 @@ export class HelpChanModule extends Module { ) { await this.markChannelAsDormant(msg.channel); } else { - return await msg.channel.send( - ':warning: you have to be the asker to close the channel.', - ); + return await msg.channel.send(beAskerToCloseChannel); } } diff --git a/src/modules/msg.ts b/src/modules/msg.ts new file mode 100644 index 00000000..2a79be62 --- /dev/null +++ b/src/modules/msg.ts @@ -0,0 +1,22 @@ +export const pingPong: string = 'pong. :ping_pong:'; +export const dontAskToAskURL: string = 'https://dontasktoask.com/'; +export const reactfcMsgIssueURL: string = + 'https://github.com/facebook/create-react-app/pull/8177#issue-353062710'; +export const onlyRunInHelp: string = + ':warning: you can only run this in ongoing help channels.'; +export const beAskerToCloseChannel: string = + ':warning: you have to be the asker to close the channel.'; +export const couldntFindCodeblock: string = + ":warning: couldn't find a codeblock!"; +export const canRemoveFullLink: string = + "Here's a shortened URL of your playground link! You can remove the full link from your message."; +export const syntaxWarning: string = + ':warning: syntax: !remind [message]'; +export const invalidDuration: string = ':warning: invalid duration!'; +export const cannotSendRepToYou: string = ':x: you cannot send rep to yourself'; +export const noRepRemain: string = + ':warning: no rep remaining! come back later.'; +export const needValidSymbol: string = + 'You need to give me a valid symbol name to look for!'; +export const noTypescriptCode: string = + ':warning: could not find any TypeScript codeblocks in the past 10 messages'; diff --git a/src/modules/playground.ts b/src/modules/playground.ts index 10bb33ae..ea7d462b 100644 --- a/src/modules/playground.ts +++ b/src/modules/playground.ts @@ -12,6 +12,7 @@ import { findCodeblockFromChannel, PLAYGROUND_REGEX, } from '../util/findCodeblockFromChannel'; +import { couldntFindCodeblock, canRemoveFullLink } from './msg'; import { addMessageOwnership, sendWithMessageOwnership } from '../util/send'; export class PlaygroundModule extends Module { @@ -35,10 +36,7 @@ export class PlaygroundModule extends Module { true, ); if (!code) - return sendWithMessageOwnership( - msg, - ":warning: couldn't find a codeblock!", - ); + return sendWithMessageOwnership(msg, couldntFindCodeblock); } const embed = new MessageEmbed() .setURL(PLAYGROUND_BASE + compressToEncodedURIComponent(code)) @@ -63,7 +61,7 @@ export class PlaygroundModule extends Module { } else { // Message also contained other characters const botMsg = await msg.channel.send( - `${msg.author} Here's a shortened URL of your playground link! You can remove the full link from your message.`, + `${msg.author} ${canRemoveFullLink}`, { embed }, ); this.editedLongLink.set(msg.id, botMsg); diff --git a/src/modules/rep.ts b/src/modules/rep.ts index 61456594..6d96cb80 100644 --- a/src/modules/rep.ts +++ b/src/modules/rep.ts @@ -11,6 +11,7 @@ import { TS_BLUE } from '../env'; import { RepGive } from '../entities/RepGive'; import { RepUser } from '../entities/RepUser'; +import { cannotSendRepToYou, noRepRemain } from './msg'; export class RepModule extends Module { constructor(client: CookiecordClient) { @@ -94,15 +95,13 @@ export class RepModule extends Module { @command({ description: 'Give a different user some reputation points' }) async rep(msg: Message, targetMember: GuildMember) { if (targetMember.id === msg.member?.id) - return msg.channel.send(`:x: you cannot send rep to yourself`); + return msg.channel.send(cannotSendRepToYou); const senderRU = await this.getOrMakeUser(msg.author); const targetRU = await this.getOrMakeUser(targetMember.user); if ((await senderRU.sent()) >= this.MAX_REP) - return await msg.channel.send( - ':warning: no rep remaining! come back later.', - ); + return await msg.channel.send(noRepRemain); await RepGive.create({ from: senderRU, diff --git a/src/modules/twoslash.ts b/src/modules/twoslash.ts index fd234e9c..bd9fac15 100644 --- a/src/modules/twoslash.ts +++ b/src/modules/twoslash.ts @@ -2,6 +2,7 @@ import { command, Module, listener } from 'cookiecord'; import { Message, TextChannel } from 'discord.js'; import { twoslasher } from '@typescript/twoslash'; import { findCodeFromChannel } from '../util/findCodeblockFromChannel'; +import { needValidSymbol, noTypescriptCode } from './msg'; import { sendWithMessageOwnership } from '../util/send'; const CODEBLOCK = '```'; @@ -16,21 +17,14 @@ export class TwoslashModule extends Module { const match = /^[_$a-zA-Z][_$0-9a-zA-Z]*/.exec(content); if (!match) { - return sendWithMessageOwnership( - msg, - 'You need to give me a valid symbol name to look for!', - ); + return sendWithMessageOwnership(msg, needValidSymbol); } const symbol = match[0]; const code = await findCodeFromChannel(msg.channel as TextChannel); - if (!code) - return sendWithMessageOwnership( - msg, - `:warning: could not find any TypeScript codeblocks in the past 10 messages`, - ); + if (!code) return sendWithMessageOwnership(msg, noTypescriptCode); const ret = twoslasher(code, 'ts', { defaultOptions: { noErrorValidation: true }, @@ -58,11 +52,7 @@ export class TwoslashModule extends Module { async twoslash(msg: Message) { const code = await findCodeFromChannel(msg.channel as TextChannel); - if (!code) - return sendWithMessageOwnership( - msg, - `:warning: could not find any TypeScript codeblocks in the past 10 messages`, - ); + if (!code) return sendWithMessageOwnership(msg, noTypescriptCode); return this.twoslashBlock(msg, code); }