import { prisma } from "../db/prisma"; import { DiscordUserProfile, DiscordGuildProfile, Voice } from "../db/generated/prisma/client"; export function getUserProfile(userId: string): Promise { return prisma.discordUserProfile.upsert({ where: { userId: userId }, update: {}, create: { userId: userId, }, }); } export async function setUserProfile(userId: string, profile: DiscordUserProfile): Promise { await prisma.discordUserProfile.upsert({ where: { userId: userId }, update: { voice: profile.voice, nya: profile.nya }, create: { userId: userId, } }); } export async function setUserNya(userId: string, nya: boolean): Promise { await prisma.discordUserProfile.upsert({ where: { userId: userId }, update: { nya: nya }, create: { userId: userId, } }); } export async function setUserSupertonicStyle(userId: string, style: string): Promise { await prisma.discordUserProfile.upsert({ where: { userId: userId }, update: { userSupertonicStyle: style }, create: { userId: userId, userSupertonicStyle: style } }); } export async function setUserVoice(userId: string, voice: Voice): Promise { await prisma.discordUserProfile.upsert({ where: { userId: userId }, update: { voice: voice }, create: { userId: userId, voice: voice } }); } export async function setUserCanTypecast(userId: string, canTypecast: boolean): Promise { await prisma.discordUserProfile.upsert({ where: { userId: userId }, update: { canTypecast: canTypecast }, create: { userId: userId, } }); } export function getGuildProfile(guildId: string): Promise { return prisma.discordGuildProfile.upsert({ where: { guildId: guildId }, update: {}, create: { guildId: guildId, }, }); } export async function hasGuildReadChannel(guildId: string, channelId: string): Promise { return ( await prisma.discordGuildProfile.findFirst({ where: { guildId: guildId, readChannel: { has: channelId } } }) ) != null; } export async function removeGuildReadChannel(guildId: string, channelId: string): Promise { const guildProfile = await prisma.discordGuildProfile.findUnique({ where: { guildId: guildId }, }); if (guildProfile) { await prisma.discordGuildProfile.update({ where: { guildId: guildId }, data: { readChannel: guildProfile.readChannel.filter(channel => channel != channelId), }, }); } } export async function insertGuildReadChannel(guildId: string, channelId: string): Promise { await prisma.discordGuildProfile.upsert({ where: { guildId: guildId, NOT: { readChannel: { has: channelId, }, } }, update: { readChannel: { push: channelId, }, }, create: { guildId: guildId, readChannel: [channelId], }, }); }