Skip to content

Commit

Permalink
chore: Add prettier and do stuff with it
Browse files Browse the repository at this point in the history
  • Loading branch information
gtm-nayan committed Dec 11, 2021
1 parent c76e69d commit b9918c7
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 144 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pnpm-lock.yaml
dist
18 changes: 9 additions & 9 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always",
"semi": true,
"useTabs": false,
"tabWidth": 4
}
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always",
"semi": true,
"useTabs": true,
"tabWidth": 4
}
8 changes: 4 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"christian-kohler.npm-intellisense",
]
"recommendations": [
"esbenp.prettier-vscode",
"christian-kohler.npm-intellisense"
]
}
22 changes: 11 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ something can go here
# Running for development

1. Once you have the bot cloned and have run `pnpm install` then you need to make a .env file and fill out the fields:

```sh
cp .env.example .env
```
Expand Down
56 changes: 29 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{
"name": "svelte-bot",
"private": true,
"version": "0.0.0",
"main": "dist/index.js",
"scripts": {
"build": "rimraf dist && tsc",
"dev": "rimraf dist && run-p dev:*",
"dev:tsc": "tsc -w --preserveWatchOutput",
"dev:nodemon": "nodemon .",
"start": "node ."
},
"license": "MIT",
"dependencies": {
"@types/nice-try": "^2.1.0",
"@types/node": "^16.11.12",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0",
"jellycommands": "^1.0.0-12",
"nice-try": "^3.0.0",
"rimraf": "^3.0.2",
"typescript": "^4.5.3",
"url-regex": "^5.0.0"
},
"devDependencies": {
"nodemon": "^2.0.15",
"npm-run-all": "^4.1.5"
}
"name": "svelte-bot",
"private": true,
"version": "0.0.0",
"main": "dist/index.js",
"scripts": {
"build": "rimraf dist && tsc",
"dev": "rimraf dist && run-p dev:*",
"dev:tsc": "tsc -w --preserveWatchOutput",
"format": "prettier --write --plugin-search-dir=. .",
"dev:nodemon": "nodemon .",
"start": "node ."
},
"license": "MIT",
"dependencies": {
"@types/nice-try": "^2.1.0",
"@types/node": "^16.11.12",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0",
"jellycommands": "^1.0.0-12",
"nice-try": "^3.0.0",
"rimraf": "^3.0.2",
"typescript": "^4.5.3",
"url-regex": "^5.0.0"
},
"devDependencies": {
"nodemon": "^2.0.15",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1"
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { command } from 'jellycommands';

export default command({
name: 'test',
description: 'Testing that the bot works fine',
name: 'test',
description: 'Testing that the bot works fine',

global: true,
dev: true,
global: true,
dev: true,

run: ({ interaction }) =>
interaction.reply({ embeds: [{ description: 'Hello World!' }] }),
run: ({ interaction }) =>
interaction.reply({ embeds: [{ description: 'Hello World!' }] }),
});
102 changes: 51 additions & 51 deletions src/events/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,72 @@ import niceTry from 'nice-try';

// TODO discuss best way to store these ids
const linkOnlyChannels = [
// Testing Channel
'918915215368810566',
// Testing Channel
'918915215368810566',

// Showcase
'479653552869081089',
// Showcase
'479653552869081089',

// Resources
'837012201444999248',
// Resources
'837012201444999248',
];

const autoThreadChannels = [
// testing
'918932662226386994',
// testing
'918932662226386994',

// Showcase
'479653552869081089',
// Showcase
'479653552869081089',

// Resources
'837012201444999248',
// Resources
'837012201444999248',
];

export default event({
name: 'messageCreate',
name: 'messageCreate',

run: async ({}, message) => {
if (message.author.bot) return;
run: async ({}, message) => {
if (message.author.bot) return;

if (linkOnlyChannels.includes(message.channel.id)) {
const hasLink = urlRegex().test(message.content);
if (linkOnlyChannels.includes(message.channel.id)) {
const hasLink = urlRegex().test(message.content);

if (!hasLink) {
try {
if (message.deletable) await message.delete();
if (!hasLink) {
try {
if (message.deletable) await message.delete();

await message.author.send({
embeds: [
{
description: `Your message in ${message.channel.toString()} was removed since it doesn't contain a link, if you are trying to showcase a project please post a link with your text. Otherwise all conversation should be inside a thread\n\nYour message was sent below so you don't lose it!`,
},
],
});
await message.author.send({
embeds: [
{
description: `Your message in ${message.channel.toString()} was removed since it doesn't contain a link, if you are trying to showcase a project please post a link with your text. Otherwise all conversation should be inside a thread\n\nYour message was sent below so you don't lose it!`,
},
],
});

await message.author.send({
content: message.content,
});
} catch {
// this will fail if message is already deleted but we don't know or if the dm can't be sent - either way we don't need to do anything
}
await message.author.send({
content: message.content,
});
} catch {
// this will fail if message is already deleted but we don't know or if the dm can't be sent - either way we don't need to do anything
}

return;
}
}
return;
}
}

if (
autoThreadChannels.includes(message.channel.id) &&
!message.hasThread &&
message.channel.type == 'GUILD_TEXT'
) {
try {
message.channel.threads.create({
name: 'Discussion',
startMessage: message,
});
} catch {
// we can ignore this error since chances are it will be that thread already exists
}
}
},
if (
autoThreadChannels.includes(message.channel.id) &&
!message.hasThread &&
message.channel.type == 'GUILD_TEXT'
) {
try {
message.channel.threads.create({
name: 'Discussion',
startMessage: message,
});
} catch {
// we can ignore this error since chances are it will be that thread already exists
}
}
},
});
4 changes: 2 additions & 2 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { event } from 'jellycommands';

export default event({
name: 'ready',
run: () => console.log('Bot is online!'),
name: 'ready',
run: () => console.log('Bot is online!'),
});
30 changes: 15 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import { JellyCommands } from 'jellycommands';
import { Intents } from 'discord.js';

const client = new JellyCommands({
commands: 'dist/commands',
events: 'dist/events',
commands: 'dist/commands',
events: 'dist/events',

clientOptions: {
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
],
},
clientOptions: {
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
],
},

dev: {
// If we set dev to true in a command it disabled global and adds it to the guilds bellow
guilds: ['918887934822858802'],
},
dev: {
// If we set dev to true in a command it disabled global and adds it to the guilds bellow
guilds: ['918887934822858802'],
},

// we can disable this but I like to see the debug messages xD - GHOST
debug: true,
// we can disable this but I like to see the debug messages xD - GHOST
debug: true,
});

// Auto reads the DISCORD_TOKEN environment variable
Expand Down
38 changes: 19 additions & 19 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"outDir": "./dist",
"lib": ["ES2020"],
"moduleResolution": "node",
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"outDir": "./dist",
"lib": ["ES2020"],
"moduleResolution": "node",

"strict": true,
"declaration": false,
"strictNullChecks": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"allowJs": true
},
"include": ["src/**/*"],
"exclude": ["dist"]
"strict": true,
"declaration": false,
"strictNullChecks": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"allowJs": true
},
"include": ["src/**/*"],
"exclude": ["dist"]
}

0 comments on commit b9918c7

Please sign in to comment.