From e1b7f4722f94e554d54930194f1575dcfea4452b Mon Sep 17 00:00:00 2001 From: suhas Date: Mon, 13 Mar 2023 22:22:57 -0500 Subject: [PATCH] rps and welcomer --- src/commands/rps.ts | 41 ++++++++++++++++++++++++++++++ src/commands/setwelcomechannel.ts | 42 +++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/commands/rps.ts create mode 100644 src/commands/setwelcomechannel.ts diff --git a/src/commands/rps.ts b/src/commands/rps.ts new file mode 100644 index 0000000..d80be3b --- /dev/null +++ b/src/commands/rps.ts @@ -0,0 +1,41 @@ +import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create' + +export default class RPSCommand extends SlashCommand { + constructor(creator: SlashCreator) { + super(creator, { + name: 'rps', + description: 'play rock paper scissors', + options: [ + { + name: 'choice', + description: 'what you want to play', + type: CommandOptionType.STRING, + choices: [ + { name: 'rock', value: 'rock' }, + { name: 'paper', value: 'paper' }, + { name: 'scissors', value: 'scissors' } + ], + required: true + } + ] + }) + } + + async run(ctx: CommandContext) { + const uc = ctx.options.choice + const cc = ['rock', 'paper', 'scissors'][Math.floor(Math.random() * 3)] + let winner = '' + if (uc == cc) { + winner = "it's a tie!" + } else if ( + (uc == 'rock' && cc == 'scissors') || + (uc == 'paper' && cc == 'rock') || + (uc == 'scissors' && cc == 'paper') + ) { + winner = 'you win!' + } else { + winner = 'computer wins!' + } + return `you chose ${uc} and the computer chose ${cc}. ${winner}` + } +} diff --git a/src/commands/setwelcomechannel.ts b/src/commands/setwelcomechannel.ts new file mode 100644 index 0000000..95e5905 --- /dev/null +++ b/src/commands/setwelcomechannel.ts @@ -0,0 +1,42 @@ +import { PrismaClient } from "@prisma/client"; +import { ChannelType, CommandContext, CommandOptionType, SlashCommand, SlashCreator } from "slash-create"; + +export default class SetWelcomeChannelCommand extends SlashCommand { + constructor(creator: SlashCreator) { + super(creator, { + name: 'set_welcome_channel', + description: 'setwelcomechannel', + options: [ + { + name: 'channel', + description: 'channel - blank to see current', + type: CommandOptionType.CHANNEL, + channel_types: [ChannelType.GUILD_TEXT] + } + ] + }) + } + + async run(ctx: CommandContext) { + const prisma = new PrismaClient() + if (ctx.options.channel == null) { + const gc = await prisma.guildConfig.findFirst({ + where: { + id: ctx.guildID + } + }) + return `current welcomechannel is ${ + '<#' + gc.welcome_channel + '>' ?? 'none (use /set_welcome_channel #CHANNEL)' + }` + } + await prisma.guildConfig.update({ + where: { + id: ctx.guildID + }, + data: { + welcome_channel: ctx.options.channel + } + }) + return `set the welcomechannel to <#${ctx.options.channel}>` + } +}