Skip to content

Commit

Permalink
Merge branch 'master' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 authored Aug 20, 2023
2 parents e17491c + dd55858 commit 09030d0
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 515 deletions.
9 changes: 6 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BOT_ADMINS=123,456
AUTOROLE=MSG_ID:ROLE_ID:EMOJI:AUTOREMOVE
# Another example: AUTOROLE=738932146978160661:728202487672078368:❌:false,738932146978160661:738936540465725520:✅:true

DATABASE_URL="localhost:5432/tsc-bot"
DATABASE_URL="postgres://tscbot:tscbot@localhost:5432/tscbot"

# Role given to trusted members, not full moderators, but can use some commands which
# are not given to all server members.
Expand All @@ -15,10 +15,13 @@ RULES_CHANNEL=

ROLES_CHANNEL=

HELP_CATEGORY=
HOW_TO_GET_HELP_CHANNEL=
HOW_TO_GIVE_HELP_CHANNEL=
GENERAL_HELP_CHANNEL=

HELP_FORUM_CHANNEL=
HELP_REQUESTS_CHANNEL=
HELP_FORUM_OPEN_TAG=Open
HELP_FORUM_RESOLVED_TAG=Resolved

# Time in milliseconds before !helper can be run
TIME_BEFORE_HELPER_PING=
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 2022-12-16

- Remove `!close`, update `!helper` to include thread tags.

# 2022-11-19

- Removed `HELP_CATEGORY`, `GENERAL_HELP_CHANNEL` environment variables.
- Added `HELP_FORUM_CHANNEL`, `HELP_REQUESTS_CHANNEL` environment variables.
- Updated how to get help and how to give help channel content to not use embeds.
- Updated to Discord.js 14, removed Cookiecord to prevent future delays in updating versions.
- The bot will now react on the configured autorole messages to indicate available roles.
- Unhandled rejections will now only be ignored if `NODE_ENV` is set to `production`.
Expand Down
8 changes: 5 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ export class Bot {
return botAdmins.includes(user.id);
}

getTrustedMemberError(msg: Message) {
isTrusted(msg: Message) {
if (!msg.guild || !msg.member || !msg.channel.isTextBased()) {
return ":warning: you can't use that command here.";
return false;
}

if (
!msg.member.roles.cache.has(trustedRoleId) &&
!msg.member.permissions.has('ManageMessages')
) {
return ":warning: you don't have permission to use that command.";
return false;
}

return true;
}

async getTargetUser(msg: Message): Promise<User | undefined> {
Expand Down
10 changes: 8 additions & 2 deletions src/entities/HelpThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ export class HelpThread extends BaseEntity {
@Column({ nullable: true })
helperTimestamp?: string;

// When the title was last set
/**
* When the title was last set, exists only for backwards compat
* @deprecated
*/
@Column({ nullable: true })
titleSetTimestamp?: string;

// The id of the original message; nullable for backwards compat
/**
* The id of the original message, exists only for backwards compat
* @deprecated
*/
@Column({ nullable: true })
origMessageId?: string;
}
7 changes: 5 additions & 2 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export const autorole = process.env.AUTOROLE!.split(',').map(x => {

export const dbUrl = process.env.DATABASE_URL!;

export const helpCategory = process.env.HELP_CATEGORY!;
export const howToGetHelpChannel = process.env.HOW_TO_GET_HELP_CHANNEL!;
export const howToGiveHelpChannel = process.env.HOW_TO_GIVE_HELP_CHANNEL!;
export const generalHelpChannel = process.env.GENERAL_HELP_CHANNEL!;
export const helpForumChannel = process.env.HELP_FORUM_CHANNEL!;
export const helpRequestsChannel = process.env.HELP_REQUESTS_CHANNEL!;

export const helpForumOpenTagName = process.env.HELP_FORUM_OPEN_TAG!;
export const helpForumResolvedTagName = process.env.HELP_FORUM_RESOLVED_TAG!;

export const trustedRoleId = process.env.TRUSTED_ROLE_ID!;

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { playgroundModule } from './modules/playground';
import { repModule } from './modules/rep';
import { twoslashModule } from './modules/twoslash';
import { snippetModule } from './modules/snippet';
import { helpThreadModule } from './modules/helpthread';
import { helpForumModule } from './modules/helpForum';

const client = new Client({
partials: [
Expand Down Expand Up @@ -45,7 +45,7 @@ client.on('ready', async () => {
for (const mod of [
autoroleModule,
etcModule,
helpThreadModule,
helpForumModule,
playgroundModule,
repModule,
twoslashModule,
Expand Down
16 changes: 10 additions & 6 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Channel,
BaseGuildTextChannel,
Client,
GuildChannel,
GuildMember,
TextChannel,
ThreadChannel,
User,
} from 'discord.js';
import { inspect } from 'util';
Expand Down Expand Up @@ -72,7 +72,11 @@ const inspectUser = (user: User) =>
defineCustomUtilInspect(User, inspectUser);
defineCustomUtilInspect(GuildMember, member => inspectUser(member.user));

defineCustomUtilInspect(
GuildChannel,
channel => `#${channel.name}/${(channel as Channel).id}`,
);
const channels: Array<{ prototype: { name: string; id: string } }> = [
BaseGuildTextChannel,
ThreadChannel,
];

for (const ctor of channels) {
defineCustomUtilInspect(ctor, channel => `#${channel.name}/${channel.id}`);
}
Loading

0 comments on commit 09030d0

Please sign in to comment.