Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
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 @@ -5,6 +5,7 @@ import {
listener,
} from 'cookiecord';
import { Message } from 'discord.js';
import { pingPong, dontAskToAsk, reactfcMsg } from './msg';

export class EtcModule extends Module {
constructor(client: CookiecordClient) {
Expand All @@ -13,22 +14,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(dontAskToAsk);
}

@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(reactfcMsg);
}

@listener({ event: 'message' })
Expand Down
14 changes: 6 additions & 8 deletions src/modules/helpchan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
} from '../env';
import { isTrustedMember } from '../util/inhibitors';

import { beAskerToCloseChannel, okHand, onlyRunInHelp } from './msg';

export class HelpChanModule extends Module {
constructor(client: CookiecordClient) {
super(client);
Expand Down Expand Up @@ -140,9 +142,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 @@ -155,9 +155,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 Expand Up @@ -348,7 +346,7 @@ export class HelpChanModule extends Module {
})
async removelock(msg: Message) {
this.busyChannels.delete(msg.channel.id);
await msg.channel.send(':ok_hand:');
await msg.channel.send(okHand);
}

@command({
Expand All @@ -358,6 +356,6 @@ export class HelpChanModule extends Module {
if (!msg.guild) return;

await this.ensureAskChannels(msg.guild);
await msg.channel.send(':ok_hand:');
await msg.channel.send(okHand);
}
}
23 changes: 23 additions & 0 deletions src/modules/msg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const okHand: string = ':ok_hand:';
export const pingPong: string = 'pong. :ping_pong:';
export const dontAskToAsk: string = 'https://dontasktoask.com/';
export const reactfcMsg: 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';

export class PlaygroundModule extends Module {
constructor(client: CookiecordClient) {
Expand All @@ -33,10 +34,7 @@ export class PlaygroundModule extends Module {
msg.channel as TextChannel,
true,
);
if (!code)
return await msg.channel.send(
":warning: couldn't find a codeblock!",
);
if (!code) return await msg.channel.send(couldntFindCodeblock);
}
const embed = new MessageEmbed()
.setURL(PLAYGROUND_BASE + compressToEncodedURIComponent(code))
Expand All @@ -61,7 +59,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
12 changes: 5 additions & 7 deletions src/modules/reminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getDB } from '../db';
import prettyMs from 'pretty-ms';
import { setTimeout } from 'timers';
import { Reminder } from '../entities/Reminder';
import { invalidDuration, okHand, syntaxWarning } from './msg';

export class ReminderModule extends Module {
constructor(client: CookiecordClient) {
Expand Down Expand Up @@ -39,14 +40,11 @@ export class ReminderModule extends Module {
async remind(msg: Message, args: string) {
// cookiecord can't have args with spaces in them (yet)
const splitArgs = args.split(' ').filter(x => x.trim().length !== 0);
if (splitArgs.length == 0)
return await msg.channel.send(
':warning: syntax: !remind <duration> [message]',
);
if (splitArgs.length == 0) return await msg.channel.send(syntaxWarning);
const maxDur = parse('10yr');
const dur = parse(splitArgs.shift()!); // TS doesn't know about the length check
if (!dur || !maxDur || dur > maxDur)
return await msg.channel.send(':warning: invalid duration!');
return await msg.channel.send(invalidDuration);

const reminder = new Reminder();
reminder.userID = msg.author.id;
Expand All @@ -57,11 +55,11 @@ export class ReminderModule extends Module {

if (splitArgs.length == 0) {
await msg.channel.send(
`:ok_hand: set a reminder for ${prettyMs(dur)}.`,
`${okHand} set a reminder for ${prettyMs(dur)}.`,
);
} else {
await msg.channel.send(
`:ok_hand: set a reminder for ${prettyMs(
`${okHand} set a reminder for ${prettyMs(
dur,
)} to remind you about "${splitArgs.join('')}".`,
);
Expand Down
9 changes: 4 additions & 5 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, okHand } from './msg';

export class RepModule extends Module {
constructor(client: CookiecordClient) {
Expand Down Expand Up @@ -94,23 +95,21 @@ 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,
to: targetRU,
}).save();

await msg.channel.send(
`:ok_hand: sent \`${targetMember.displayName}\` 1 rep (${
`${okHand} sent \`${targetMember.displayName}\` 1 rep (${
(await senderRU.sent()) + 1
}/${this.MAX_REP} sent)`,
);
Expand Down
15 changes: 4 additions & 11 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';

const CODEBLOCK = '```';

Expand All @@ -15,20 +16,15 @@ export class TwoslashModule extends Module {
const match = /^[_$a-zA-Z][_$0-9a-zA-Z]*/.exec(content);

if (!match) {
msg.channel.send(
'You need to give me a valid symbol name to look for!',
);
msg.channel.send(needValidSymbol);
return;
}

const symbol = match[0];

const code = await findCodeFromChannel(msg.channel as TextChannel);

if (!code)
return msg.channel.send(
`:warning: could not find any TypeScript codeblocks in the past 10 messages`,
);
if (!code) return msg.channel.send(noTypescriptCode);

const ret = twoslasher(code, 'ts', {
defaultOptions: { noErrorValidation: true },
Expand All @@ -54,10 +50,7 @@ export class TwoslashModule extends Module {
async twoslash(msg: Message) {
const code = await findCodeFromChannel(msg.channel as TextChannel);

if (!code)
return msg.channel.send(
`:warning: could not find any TypeScript codeblocks in the past 10 messages`,
);
if (!code) return msg.channel.send(noTypescriptCode);

return this.twoslashBlock(msg, code);
}
Expand Down