rps and welcomer but i stage all of them

main
suhas 2 years ago
parent e1b7f4722f
commit 0ea8a441db

@ -14,6 +14,7 @@ model GuildConfig {
id String @id
welcome_message String @default("Hello %USER%!")
welcome_channel String?
welcome_on Boolean @default(false)
daily_message_text String @default("daily message")
daily_message_channel String?
daily_message_time DateTime @default(now()) @db.Timetz

@ -0,0 +1,29 @@
import { PrismaClient } from '@prisma/client'
import { CommandContext, SlashCommand, SlashCreator, CommandOptionType } from 'slash-create'
export default class SetWelcomeMessageCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'setwelcomemessage',
description: 'set the welcome message, %USER% replaces to a mention of the joined user',
options: [
{
name: 'message',
description: 'the message (leave blank to see current message)',
type: CommandOptionType.STRING
}
]
})
}
async run(ctx: CommandContext) {
const prisma = new PrismaClient()
if (ctx.options.message == null) {
const g = await prisma.guildConfig.findFirst({ where: { id: ctx.guildID } })
return `the current welcome message is ${g.welcome_message}`
}
await prisma.guildConfig.update({ where: { id: ctx.guildID }, data: { welcome_message: ctx.options.message } })
return `updated your welcome message to ${ctx.options.message}!`
}
}

@ -0,0 +1,42 @@
import { PrismaClient } from '@prisma/client';
import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create';
export default class ToggleWelcomerCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'toggle_welcomer',
description: 'toggle the welcome',
options: [
{
name: 'setting',
type: CommandOptionType.BOOLEAN,
description: 'whether it is on or not (leave blank to see the current setting)'
}
]
})
}
async run(ctx: CommandContext) {
const p = new PrismaClient()
if (ctx.options.setting == null) {
const gcf = await p.guildConfig.findFirst({
where: {
id: ctx.guildID
}
})
return `the welcomer is currently ${gcf.welcome_on ? 'on' : 'off'}`
}
await p.guildConfig.update({
where: {
id: ctx.guildID
},
data: {
welcome_on: ctx.options.setting
}
})
return `set welcomer to ${ctx.options.setting ? 'on' : 'off'}`
}
}

@ -1,8 +1,8 @@
import dotenv from 'dotenv'
import { SlashCreator, GatewayServer } from 'slash-create'
import { SlashCreator, GatewayServer, Member } from 'slash-create'
import path from 'path'
import CatLoggr from 'cat-loggr/ts'
import { Client, GatewayDispatchEvents, Events, Guild, Message } from 'discord.js'
import { Client, GatewayDispatchEvents, Events, Guild, Message, GuildMember, TextChannel } from 'discord.js'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
@ -76,4 +76,17 @@ client.on(Events.MessageCreate, async (msg: Message) => {
})
})
client.on(Events.GuildMemberAdd, async (m: GuildMember) => {
const gc = await prisma.guildConfig.findFirst({
where: {
id: m.guild.id
}
})
if (gc.welcome_on) {
const ch = (await m.guild.channels.fetch(gc.welcome_channel)) as TextChannel
await ch.send(gc.welcome_message.replace('%USER%', `<@${m.id}>`))
}
})
client.login(process.env.TOKEN)

Loading…
Cancel
Save