Setup and migrate to Prisma (#456)

This commit is contained in:
Peerawas Archavanuntakun 2022-01-06 03:30:32 +07:00 committed by GitHub
parent 129d121364
commit 51d378e4cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 605 additions and 273 deletions

View file

@ -1,13 +1,24 @@
import {Guild, TextChannel, Message, MessageReaction, User} from 'discord.js';
import emoji from 'node-emoji';
import pEvent from 'p-event';
import {Settings} from '../models/index.js';
import {chunk} from '../utils/arrays.js';
import {prisma} from '../utils/db.js';
const DEFAULT_PREFIX = '!';
export default async (guild: Guild): Promise<void> => {
await Settings.upsert({guildId: guild.id, prefix: DEFAULT_PREFIX});
await prisma.setting.upsert({
where: {
guildId: guild.id,
},
create: {
guildId: guild.id,
prefix: DEFAULT_PREFIX,
},
update: {
prefix: DEFAULT_PREFIX,
},
});
const owner = await guild.client.users.fetch(guild.ownerId);
@ -70,7 +81,15 @@ export default async (guild: Guild): Promise<void> => {
const prefixCharacter = prefixResponses.first()!.content;
// Save settings
await Settings.update({prefix: prefixCharacter, channel: chosenChannel.id}, {where: {guildId: guild.id}});
await prisma.setting.update({
where: {
guildId: guild.id,
},
data: {
channel: chosenChannel.id,
prefix: prefixCharacter,
},
});
// Send welcome
const boundChannel = guild.client.channels.cache.get(chosenChannel.id) as TextChannel;