Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
mandar1jn authored and astrobot-houston committed Nov 13, 2023
1 parent aec6f0c commit 6216637
Show file tree
Hide file tree
Showing 23 changed files with 679 additions and 645 deletions.
112 changes: 56 additions & 56 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
/** @type {import("@types/eslint").Linter.Config} */
module.exports = {
extends: [
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
// These off/configured-differently-by-default rules fit well for us
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-shadow': ['error'],
extends: [
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
// These off/configured-differently-by-default rules fit well for us
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-shadow': ['error'],

// We do want console statements occasionally (for example, used in error handling)
'no-console': 'off',
'no-console': 'off',

// Todo: do we want these?
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/class-literal-property-style': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-explicit-any': 'off',
// Todo: do we want these?
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/class-literal-property-style': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-explicit-any': 'off',

// These rules enabled by the preset configs don't work well for us
'@typescript-eslint/await-thenable': 'off',
'prefer-const': 'off',
},
// These rules enabled by the preset configs don't work well for us
'@typescript-eslint/await-thenable': 'off',
'prefer-const': 'off',
},
};
10 changes: 5 additions & 5 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
printWidth: 120,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
printWidth: 120,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Astro's own Houston, a bot made to provide support to our support team.

# How to build

To build, clone the repository and run `pnpm install` in the root directory to install all required dependencies.

After that, make a copy of [.env.example](.env.example) and rename it to `.env`. Then, fill out all the fields.
Expand Down
82 changes: 41 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
{
"name": "houston-bot",
"private": true,
"version": "1.0.0",
"description": "",
"main": "dist/app.js",
"type": "module",
"scripts": {
"build": "tsc --build --verbose",
"start": "node .",
"dev": "tsc && node .",
"preinstall": "npx only-allow pnpm",
"lint": "eslint . --report-unused-disable-directives",
"format": "pnpm run format:code",
"name": "houston-bot",
"private": true,
"version": "1.0.0",
"description": "",
"main": "dist/app.js",
"type": "module",
"scripts": {
"build": "tsc --build --verbose",
"start": "node .",
"dev": "tsc && node .",
"preinstall": "npx only-allow pnpm",
"lint": "eslint . --report-unused-disable-directives",
"format": "pnpm run format:code",
"format:ci": "pnpm run format:imports && pnpm run format:code",
"format:code": "prettier . -w --cache",
"format:code": "prettier . -w --cache",
"format:imports": "organize-imports-cli ./tsconfig.json"
},
"engines": {
"node": ">=18.18.0",
"pnpm": ">=8.6.12"
},
"packageManager": "[email protected]",
"dependencies": {
"@octokit/rest": "^20.0.2",
"algoliasearch": "^4.20.0",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"html-entities": "^2.4.0",
"node-schedule": "^2.1.1",
"organize-imports-cli": "^0.10.0"
},
"devDependencies": {
"@types/node": "^18.17.18",
"@types/node-schedule": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"license": "MIT"
},
"engines": {
"node": ">=18.18.0",
"pnpm": ">=8.6.12"
},
"packageManager": "[email protected]",
"dependencies": {
"@octokit/rest": "^20.0.2",
"algoliasearch": "^4.20.0",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"html-entities": "^2.4.0",
"node-schedule": "^2.1.1",
"organize-imports-cli": "^0.10.0"
},
"devDependencies": {
"@types/node": "^18.17.18",
"@types/node-schedule": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export default {
options: {
useTabs: false,
},
}
},
],
};
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from 'dotenv';

dotenv.config()
dotenv.config();

import("./client/client.js");
import('./client/client.js');
58 changes: 27 additions & 31 deletions src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
import discordjs, { Collection, REST, Routes, RESTPostAPIApplicationCommandsJSONBody, IntentsBitField } from "discord.js";
import fs from "node:fs";
import { Client, Command, Event, Scheduled } from "../types";
import { scheduleJob } from "node-schedule";

