Skip to content

Commit

Permalink
fix(bot): make influx and sentry optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Apr 24, 2024
1 parent b217642 commit c9dd7a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/bot/src/influx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { hostname } from 'os';
import { client as dexareClient, CraigBotConfig } from './bot';
import type RecorderModule from './modules/recorder';

const influxOpts: any = config.get('influx');
const influxOpts: any = config.has('influx') ? config.get('influx') : null;
export const client: InfluxDB | null = influxOpts && influxOpts.url ? new InfluxDB({ url: influxOpts.url, token: influxOpts.token }) : null;

export const cron = new CronJob('*/5 * * * *', collect, null, false, 'America/New_York');
Expand Down
35 changes: 20 additions & 15 deletions apps/bot/src/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import { CommandContext } from 'slash-create';
import Recording from './modules/recorder/recording';
import { prisma } from './prisma';

const sentryOpts: any = config.get('sentry');
Sentry.init({
dsn: sentryOpts.dsn,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new RewriteFrames({
root: __dirname
}),
new Integrations.Prisma({ client: prisma })
],
const sentryOpts: any = config.has('sentry') ? config.get('sentry') : null;
if (sentryOpts)
Sentry.init({
dsn: sentryOpts.dsn,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new RewriteFrames({
root: __dirname
}),
new Integrations.Prisma({ client: prisma })
],

environment: sentryOpts.env || process.env.NODE_ENV || 'development',
// eslint-disable-next-line @typescript-eslint/no-var-requires
release: `craig-bot@${require('../package.json').version}`,
tracesSampleRate: sentryOpts.sampleRate ? parseFloat(sentryOpts.sampleRate) : 1.0
});
environment: sentryOpts.env || process.env.NODE_ENV || 'development',
// eslint-disable-next-line @typescript-eslint/no-var-requires
release: `craig-bot@${require('../package.json').version}`,
tracesSampleRate: sentryOpts.sampleRate ? parseFloat(sentryOpts.sampleRate) : 1.0
});

export function reportErrorFromCommand(ctx: CommandContext, error: any, commandName: string, type?: string) {
if (!sentryOpts) return;
Sentry.withScope((scope) => {
scope.setTag('type', type || 'generic');
if (commandName) scope.setTag('command', commandName);
Expand All @@ -43,6 +45,7 @@ export function reportErrorFromCommand(ctx: CommandContext, error: any, commandN
}

export function reportRecordingError(ctx: CommandContext, error: any, recording?: Recording) {
if (!sentryOpts) return;
Sentry.withScope((scope) => {
scope.setTag('type', 'command');
scope.setTag('command', 'join');
Expand All @@ -61,6 +64,7 @@ export function reportRecordingError(ctx: CommandContext, error: any, recording?
}

export function reportAutorecordingError(member: Eris.Member, guildId: string, channelId: string, error: any, recording?: Recording) {
if (!sentryOpts) return;
Sentry.withScope((scope) => {
scope.setTag('type', 'autorecord');
if (recording) scope.setTag('recording', recording.id);
Expand All @@ -77,5 +81,6 @@ export function reportAutorecordingError(member: Eris.Member, guildId: string, c
}

export function close() {
if (!sentryOpts) return;
return Sentry.close();
}

0 comments on commit c9dd7a5

Please sign in to comment.