Skip to content

Commit

Permalink
chore(deps): update dependenices to latest and use type imports (#27)
Browse files Browse the repository at this point in the history
* feat: initial update

* feat: pass 1 type imports (ts 4.5)

* feat: pass 2 type imports

* chore(deps): update to latest all packages

* fix: fix npm error with node >= 16.6.x

* chore(deps): audit fix

* fix: fix build

* Update minimum nodejs version in readme

Co-authored-by: MarcusOtter <[email protected]>
  • Loading branch information
c43721 and MarcusOtter authored Feb 1, 2022
1 parent 32b90b7 commit 2ce78dd
Show file tree
Hide file tree
Showing 14 changed files with 703 additions and 1,245 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

## Self-hosting
This step-by-step guide assumes you have [NodeJS](https://nodejs.org/en/) version `16.6.0` or higher installed and that you have a Discord Bot user set up at [Discord's developer page](https://discord.com/developers/applications) that has been invited to your server with the scopes `applications.commands` and `bot`.
This step-by-step guide assumes you have [NodeJS](https://nodejs.org/en/) version `16.9.0` or higher installed and that you have a Discord Bot user set up at [Discord's developer page](https://discord.com/developers/applications) that has been invited to your server with the scopes `applications.commands` and `bot`.

1. Fork and clone the repository
2. Create a file named `.env` in the root directory and insert your bot's Discord API token and Application ID:
Expand Down
1,873 changes: 666 additions & 1,207 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"name": "discord-needle",
"version": "1.0.0",
"description": "Needle is a discord bot that helps you manage your discord threads.",
"main": "src/index.js",
"main": "./dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rd /s /q dist & tsc",
"start": "npm run build && node ./dist/index.js",
"dev": "npm run build && node ./scripts/deploy-commands.js && node ./dist/index.js",
Expand All @@ -22,20 +21,20 @@
},
"homepage": "https://github.com/MarcusOtter/discord-needle",
"dependencies": {
"@discordjs/builders": "^0.8.2",
"@discordjs/rest": "^0.1.0-canary.0",
"discord-api-types": "^0.24.0",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0"
"@discordjs/builders": "^0.12.0",
"@discordjs/rest": "^0.3.0",
"discord-api-types": "^0.26.1",
"discord.js": "^13.6.0",
"dotenv": "^15.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"eslint": "^7.32.0",
"typescript": "^4.3.5"
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"eslint": "^8.8.0",
"typescript": "^4.5.5"
},
"engines": {
"node": "16.*",
"node": ">=16.9.x",
"npm": "*"
}
}
4 changes: 2 additions & 2 deletions src/commands/close.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction, GuildMember, MessageComponentInteraction, Permissions } from "discord.js";
import { type CommandInteraction, GuildMember, MessageComponentInteraction, Permissions } from "discord.js";
import { interactionReply, getThreadStartMessage, getMessage } from "../helpers/messageHelpers";
import { NeedleCommand } from "../types/needleCommand";
import type { NeedleCommand } from "../types/needleCommand";