const client: Client = new discordjs.Client({intents: [
IntentsBitField.Flags.Guilds
]});
import discordjs, {
Collection,
IntentsBitField,
REST,
RESTPostAPIApplicationCommandsJSONBody,
Routes,
} from 'discord.js';
import { scheduleJob } from 'node-schedule';
import fs from 'node:fs';
import { Client, Command, Event, Scheduled } from '../types';

const client: Client = new discordjs.Client({ intents: [IntentsBitField.Flags.Guilds] });

client.commands = new Collection<string, any>();

const commandPath = new URL("../commands", import.meta.url);
const commandFiles = fs.readdirSync(commandPath).filter(file => file.endsWith(".js"));
const commandPath = new URL('../commands', import.meta.url);
const commandFiles = fs.readdirSync(commandPath).filter((file) => file.endsWith('.js'));

for(const file of commandFiles)
{
for (const file of commandFiles) {
const filePath = new URL(`../commands/${file}`, import.meta.url);
const command: Command = (await import(filePath.toString())).default;

if('data' in command && 'execute' in command)
{
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
}
else {
} else {
console.warn(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}

const rest = new REST({version: '10'}).setToken(process.env.DISCORD_TOKEN!);
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);

(async () => {
try {
const commands: RESTPostAPIApplicationCommandsJSONBody[] = [];

const commandList = Array.from<Command>(client.commands!.values());

for(const i in commandList)
{
for (const i in commandList) {
commands.push(commandList[i].data.toJSON());
}

console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data: any = await rest.put(
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID!),
{ body: commands },
);

const data: any = await rest.put(Routes.applicationCommands(process.env.DISCORD_CLIENT_ID!), { body: commands });

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();

const eventsPath = new URL("../events", import.meta.url);
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
const eventsPath = new URL('../events', import.meta.url);
const eventFiles = fs.readdirSync(eventsPath).filter((file) => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = new URL(`../events/${file}`, import.meta.url).toString();
Expand All @@ -66,8 +63,8 @@ for (const file of eventFiles) {
}
}

const scheduledPath = new URL("../scheduled", import.meta.url)
const scheduledFiles = fs.readdirSync(scheduledPath).filter(file => file.endsWith('.js'));
const scheduledPath = new URL('../scheduled', import.meta.url);
const scheduledFiles = fs.readdirSync(scheduledPath).filter((file) => file.endsWith('.js'));

for (const file of scheduledFiles) {
const filePath = new URL(`../scheduled/${file}`, import.meta.url).toString();
Expand All @@ -76,8 +73,7 @@ for (const file of scheduledFiles) {

scheduleJob(scheduled.time, async () => {
scheduled.execute(client);
})

});
}

client.login(process.env.DISCORD_TOKEN);
client.login(process.env.DISCORD_TOKEN);
22 changes: 12 additions & 10 deletions src/commands/ask.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
import { getDefaultEmbed } from "../utils/embeds.js";
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { getDefaultEmbed } from '../utils/embeds.js';

export default {
data: new SlashCommandBuilder()
.setName("ask")
.setDescription("Trigger a message on questions that should be reworded"),
.setName('ask')
.setDescription('Trigger a message on questions that should be reworded'),
async execute(interaction: ChatInputCommandInteraction) {
const embed = getDefaultEmbed()
.setTitle('Help us help you!')
.setDescription(
"Hey, I'm not sure how to answer your question. Here's some basic info that can help you provide the info we need to help you!\n\nhttps://hackmd.io/w9Sdod7HQTWYaZsaAcW44g"
);

const embed = getDefaultEmbed().setTitle("Help us help you!")
.setDescription("Hey, I'm not sure how to answer your question. Here's some basic info that can help you provide the info we need to help you!\n\nhttps://hackmd.io/w9Sdod7HQTWYaZsaAcW44g");;

interaction.reply({embeds: [embed], ephemeral: false});
}
}
interaction.reply({ embeds: [embed], ephemeral: false });
},
};
Loading

0 comments on commit 6216637

Please sign in to comment.