Skip to content

Commit

Permalink
add nvmrc (#107)
Browse files Browse the repository at this point in the history
migrate from sentry/profiling to sentry/node
add mudae troll
  • Loading branch information
im-calvin authored Mar 6, 2024
1 parent ce2a42a commit 8576671
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 730 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.12.1
922 changes: 216 additions & 706 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"dependencies": {
"@google-cloud/translate": "^8.0.1",
"@sentry/integrations": "^7.61.0",
"@sentry/node": "^7.64.0",
"@sentry/profiling-node": "^1.1.2",
"@sentry/node": "^7.105.0",
"discord.js": "^14.9.0",
"dotenv": "^16.1.4",
"kuroshiro": "~1.1.2",
Expand Down
35 changes: 30 additions & 5 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GatewayIntentBits, Events, Message, PartialMessage } from "discord.js";
import { GatewayIntentBits, Events, Message, PartialMessage, userMention } from "discord.js";
import MittensClient from "./utils/Client.js";
import { handleTranslate } from "./translate/Translate.js";
import Sentry from "@sentry/node";
Expand Down Expand Up @@ -59,7 +59,7 @@ client.on(Events.InteractionCreate, async (interaction) => {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
transaction.finish();
transaction.end();
});

// handle autocomplete
Expand All @@ -83,7 +83,7 @@ client.on(Events.InteractionCreate, async (interaction) => {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
transaction.finish();
transaction.end();
});

// handle translating
Expand Down Expand Up @@ -186,8 +186,33 @@ client.on(Events.GuildCreate, (guild) => {
guildTranslate.discordGuildId = guild.id;

guildTranslateRepo.insert(guildTranslate);
transaction.finish();
transaction.end();
});

// randomly ping certain users to troll them in a particular channel
const trollUsers = [
"218854936539037697", // kevin
// "277242405684641794", // derk
"554202008882511872", // izzy
"254235152341925888", // lsr
];
const interval = 12 * 60 * 60 * 1000; // half a day in milliseconds
const channelId = "1213400628739579924";
const guildId = "1099897092366942300";

setInterval(() => {
const randomUser = trollUsers[Math.floor(Math.random() * trollUsers.length)];
const guild = client.guilds.cache.get(guildId);
if (guild) {
const channel = guild.channels.cache.get(channelId);
if (channel && channel.isTextBased()) {
const member = guild.members.cache.find((member) => member.user.id === randomUser);
if (member) {
channel.send(`Wished by ${userMention(member.user.id)}`);
}
}
}
}, interval);

client.login(readEnv("DISCORD_TOKEN"));
boot.finish();
boot.end();
8 changes: 4 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getDBStreamers(): Promise<Streamer[]> {
throw new Error("Streamer table is empty");
}

transaction.finish();
transaction.end();
return streamers;
}

Expand All @@ -32,7 +32,7 @@ export async function getGroups(): Promise<Group[]> {
});
const groups = await AppDataSource.getRepository(Group).find();

transaction.finish();
transaction.end();
return groups;
}

Expand All @@ -48,7 +48,7 @@ export async function getStreamersByLanguage(language: Language): Promise<Stream
.leftJoin(Language, "languages", "groups.language_id = :language", { language: language.id })
.getMany();

transaction.finish();
transaction.end();
return streamers;
}

Expand All @@ -60,7 +60,7 @@ export async function getLanguages(): Promise<Language[]> {

const languages = await AppDataSource.getRepository(Language).find();

transaction.finish();
transaction.end();
return languages;
}

Expand Down
7 changes: 1 addition & 6 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Sentry from "@sentry/node";
import { ProfilingIntegration } from "@sentry/profiling-node";
import Kuroshiro from "kuroshiro";
import KuromojiAnalyzer from "kuroshiro-analyzer-kuromoji";
import { AppDataSource } from "./db/data-source.js";
Expand All @@ -15,11 +14,7 @@ export async function monitoringInit(): Promise<void> {
// inits Sentry
Sentry.init({
dsn: "https://c9c992d5a347411db99537a0ed2c0094@o4505106964742144.ingest.sentry.io/4505106967691264",
integrations: [
new ProfilingIntegration(),
new Sentry.Integrations.Http({ tracing: true }),
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
release: "mittens@" + readEnv("npm_package_version"),
Expand Down
5 changes: 2 additions & 3 deletions src/translate/Translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function translateText(text: string, language: string): Promise<string> {
throw new Error("No translation found");
}
const translatedText = translations.map((t) => t.translatedText).join("\n");
transaction.finish();
transaction.end();
return translatedText;
}

Expand All @@ -46,7 +46,6 @@ async function translateText(text: string, language: string): Promise<string> {
* @returns true if the text is detected as the target language
*/
async function detectLanguage(text: string): Promise<DetectedLanguage> {

const transaction = Sentry.startTransaction({
op: "detectLanguage",
name: "Detects the language of the text",
Expand All @@ -69,7 +68,7 @@ async function detectLanguage(text: string): Promise<DetectedLanguage> {
)
throw new Error("No detected language found");

transaction.finish();
transaction.end();
return {
confidence:
language.confidence > targetConfidence && targetLanguages.includes(language.languageCode),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Holodex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ export async function getHoloChannels(): Promise<HolodexChannel[]> {
offset += 25;
} while (data.length !== 0);

transaction.finish();
transaction.end();
return res;
}
2 changes: 1 addition & 1 deletion src/utils/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function announceStream(
${video.id}
${mentions}
`);
transaction.finish();
transaction.end();
}

export async function embedScheduleFormatter(
Expand Down
4 changes: 2 additions & 2 deletions src/utils/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function scrape() {
const job = new SimpleIntervalJob({ minutes: intervalTime, runImmediately: true }, task);

scheduler.addSimpleIntervalJob(job);
transaction.finish();
transaction.end();
}

/**
Expand Down Expand Up @@ -194,7 +194,7 @@ async function getChannelSubs(video: Video): Promise<Map<string, string[]>> {
channelSubs.set(sub.discordChannelId, [...channelUsers, sub.discordUser.id]);
}
}
transaction.finish();
transaction.end();

return channelSubs;
}

0 comments on commit 8576671

Please sign in to comment.