Skip to content

Commit

Permalink
Typescript (#5)
Browse files Browse the repository at this point in the history
* import/export

* eslint && prettier

* ts

* ts

* uh

* Code

* Types

* code i think

* works

* Swap fetch packages

* lint fixs

* Event Logging

* Fixes

* Compile/build changes

* bump deps

* add missing package

* prettier
  • Loading branch information
Kathund authored Jan 29, 2024
1 parent bd0d1ae commit 68b8336
Show file tree
Hide file tree
Showing 43 changed files with 2,126 additions and 2,630 deletions.
32 changes: 14 additions & 18 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:import/recommended"],
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended"
],
"env": { "commonjs": true, "es2021": true, "node": true },
"parserOptions": { "ecmaVersion": "latest" },
"plugins": [ "@typescript-eslint" ],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest"
},
"globals": {
"client": true,
"uptime": true
},
"rules": {
"curly": ["error", "multi-line", "consistent"],
"no-unused-vars": ["error", { "args": "none" }],
"prefer-const": ["warn", { "destructuring": "all" }],
"no-constant-condition": ["error", { "checkLoops": false }],
"import/extensions": ["error", "always", { "ts": "never" }],
"curly": [ "error", "multi-line", "consistent" ],
"@typescript-eslint/no-explicit-any": "off",
"no-template-curly-in-string": "error",
"no-use-before-define": "error",
"import/no-unresolved": "off",
"no-duplicate-case": "error",
"no-throw-literal": "error",
"no-self-compare": "error",
"no-unreachable": "error",
"sort-imports": "error",
"no-unused-vars": "error",
"prefer-const": "error",
"no-console": "error",
"sort-vars": "error",
"no-empty": "error",
Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
**Changes**

<!-- Please explain the changes that you have made -->

- [ ] I've added new features
- [ ] I've fixed bug. (_optional_ you can mention a issue if there is one)
- [ ] I've corrected the spelling in README, documentation, etc.
- [ ] I've fixed my eslint errors. (`npm run lint`)
- [ ] I've fixed my formatting. (`npm run prettier`)
- [ ] I've made sure it builds. (`npm run build`)
20 changes: 20 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ jobs:

- name: prettier
run: npm run prettier:check

build:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install node dependencies
run: npm i

- name: Copy Config
run: cp config.example.json config.json

- name: Test Build
run: npm run build
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/config.json
node_modules/
package-lock.json
a.js
b.js
.VSCodeCounter/
logs/
logs/
dist/
53 changes: 0 additions & 53 deletions deploy-commands.js

This file was deleted.

99 changes: 0 additions & 99 deletions index.js

This file was deleted.

21 changes: 21 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { deployCommands } from './src/functions/deployCommands';
import { Client, Events, GatewayIntentBits } from 'discord.js';
import { execute } from './src/events/ready';
import { discord } from './config.json';

const client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.Guilds,
],
});

deployCommands(client);

client.on(Events.ClientReady, () => {
execute(client);
});

client.login(discord.token);
42 changes: 24 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,39 @@
"name": "wynntools-utils",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "index.ts",
"types": "src/types/main.d.ts",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"lint:check": "npx eslint .",
"lint": "npx eslint . --fix",
"prettier": "npx prettier --write .",
"prettier:check": "npx prettier --check ."
"start": "npx tsx index.ts",
"lint:check": "npx eslint src/ index.ts",
"lint": "npx eslint src/ index.ts --fix",
"prettier": "npx prettier --write src/ index.ts",
"prettier:check": "npx prettier --check src/ index.ts",
"build": "npx tsc --build"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"cli-color": "^2.0.3",
"discord.js": "^14.13.0",
"fs-extra": "^11.1.1",
"axios": "^1.6.7",
"discord.js": "^14.14.1",
"fs-extra": "^11.2.0",
"mkdirp": "^3.0.1",
"node-cron": "^3.0.2",
"node-fetch": "^3.3.2",
"winston": "^3.10.0"
"node-cron": "^3.0.3",
"winston": "^3.11.0"
},
"devDependencies": {
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.40.0",
"eslint-config-prettier": "^9.0.0",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.14.202",
"@types/node-cron": "^3.0.11",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-import": "^2.27.5",
"prettier": "3.0.3"
"eslint-plugin-import": "^2.29.1",
"prettier": "^3.2.4",
"tsx": "^4.7.0",
"typescript": "^5.3.3"
}
}
64 changes: 64 additions & 0 deletions src/commands/about.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
ChatInputCommandInteraction,
SlashCommandBuilder,
ActionRowBuilder,
ColorResolvable,
ButtonBuilder,
EmbedBuilder,
ButtonStyle,
} from 'discord.js';
import { generateID, cleanMessage } from '../functions/helper';
import { errorMessage } from '../functions/logger';
import { discord, other } from '../../config.json';
import { version } from '../../package.json';

export const data = new SlashCommandBuilder()
.setName('about')
.setDescription('Shows info about the bot')
.setDMPermission(false);

export const execute = async (interaction: ChatInputCommandInteraction) => {
try {
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setLabel('source').setURL('https://github.com/Kathund/WynnTools').setStyle(ButtonStyle.Link),
new ButtonBuilder().setLabel('support').setURL(discord.supportInvite).setStyle(ButtonStyle.Link),
new ButtonBuilder().setLabel('invite').setURL(discord.botInvite).setStyle(ButtonStyle.Link)
);
const embed = new EmbedBuilder()
.setTitle(`WynnTools Utils Stats`)
.setColor(other.colors.green.hex as ColorResolvable)
.setTimestamp()
.setDescription(
'WynnTools - A bot that does stuff with the wynncraft api - The Only bot that uses images **that i have seen**'
)
.addFields({
name: 'General',
value: `<:Dev:1130772126769631272> Developer - \`@kathund\`\n<:bullet:1064700156789927936> Version \`${version}\`\nUptime - <t:${Math.floor(
(Date.now() - interaction.client.uptime) / 1000
)}:R>`,
inline: true,
})
.setFooter({
text: `by @kathund | ${discord.supportInvite} for support`,
iconURL: other.logo,
});
await interaction.reply({ embeds: [embed], components: [row] });
} catch (error: any) {
const errorId = generateID(other.errorIdLength);
errorMessage(`Error Id - ${errorId}`);
errorMessage(error);
const errorEmbed = new EmbedBuilder()
.setColor(other.colors.red.hex as ColorResolvable)
.setTitle('An error occurred')
.setDescription(
`Use </report-bug:${
discord.commands['report-bug']
}> to report it\nError id - ${errorId}\nError Info - \`${cleanMessage(error)}\``
)
.setFooter({ text: `by @kathund | ${discord.supportInvite} for support`, iconURL: other.logo });
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setLabel('Support Discord').setURL(discord.supportInvite).setStyle(ButtonStyle.Link)
);
await interaction.reply({ embeds: [errorEmbed], components: [row] });
}
};
Loading

0 comments on commit 68b8336

Please sign in to comment.