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

feat: add CI #84

Merged
merged 20 commits into from
Apr 7, 2022
Merged
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: 26 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": ["@commitlint/config-angular"],
"rules": {
"scope-case": [2, "always", "pascal-case"],
"type-enum": [
2,
"always",
[
"chore",
"build",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
"types",
"workflow",
"wip"
]
]
}
}
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,ts}]
indent_size = 4
indent_style = tab
block_comment_start = /*
block_comment = *
block_comment_end = */

[*.{md}]
tab_width = 4
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@sapphire"
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
22 changes: 22 additions & 0 deletions .github/problemMatchers/eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"problemMatcher": [
{
"owner": "eslint-stylish",
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": 1
},
{
"regexp": "^\\s+(\\d+):(\\d+)\\s+(error|warning|info)\\s+(.*)\\s\\s+(.*)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
}
]
}
17 changes: 17 additions & 0 deletions .github/problemMatchers/tsc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "tsc",
"pattern": [
{
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
}
]
}
]
}
46 changes: 46 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Continuous Integration

on:
push:
branches:
- main
pull_request:

jobs:
Linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2
- name: Add problem matcher
run: echo "::add-matcher::.github/problemMatchers/eslint.json"
- name: Use Node.js v16
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561 # renovate: tag=v2
with:
node-version: 16
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
run: yarn --immutable
- name: Run ESLint
run: yarn lint --fix=false

Building:
name: Compile source code
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2
- name: Add problem matcher
run: echo "::add-matcher::.github/problemMatchers/tsc.json"
- name: Use Node.js v16
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561 # renovate: tag=v2
with:
node-version: 16
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
run: yarn --immutable
- name: Build Code
run: yarn build
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{mjs,js,ts}": "eslint --fix --ext mjs,js,ts",
"*.{json,yml,yaml}": "prettier --write"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["bierner.github-markdown-preview", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"eslint.validate": ["typescript"],
"editor.tabSize": 4,
"editor.useTabStops": true,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"files.eol": "\n",
"typescript.tsdk": "node_modules\\typescript\\lib"
}
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"update": "yarn up \"*\" -i",
"clean": "node scripts/clean-dist.mjs",
"build": "yarn clean && tsup && tsc --p tsconfig.lang.json",
"lint": "eslint --ext mjs,js,ts",
"lint:fix": "eslint --ext mjs,js,ts --fix",
"lint": "eslint src scripts --ext mjs,ts --fix",
"format": "prettier --write **/*.{ts,js,json,yml,yaml}",
"prepare": "husky install",
"start": "yarn build && node dist/sharder.mjs"
},
"repository": {
Expand Down Expand Up @@ -48,9 +48,18 @@
"ytdl-core": "^4.10.1"
},
"devDependencies": {
"@commitlint/config-angular": "^16.2.3",
"@sapphire/eslint-config": "^4.3.2",
"@sapphire/ts-config": "^3.3.3",
"@types/common-tags": "^1.8.1",
"@types/eslint": "^8",
"@types/node": "^17.0.17",
"@types/prettier": "^2",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"prettier": "^2.5.1",
"prisma": "^3.11.1",
"tsup": "^5.12.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/clean-dist.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(await import("fs/promises")).rm(new URL("../dist", import.meta.url), { recursive: true, force: true });
(await import("fs/promises")).rm(new URL("../dist", import.meta.url), {recursive: true, force: true});
36 changes: 18 additions & 18 deletions src/augment.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Player } from "discord-player";
export * from "@sapphire/pieces";
declare module "@sapphire/pieces" {
export interface Container {
player: Player;
}
}
declare global {
namespace NodeJS {
interface ProcessEnv {
GUILD: string;
OWNER: string;
CONSOLE_URL: string;
}
}
}
import {Player} from "discord-player";

export * from "@sapphire/pieces";
declare module "@sapphire/pieces" {
export interface Container {
player: Player;
}
}

declare global {
namespace NodeJS {
interface ProcessEnv {
GUILD: string;
OWNER: string;
CONSOLE_URL: string;
}
}
}
32 changes: 16 additions & 16 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {config} from "dotenv";
import {Player} from "discord-player";
import {Logger} from "./logger";
import {container, LogLevel, SapphireClient} from "@sapphire/framework";
import "@sapphire/plugin-logger/register";
import "@sapphire/plugin-i18next/register";
import "./container";
config();
const client = new SapphireClient({
intents: ["GUILDS", "GUILD_VOICE_STATES"]
});
container.player = new Player(client);
container.logger = new Logger(container, {level: LogLevel.Debug});
client.login(process.env.TOKEN);
import {config} from "dotenv";
import {Player} from "discord-player";
import {Logger} from "./logger";
import {container, LogLevel, SapphireClient} from "@sapphire/framework";
import "@sapphire/plugin-logger/register";
import "@sapphire/plugin-i18next/register";
import "./container";
config();

const client = new SapphireClient({
intents: ["GUILDS", "GUILD_VOICE_STATES"]
});
container.player = new Player(client);
container.logger = new Logger(container, {level: LogLevel.Debug});

void client.login(process.env.TOKEN);
55 changes: 29 additions & 26 deletions src/commands/clear.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { ApplyOptions } from "@sapphire/decorators";
import { ApplicationCommandRegistry, Command, CommandOptions } from "@sapphire/framework";
import { CommandInteraction, MessageEmbed } from "discord.js";
@ApplyOptions<CommandOptions>({
description: "clear the queue",
preconditions: ["GuildOnly", "BotInVoice", "InSameVoice"]
})
export class ClearCommand extends Command {
public registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand(new SlashCommandBuilder().setName(this.name).setDescription(this.description));
}
public async chatInputRun(interaction: CommandInteraction) {
await interaction.deferReply();
this.container.player.getQueue(interaction.guild!).clear();
interaction.editReply({
embeds: [
new MessageEmbed({
color: "GREEN",
title: this.container.getTranslation(interaction, "commands/clear:success.title"),
description: this.container.getTranslation(interaction, "commands/clear:success.description")
})
]
});
}
}
import {SlashCommandBuilder} from "@discordjs/builders";
import {ApplyOptions} from "@sapphire/decorators";
import {ApplicationCommandRegistry, Command, CommandOptions} from "@sapphire/framework";
import {CommandInteraction, MessageEmbed} from "discord.js";
@ApplyOptions<CommandOptions>({
description: "clear the queue",
preconditions: ["GuildOnly", "BotInVoice", "InSameVoice"]
})
export class ClearCommand extends Command {
public registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand(
new SlashCommandBuilder().setName(this.name).setDescription(this.description)
);
}

public async chatInputRun(interaction: CommandInteraction) {
await interaction.deferReply();
this.container.player.getQueue(interaction.guild!).clear();
return interaction.editReply({
embeds: [
new MessageEmbed({
color: "GREEN",
title: this.container.getTranslation(interaction, "commands/clear:success.title"),
description: this.container.getTranslation(interaction, "commands/clear:success.description")
})
]
});
}
}
Loading