Skip to content

Commit

Permalink
Refactor with eslint chagnes
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickrizzardi committed Aug 13, 2023
1 parent 152c3a1 commit ba49604
Show file tree
Hide file tree
Showing 27 changed files with 2,638 additions and 1,214 deletions.
332 changes: 282 additions & 50 deletions .eslintrc

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"singleQuote": true,
"tabWidth": 2,
"semi": true,
"printWidth": 160,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always",
"bracketSameLine": false,
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": true,
"embeddedLanguageFormatting": "auto",
"singleAttributePerLine": true
}
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
FROM node:20.0-bullseye-slim as development

ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
ENV USER node

RUN echo "NODE_ENV=${NODE_ENV}"

# Install the required packages
RUN apt update && apt upgrade -y && apt install -y --no-install-recommends \
vim \
Expand Down
35 changes: 25 additions & 10 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
require('dotenv').config();
import { CronJob } from 'cron';
import { processClanData } from './app/processClanData';
import { Discord } from './app/utils/discord';
import schedule from './app/utils/schedule';
import { Client } from 'discord.js';
import log from './app/utils/log';
import config from './app/config/config';
import { intents } from './app/utils/discordIntents';
import { clientReadyEvent } from './app/events/clientReady';
import { errorEvent } from './app/events/error';
import { messageCreateEvent } from './app/events/messageCreate';
import { config } from './app/config/index.config';

log.info(`Starting clash of clans app on ${config.get('env')} environment`);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async (): Promise<void> => {
try {
log.info(`Starting ${config.get('app.name')} on ${config.get('app.env')} environment`);

const job = new CronJob(schedule.everyFiveMinutes, processClanData);
const discordClient = new Client({ intents });

new Discord(true);
clientReadyEvent(discordClient);

job.start();
messageCreateEvent(discordClient);

errorEvent(discordClient);

log.info(config.get('discord.token'));

await discordClient.login(config.get('discord.token'));

// New Discord(true);
} catch (error) {
log.error('Error:', error);
}
})();
77 changes: 0 additions & 77 deletions app/config/config.ts

This file was deleted.

36 changes: 36 additions & 0 deletions app/config/database.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const database = {
user: {
doc: 'The database user.',
format: String,
default: 'app',
env: 'DATABASE_USER',
sensitive: true,
},
password: {
doc: 'The database password.',
format: String,
default: 'password',
env: 'DATABASE_PASSWORD',
sensitive: true,
},
name: {
doc: 'The database name.',
format: String,
default: 'zerowars',
env: 'CLASH_OF_CLANS_DATABASE_NAME',
},
port: {
doc: 'The database port.',
format: 'port',
default: 3306,
env: 'DATABASE_PORT',
sensitive: true,
},
host: {
doc: 'The database host.',
format: String,
env: 'DATABASE_HOST',
default: 'localhost',
sensitive: true,
},
};
45 changes: 45 additions & 0 deletions app/config/index.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import convict from 'convict';
import { log } from './log.config';
import { database } from './database.config';
import 'dotenv/config';

const config = convict({
app: {
env: {
doc: 'The application environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV',
},
name: {
doc: 'The application name.',
format: String,
default: 'Clash of Clans Bot',
env: 'APP_NAME',
},
},
log,
database,
clashOfClans: {
apiKey: {
doc: 'The Clash of Clans API key.',
format: String,
default: '',
env: 'CLASH_OF_CLANS_API_KEY',
sensitive: true,
},
},
discord: {
token: {
doc: 'The Discord bot token.',
format: String,
default: '',
env: 'CLASH_OF_CLANS_DISCORD_TOKEN',
sensitive: true,
},
},
});

config.validate({ allowed: 'strict' });

export { config };
31 changes: 31 additions & 0 deletions app/config/log.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from 'path';

