Skip to content

Commit

Permalink
adding some fixes for vods
Browse files Browse the repository at this point in the history
  • Loading branch information
trent-001 committed Aug 23, 2024
1 parent 3bdf73f commit 5dada10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export const discordBotTwitch = pgTable("discord_bot_twitch", {
keep_vod: boolean("keep_vod").default(false).notNull(),
mention: text("mention"),
message: text("message"),
vod_id: text("vod_id"),
});
22 changes: 15 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { db } from "./db";
import * as schema from "./db/schema";
import { ITwitch } from "./types";
import { eq } from "drizzle-orm";
import cron from "node-cron";
export const AddButtonDataTwitch = new Map();
export const discord = new Client({
intents: [
Expand Down Expand Up @@ -45,18 +46,22 @@ discord.login(process.env.DISCORD_TOKEN);
discord.on(Events.ClientReady, async () => {
console_log.colour(discord?.user?.username + " bot is ready", "green");
await registerSlashCommands();
setInterval(timeCheck, 1000);
TwitchEmbedLoop();
// setInterval(timeCheck, 1000);
// TwitchEmbedLoop();
cron.schedule("*/10 * * * *", () => {
TwitchEmbedLoop();
});
});
import "./events/interactionCreate";
function timeCheck() {
var now = new Date();
let minute = now.getMinutes();
let second = now.getSeconds();
if (minute % 10 === 0 && second === 0) {
TwitchEmbedLoop();
// TwitchEmbedLoop();
}
}
// run every 10 minutes
const TwitchEmbedLoop = async () => {
const servers = await db.query.discordBotTwitch.findMany();
console_log.log(`Twitch Embeds Processing ${servers.length} Users`);
Expand Down Expand Up @@ -95,6 +100,7 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
.update(schema.discordBotTwitch)
.set({
message_id: null,
vod_id: null,
})
.where(eq(schema.discordBotTwitch.id, item.id));
return;
Expand Down Expand Up @@ -143,12 +149,11 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
.setLabel("Watch Stream")
.setStyle(ButtonStyle.Link)
.setURL(`https://www.twitch.tv/${item.username.toLowerCase()}`);
// let buttonLinks = new ButtonBuilder()
// .setLabel("Social Links")
// .setStyle(ButtonStyle.Link)
// .setURL("https://doras.to");
let row: any = new ActionRowBuilder().addComponents(buttonWatch);
if (!dataLive.live) {
if (dataLive.video.id !== item.vod_id) {
return;
}
buttonWatch.setLabel("Watch Vod");
buttonWatch.setURL(dataLive.video.url);
if (!channel.isTextBased()) return;
Expand Down Expand Up @@ -181,6 +186,7 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
.update(schema.discordBotTwitch)
.set({
message_id: null,
vod_id: null,
})
.where(eq(schema.discordBotTwitch.id, item.id));
return;
Expand Down Expand Up @@ -209,6 +215,7 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
.update(schema.discordBotTwitch)
.set({
message_id: message.id,
vod_id: dataLive.id,
})
.where(eq(schema.discordBotTwitch.id, item.id));
return;
Expand All @@ -231,6 +238,7 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
.update(schema.discordBotTwitch)
.set({
message_id: message.id,
vod_id: dataLive.id,
})
.where(eq(schema.discordBotTwitch.id, item.id));
return;
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"license": "ISC",
"dependencies": {
"@types/node": "^20.14.11",
"@types/node-cron": "^3.0.11",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.32.0",
"node-cron": "^3.0.3",
"nodemon": "^3.1.4",
"postgres": "^3.4.4",
"ts-node": "^10.9.2",
Expand Down

0 comments on commit 5dada10

Please sign in to comment.