diff --git a/config.ts b/config.ts index 9df3c8a..54378a0 100644 --- a/config.ts +++ b/config.ts @@ -1,3 +1,4 @@ +import { Events } from "discord.js"; import dotenv from "dotenv"; // use .env without extension file if node_env is not defined otherwise use .env.${node_env} @@ -101,6 +102,17 @@ export const categoryEmojiMap: { Bounty: "WMBOUNTY", Video: "WMVIDEO", Paraverse: "WMPARAVERSE", + Tip: "WMTIP", + Wallet: "WMWALLET", + RWA: "WMRWA", + Rollup: "WMROLLUP", + Meme: "WMMEME", + Jam: "WMJAM", + Grant: "WMGRANT", + Events: "WMEVENTS", + DV: "WMDV", + DAO: "WMDAO", + Coretime: "WMCORETIME", }; export const NEWSLETTER_CATEGORY_NAME = "Newsletter"; diff --git a/data/post.ts b/data/post.ts index 46932ad..c34d6d7 100644 --- a/data/post.ts +++ b/data/post.ts @@ -51,6 +51,8 @@ export const findOrCreatePost = async ( const contentType = determinePostType(messageLink); + console.log("aaa contentType", contentType); + const user = await findOrCreateUser(message); // Ensure all tags exist @@ -585,8 +587,16 @@ export function determinePostType( const channelNewsIds = JSON.parse(process.env.CHANNELS_NEWS || "[]"); const channelArticleIds = JSON.parse(process.env.CHANNELS_ARTICLES || "[]"); + console.log( + "aaa determinePostType", + messageLink, + channelNewsIds, + channelArticleIds, + ); + for (const channelId of channelNewsIds) { if (messageLink.includes(channelId)) { + console.log("aaa determinePostType news"); return "news"; } } diff --git a/package.json b/package.json index 31dd0f8..9d76803 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "data-migration:add-content-type": "ts-node prisma/migrations/20240422153641_add_content_type/data-migration.ts", "data-migration:test": "ts-node prisma/log-multiple-post-earnings.ts", "migrate-roles": "ts-node prisma/migrate-roles.ts", + "update-categories": "ts-node prisma/update-categories.ts", "postinstall": "pnpm prisma generate" }, "simple-git-hooks": { diff --git a/prisma/update-categories.ts b/prisma/update-categories.ts new file mode 100644 index 0000000..58277cc --- /dev/null +++ b/prisma/update-categories.ts @@ -0,0 +1,88 @@ +//update the categories in the database from the config.ts file +import { PrismaClient } from "@prisma/client"; +import * as config from "../config"; +const prisma = new PrismaClient(); + +export async function updateCategories() { + const categories = Object.keys(config.categoryEmojiMap); + const dbCategories = await prisma.category.findMany(); + + //check if the categories are in the database + const categoriesInDb = dbCategories.map((category) => category.name); + const categoriesNotInDb = categories.filter( + (category) => !categoriesInDb.includes(category), + ); + + console.log( + `Found ${dbCategories.length} categories in the database: ${dbCategories + .map((category) => category.name) + .join(", ")}`, + ); + + //create the categories that are not in the database + const categoriesToCreate = categoriesNotInDb.map((category) => ({ + name: category, + emoji: config.categoryEmojiMap[category], + })); + + console.log( + `Creating ${categoriesToCreate.length} missing categories: ${categoriesToCreate + .map((category) => `${category.name}: (${category.emoji})`) + .join(", ")}`, + ); + + for (const name in config.categoryEmojiMap) { + try { + const emojiName = config.categoryEmojiMap[name]; + + // 1) Seed Emoji + const emoji = await prisma.emoji.upsert({ + where: { + id: emojiName, + }, + update: {}, + create: { + id: emojiName, + name: emojiName, + }, + }); + + // 2) Seed Category + const category = await prisma.category.upsert({ + where: { + name: name, + }, + update: { + name: name, + emojiId: emoji.id, + }, + create: { + name: name, + emojiId: emoji.id, + }, + }); + + // 3) Seed Category Rules + await prisma.categoryRule.upsert({ + where: { + emojiId: emoji.id, + }, + update: {}, + create: { + categoryId: category.id, + emojiId: emoji.id, + }, + }); + } catch (e) { + console.log("error seeding category", name, e); + } + } + + console.log("Categories updated successfully"); +} + +async function main() { + await updateCategories(); +} + +main();