export const command: NeedleCommand = {
name: "close",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/configure.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types";
import { CommandInteraction, GuildMember, GuildTextBasedChannel, Permissions } from "discord.js";
import { type CommandInteraction, GuildMember, type GuildTextBasedChannel, Permissions } from "discord.js";
import { disableAutothreading, enableAutothreading, getConfig, resetConfigToDefault, setMessage } from "../helpers/configHelpers";
import { interactionReply, getMessage, MessageKey, isAutoThreadChannel, addMessageContext } from "../helpers/messageHelpers";
import { NeedleCommand } from "../types/needleCommand";
import type { NeedleCommand } from "../types/needleCommand";
import { memberIsModerator } from "../helpers/permissionHelpers";

// Note:
Expand Down Expand Up @@ -125,7 +125,7 @@ async function configureAutothreading(interaction: CommandInteraction): Promise<
const enabled = interaction.options.getBoolean("enabled");
const customMessage = interaction.options.getString("custom-message") ?? "";

if (!interaction.guild) {
if (!interaction.guild || !interaction.guildId) {
return interactionReply(interaction, getMessage("ERR_ONLY_IN_SERVER"));
}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction, MessageActionRow, MessageEmbed } from "discord.js";
import { APIApplicationCommandOption } from "discord-api-types";
import { type CommandInteraction, MessageActionRow, MessageEmbed } from "discord.js";
import type { APIApplicationCommandOption } from "discord-api-types";
import { getCommand, getOrLoadAllCommands } from "../handlers/commandHandler";
import { getBugReportButton, getDiscordInviteButton, getFeatureRequestButton } from "../helpers/messageHelpers";
import { NeedleCommand } from "../types/needleCommand";
import type { NeedleCommand } from "../types/needleCommand";

export const command: NeedleCommand = {
name: "help",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/title.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction, GuildMember, Permissions } from "discord.js";
import { type CommandInteraction, GuildMember, Permissions } from "discord.js";
import { interactionReply, getThreadStartMessage, getMessage } from "../helpers/messageHelpers";
import { NeedleCommand } from "../types/needleCommand";
import type { NeedleCommand } from "../types/needleCommand";

export const command: NeedleCommand = {
name: "title",
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/commandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CommandInteraction, MessageComponentInteraction } from "discord.js";
import { type CommandInteraction, type MessageComponentInteraction } from "discord.js";
import { promises } from "fs";
import { resolve as pathResolve } from "path";
import { getMessage, interactionReply } from "../helpers/messageHelpers";
import { NeedleCommand } from "../types/needleCommand";
import type { NeedleCommand } from "../types/needleCommand";

const COMMANDS_PATH = pathResolve(__dirname, "../commands");

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/interactionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Interaction } from "discord.js";
import type { Interaction } from "discord.js";
import { resetMessageContext, addMessageContext } from "../helpers/messageHelpers";
import { handleButtonClickedInteraction, handleCommandInteraction } from "./commandHandler";

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/messageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageActionRow, MessageButton, NewsChannel, TextChannel } from "discord.js";
import { type Message, MessageActionRow, MessageButton, NewsChannel, TextChannel } from "discord.js";
import { getConfig } from "../helpers/configHelpers";
import { getMessage, resetMessageContext, addMessageContext, isAutoThreadChannel } from "../helpers/messageHelpers";
import { getRequiredPermissions } from "../helpers/permissionHelpers";
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/configHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Client, Guild } from "discord.js";
import type { Client, Guild } from "discord.js";
import * as defaultConfig from "../config.json";
import { resolve as pathResolve } from "path";
import * as fs from "fs";
import { NeedleConfig } from "../types/needleConfig";
import type { NeedleConfig } from "../types/needleConfig";
import { MessageKey } from "./messageHelpers";

const CONFIGS_PATH = pathResolve(__dirname, "../../configs");
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/messageHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
BaseCommandInteraction,
Message,
type Message,
MessageButton,
MessageComponentInteraction,
TextBasedChannels,
type TextBasedChannel,
} from "discord.js";

import { MessageContext } from "../types/messageContext";
import { NeedleConfig } from "../types/needleConfig";
import type { MessageContext } from "../types/messageContext";
import type { NeedleConfig } from "../types/needleConfig";
import { getConfig } from "./configHelpers";

let context: MessageContext = {};
Expand All @@ -27,7 +27,7 @@ export function isAutoThreadChannel(channelId: string, guildId: string): boolean
return config?.threadChannels?.some(x => x?.channelId === channelId) ?? false;
}

export async function getThreadStartMessage(threadChannel: TextBasedChannels | null): Promise<Message | null> {
export async function getThreadStartMessage(threadChannel: TextBasedChannel | null): Promise<Message | null> {
if (!threadChannel?.isThread()) { return null; }
if (!threadChannel.parentId) { return null; }

Expand Down Expand Up @@ -75,7 +75,7 @@ export function interactionReply(
}

export function getMessage(messageKey: MessageKey, replaceVariables = true): string | undefined {
const config = getConfig(context?.interaction?.guildId);
const config = getConfig(context?.interaction?.guildId!);
if (!config.messages) { return ""; }

const message = config.messages[messageKey];
Expand Down
4 changes: 2 additions & 2 deletions src/types/messageContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CacheType, Interaction, Message, TextBasedChannels, User } from "discord.js";
import { CacheType, Interaction, Message, TextBasedChannel, User } from "discord.js";

export interface MessageContext {
interaction?: Interaction<CacheType>;
Expand All @@ -7,7 +7,7 @@ export interface MessageContext {
// Variables that can be used in messages (if they exist at the time of invocation)
// To use in message configuration, prefix with $ and convert name to SCREAMING_SNAKE_CASE
// For example, $TIME_AGO and $USER
channel?: TextBasedChannels;
channel?: TextBasedChannel;
user?: User;
timeAgo?: string;
}
2 changes: 1 addition & 1 deletion src/types/needleCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction, MessageComponentInteraction } from "discord.js";
import type { CommandInteraction, MessageComponentInteraction } from "discord.js";

export interface NeedleCommand {
name: string;
Expand Down

0 comments on commit 2ce78dd

Please sign in to comment.