Skip to content

Commit

Permalink
chore: remove some webhook stuff and update prod docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyko committed Nov 10, 2023
1 parent cbde246 commit a5ddef9
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 60 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ Help us translate Thoth in the top 30 languages over at our [Crowdin Project](ht

## Terms of Service

1. Thoth is provided as-is. Uptime, compatibility, and functionality is not guaranteed.
Moved to [TERMS_OF_SERVICE.md](./legal/TERMS_OF_SERVICE.md)

## Privacy Policy

_Note_: Thoth does not have or need a database!

1. Configuration data is saved indefinitely. The application uses IDs whenever possible.
2. Debug logs to improve the flow the app may be employed temporarily and may log any data necessary. Log entries of any kind do not persist.
3. Errors logs to improve the flow of the app will log any data deemed necessary to resolve errors. Error entries are stored, and discarded once resolved.
4. Thoth may store anonymous analytics including, but not limited to, which command was executed, the ID of the user who executed it, the ID of the server it was executed in (if applicable), the locale (language settings) of the relevant user or server, and error logs.
5. Thoth does not log or otherwise make data visible outside of the application's purpose.
Moved to [PRIVACY_POLICY.md](./legal/PRIVACY_POLICY.md)
49 changes: 28 additions & 21 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,15 @@ services:
thoth:
image: ghcr.io/fyko/thoth:latest
ports:
- '2399:2399'
- '21983:21983'
restart: unless-stopped
env_file:
- ./.env.prod
labels:
- 'com.centurylinklabs.watchtower.enable=true'

gateway:
image: twilightrs/gateway-queue
environment:
HOST: '0.0.0.0'
PORT: '2398'
DISCORD_TOKEN: ${DISCORD_TOKEN}
env_file:
- ./.env.prod
ports:
- '2398:2398'

thothd:
image: ghcr.io/fyko/thothd:latest
volumes:
- ./thothd/thothd.toml:/thothd.toml
restart: unless-stopped
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:21983/health']
interval: 10s
timeout: 5s
retries: 5
labels:
- 'com.centurylinklabs.watchtower.enable=true'

Expand All @@ -37,13 +23,25 @@ services:
POSTGRES_USER: 'admin'
POSTGRES_PASSWORD: 'doctordoctor'
POSTGRES_DB: 'thoth'
ports:
- '5432:5432'
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'admin']
interval: 10s
timeout: 5s
retries: 5
volumes:
- postgres-storage:/var/lib/postgresql/data
restart: unless-stopped

redis:
image: redis:alpine
restart: unless-stopped
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 10s
timeout: 5s
retries: 5
ports:
- '6379:6379'

Expand All @@ -52,6 +50,11 @@ services:
context: ./docker/prometheus
restart: unless-stopped
command: --config.file=/etc/prometheus/prometheus.yml --log.level=debug
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:9090/-/healthy']
interval: 10s
timeout: 5s
retries: 5
ports:
- 9090:9090
volumes:
Expand All @@ -64,11 +67,15 @@ services:
environment:
GF_SERVER_DOMAIN: ${GF_SERVER_DOMAIN}
GF_SERVER_ROOT_URL: ${GF_SERVER_ROOT_URL}
GF_SERVE_FROM_SUB_PATH: 'true'
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: admin
GF_USERS_ALLOW_SIGN_UP: 'false'
GF_AUTH_ANONYMOUS_ENABLED: 'false'
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/']
interval: 10s
timeout: 5s
retries: 5
env_file:
- ./.env.prod
ports:
Expand Down
5 changes: 1 addition & 4 deletions src/events/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { injectable } from 'tsyringe';
import { logger } from '#logger';

