Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralized file for messages #91

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ jobs:
run: yarn run build
- name: lint
run: yarn run lint
NimperX marked this conversation as resolved.
Show resolved Hide resolved

- 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ typings/

dist/

.idea
.idea
9 changes: 4 additions & 5 deletions src/modules/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Module,
listener,
} from 'cookiecord';
import { pingPong, dontAskToAskURL, reactfcMsgIssueURL } from './msg';
import { Message, MessageReaction, GuildMember } from 'discord.js';
import {
clearMessageOwnership,
Expand All @@ -18,22 +19,20 @@ 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 <https://dontasktoask.com>' })
async ask(msg: Message) {
await msg.channel.send('https://dontasktoask.com/');
await msg.channel.send(dontAskToAskURL);
}

@command({
description:
'Sends a link to <https://github.com/facebook/create-react-app/pull/8177#issue-353062710>',
})
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' })
Expand Down
9 changes: 3 additions & 6 deletions src/modules/helpchan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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({
Expand All @@ -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);
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/modules/msg.ts
Original file line number Diff line number Diff line change
@@ -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 <duration> [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';
8 changes: 3 additions & 5 deletions src/modules/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand All @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/modules/rep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 4 additions & 14 deletions src/modules/twoslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '```';
Expand All @@ -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 },
Expand Down Expand Up @@ -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);
}
Expand Down