export const log = {
level: {
doc: 'The log level to use. This only applies to when the environment is set to production or development',
format: ['info', 'warn', 'error', 'critical'],
default: 'info',
env: 'LOG_LEVEL',
},
transports: {
doc: 'The transports to use for logging. This only applies to when the environment is set to production or development',
format: String,
default: "'console', 'file'",
env: 'LOG_TRANSPORTS',
},
file: {
doc: 'The file name to use for logging. This only applies to when the environment is set to production or development, and the file transport is enabled',
format: String,
default: path.join(__dirname, '../../storage/logs/info.log'),
env: 'LOG_FILE',
},
datadog: {
apiKey: {
doc: 'The api key to use for datadog logging. This only applies to when the environment is set to production or development, and the datadog transport is enabled',
format: String,
default: 'secret',
env: 'LOG_DATADOG_API_KEY',
sensitive: true,
},
},
};
44 changes: 5 additions & 39 deletions app/database/models/Clan.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Model, DataTypes, Optional } from 'sequelize';
import type { Optional } from 'sequelize';
import { DataTypes, Model } from 'sequelize';
import ClanMember from './ClanMember.model';
import { sequelize } from './index';

export interface ClanAttributes {
id: number;
tag: string;
Expand Down Expand Up @@ -30,7 +32,7 @@ export interface ClanAttributes {
updatedAt: Date;
}

interface ClanCreationAttributes extends Optional<ClanAttributes, 'id' | 'createdAt' | 'updatedAt'> {}
type ClanCreationAttributes = Optional<ClanAttributes, 'createdAt' | 'id' | 'updatedAt'>;

export default class Clan extends Model<ClanAttributes, ClanCreationAttributes> implements ClanAttributes {
declare readonly id: ClanAttributes['id'];
Expand Down Expand Up @@ -85,7 +87,7 @@ export default class Clan extends Model<ClanAttributes, ClanCreationAttributes>

declare readonly updatedAt: ClanAttributes['updatedAt'];

declare readonly members: ClanMember[];
declare readonly members: Array<ClanMember>;
}

Clan.init(
Expand Down Expand Up @@ -115,22 +117,10 @@ Clan.init(
location: {
type: DataTypes.TEXT,
allowNull: false,
set(val: string) {
this.setDataValue('location', JSON.stringify(val));
},
get() {
return JSON.parse(this.getDataValue('location'));
},
},
badgeUrls: {
type: DataTypes.TEXT,
allowNull: false,
set(val) {
this.setDataValue('badgeUrls', JSON.stringify(val));
},
get() {
return JSON.parse(this.getDataValue('badgeUrls'));
},
},
clanLevel: {
type: DataTypes.INTEGER,
Expand Down Expand Up @@ -175,12 +165,6 @@ Clan.init(
warLeague: {
type: DataTypes.TEXT,
allowNull: false,
set(val) {
this.setDataValue('warLeague', JSON.stringify(val));
},
get() {
return JSON.parse(this.getDataValue('warLeague'));
},
},
memberCount: {
type: DataTypes.INTEGER,
Expand All @@ -189,12 +173,6 @@ Clan.init(
labels: {
type: DataTypes.TEXT,
allowNull: false,
set(val) {
this.setDataValue('labels', JSON.stringify(val));
},
get() {
return JSON.parse(this.getDataValue('labels'));
},
},
requiredVersusTrophies: {
type: DataTypes.INTEGER,
Expand All @@ -207,22 +185,10 @@ Clan.init(
clanCapital: {
type: DataTypes.TEXT,
allowNull: false,
set(val) {
this.setDataValue('clanCapital', JSON.stringify(val));
},
get() {
return JSON.parse(this.getDataValue('clanCapital'));
},
},
chatLanguage: {
type: DataTypes.TEXT,
allowNull: false,
set(val) {
this.setDataValue('chatLanguage', JSON.stringify(val));
},
get() {
return JSON.parse(this.getDataValue('chatLanguage'));
},
},
createdAt: {
allowNull: false,
Expand Down
Loading

0 comments on commit ba49604

Please sign in to comment.