Expand All @@ -12,8 +11,6 @@ export default class implements Event {

public constructor(private readonly client: Client<true>) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (message) => {
logger.debug(message);
Expand Down
6 changes: 5 additions & 1 deletion src/events/guildCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export default class implements Event {
@inject(kGuildCountGuage) private readonly guildCount: Gauge<string>,
) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });
public webhook = new WebhookClient({ url: process.env.GUILD_LOG_WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (guild) => {
logger.info({ guildId: guild.id }, `Joined guild ${guild.name}`);
this.guildCount.inc();

this.webhook.send({
content: `Joined guild ${guild.name} (${guild.id})`,
});
});
}
}
6 changes: 5 additions & 1 deletion src/events/guildDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export default class implements Event {
@inject(kGuildCountGuage) private readonly guildCount: Gauge<string>,
) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });
public webhook = new WebhookClient({ url: process.env.GUILD_LOG_WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (guild) => {
logger.info({ guildId: guild.id }, `Left guild ${guild.name}`);
this.guildCount.dec();

this.webhook.send({
content: `Left guild ${guild.name} (${guild.id})`,
});
});
}
}
21 changes: 20 additions & 1 deletion src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import process from 'node:process';
import type { Command } from '@yuudachi/framework';
import { transformApplicationInteraction, kCommands } from '@yuudachi/framework';
import type { Event } from '@yuudachi/framework/types';
import { ApplicationCommandType, Client, Events } from 'discord.js';
import { stripIndents } from 'common-tags';
import { ApplicationCommandType, Client, Events, WebhookClient } from 'discord.js';
import { Counter } from 'prom-client';
import { inject, injectable } from 'tsyringe';
import { logger } from '#logger';
Expand All @@ -18,6 +20,8 @@ export default class implements Event {

public event = Events.InteractionCreate as const;

public webhook = new WebhookClient({ url: process.env.COMMAND_LOG_WEBHOOK_URL! });

public constructor(
public readonly client: Client<true>,
@inject(kCommands) public readonly commands: Map<string, Command>,
Expand All @@ -36,6 +40,21 @@ export default class implements Event {

if (command) {
try {
const args_ = interaction.options.data.map(
// @ts-expect-error i know it works
({ name, value }: { name: string; value: any }) => `\`${name}\`: \`${value}\``,
);

void this.webhook.send({
content: stripIndents`
Command \`${interaction.commandName}\` (\`${interaction.commandId}\`) executed by ${interaction.user.tag} (\`${
interaction.user.id
}\`)
Arguments: ${args_.join('; ')}
`,
});

if (interaction.commandType === ApplicationCommandType.ChatInput) {
logger.info(
{ command: { name: interaction.commandName, type: interaction.type }, userId: interaction.user.id },
Expand Down
5 changes: 1 addition & 4 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { Gauge } from 'prom-client';
import { inject, injectable } from 'tsyringe';
import { logger } from '#logger';
Expand All @@ -17,8 +16,6 @@ export default class implements Event {
@inject(kGuildCountGuage) private readonly guildCount: Gauge<string>,
) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async () => {
logger.info(`Client is ready! Logged in as ${this.client.user!.tag}}`);
Expand Down
5 changes: 1 addition & 4 deletions src/events/shard/disconnect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { injectable } from 'tsyringe';
import { logger } from '#logger';

Expand All @@ -12,8 +11,6 @@ export default class implements Event {

public constructor(private readonly client: Client<true>) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (event, id) => {
logger.warn(event, `Shard ${id} closed!`);
Expand Down
5 changes: 1 addition & 4 deletions src/events/shard/error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { injectable } from 'tsyringe';
import { logger } from '#logger';

Expand All @@ -12,8 +11,6 @@ export default class implements Event {

public constructor(private readonly client: Client<true>) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (error, id) => {
logger.error(error, `Shard ${id} errored!`);
Expand Down
5 changes: 1 addition & 4 deletions src/events/shard/ready.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { injectable } from 'tsyringe';
import { logger } from '#logger';

Expand All @@ -12,8 +11,6 @@ export default class implements Event {

public constructor(private readonly client: Client<true>) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (id) => {
logger.info({ shardId: id }, `Shard ${id} is ready!`);
Expand Down
5 changes: 1 addition & 4 deletions src/events/shard/reconnecting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { injectable } from 'tsyringe';
import { logger } from '#logger';

Expand All @@ -12,8 +11,6 @@ export default class implements Event {

public constructor(private readonly client: Client<true>) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (id) => {
logger.warn(`Shard ${id} reconnecting...`);
Expand Down
5 changes: 1 addition & 4 deletions src/events/shard/resume.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import type { Event } from '@yuudachi/framework/types';
import { Client, Events, WebhookClient } from 'discord.js';
import { Client, Events } from 'discord.js';
import { injectable } from 'tsyringe';
import { logger } from '#logger';

Expand All @@ -12,8 +11,6 @@ export default class implements Event {

public constructor(private readonly client: Client<true>) {}

public webhook = new WebhookClient({ url: process.env.WEBHOOK_URL! });

public execute(): void {
this.client.on(this.event, async (id, count) => {
logger.warn(`Shard ${id} resuming! Replaying ${count} events...`);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ await server.register(fastifyMetrics, {
} as IMetricsPluginOptions);
server.get('/terms', (_req, res) => res.redirect(301, process.env.TERMS_URL));
server.get('/privacy', (_req, res) => res.redirect(301, process.env.PRIVACY_URL));
server.get('/health', (_req, res) => res.send({ status: 'ok' }));

const port = process.env.PORT ? Number.parseInt(process.env.PORT, 10) : 2_399;

Expand Down

0 comments on commit a5ddef9

Please sign in to comment.