Compare commits

..

No commits in common. '54d0aa98e32db403bee372cb03f45f01ecc51371' and '55d8df5f28a9ee95daa12c21ce7695ca43b2bfa4' have entirely different histories.

3535
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -12,6 +12,7 @@
"lint:fix": "npx eslint --ext .ts ./src --fix"
},
"dependencies": {
"@prisma/client": "^4.11.0",
"cat-loggr": "^1.1.0",
"discord.js": "^14.7.1",
"dotenv": "^8.2.0",
@ -31,6 +32,7 @@
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.3.0",
"prettier": "^2.2.1",
"prisma": "^4.11.0",
"slash-up": "^1.0.11",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"

@ -0,0 +1,30 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model GuildConfig {
id String @id
welcome_message String @default("Hello %USER%!")
welcome_channel String?
daily_message_text String @default("daily message")
daily_message_channel String?
daily_message_time DateTime @default(now()) @db.Timetz
users User[]
}
model User {
id String
guild GuildConfig @relation(fields: [guild_id], references: [id])
guild_id String
messages Int @default(0)
@@id([id, guild_id])
}

@ -1,31 +0,0 @@
import { SlashCommand, SlashCreator, CommandContext, CommandOptionType } from 'slash-create';
import { Client } from 'discord.js'
const valid = ['498992803532242945', '435206857276260353']
export default class PingCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'andrewkuo',
description: 'give andrewkuo role',
options: [
{
name: 'who',
description: 'who',
type: CommandOptionType.USER,
required: true
}
]
})
}
async run(ctx: CommandContext) {
if (valid.indexOf(ctx.user.id) == -1) {
return 'no'
}
const cli = this.client as Client
const g = cli.guilds.cache.get(ctx.guildID)
const me = g.members.cache.get(ctx.options.who as string)
await me.roles.add('1148804439755460638', '/andrewkuo')
return `gave andrewkuo role to @${me.user.username}`
}
}

@ -1,43 +0,0 @@
import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create'
const things: Record<string, string> = {
'gm': 'good morning',
'ga': 'good afternoon',
'gn': 'good night'
}
export default class RPSCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'g',
description: 'gmgnga',
options: [
{
name: 'type',
description: 'type of gmgnga',
type: CommandOptionType.STRING,
choices: [
{ name: 'gm', value: 'gm' },
{ name: 'ga', value: 'ga' },
{ name: 'gn', value: 'gn' }
],
required: true
},
{
name: 'who',
description: 'who to gmgnga (optional)',
type: CommandOptionType.USER,
required: false
}
]
})
}
async run(ctx: CommandContext) {
if (ctx.options.who == null) {
return `<@${ctx.member?.id}> says ${things[ctx.options.type as 'gm' | 'gn' | 'ga']}`
} else {
return `<@${ctx.member?.id}> says ${things[ctx.options.type as 'gm' | 'gn' | 'ga']} to <@${ctx.options.who}>`
}
}
}

@ -0,0 +1,27 @@
import { PrismaClient } from '@prisma/client'
import { SlashCommand, SlashCreator, CommandContext, MessageEmbed } from 'slash-create'
export default class LeaderboardCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'leaderboard',
description: 'see top 10 messages'
})
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async run(ctx: CommandContext) {
const prisma = new PrismaClient()
const users = await prisma.user.findMany({
where: { guild_id: ctx.guildID },
take: 10,
orderBy: { messages: 'desc' }
})
let st = ''
for (const u of users) {
const uu = await this.client.users.fetch(u.id)
st += `${uu.username}#${uu.discriminator} - ${u.messages} message(s)\n`
}
return st
}
}

@ -0,0 +1,34 @@
import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create'
import { PrismaClient } from '@prisma/client'
export default class MessagesCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'messages',
description: 'show message count, either for yourself, or someone else',
options: [
{
name: 'user',
description: 'person to show messages for (blank shows your own)',
required: false,
type: CommandOptionType.USER
}
]
})
}
async run(ctx: CommandContext) {
const prisma = new PrismaClient()
if (ctx.options.user == null) {
const u = await prisma.user.findFirst({ where: { id: ctx.member?.id, guild: { id: ctx.guildID } } })
if (!u) return `you have no messages!`
return `you have ${u.messages} message(s)`
} else {
const uid = ctx.options.user
const u = await prisma.user.findFirst({ where: { id: uid, guild: { id: ctx.guildID } } })
if (!u) return `this user has no messages!`
const uu = await this.client.users.fetch(u.id)
return `${uu.username}#${uu.discriminator} has ${u.messages} message(s)`
}
}
}

@ -5,11 +5,11 @@ export default class PingCommand extends SlashCommand {
super(creator, {
name: 'ping',
description: 'pongs'
})
});
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async run(_ctx: CommandContext) {
return `pong from ${this.client.user.tag}!`
return `pong from ${this.client.user.tag}!`;
}
}

@ -1,41 +0,0 @@
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}`
}
}

@ -0,0 +1,23 @@
/* eslint-disable prettier/prettier */
import { SlashCommand, SlashCreator, CommandOptionType, CommandContext } from 'slash-create';
export default class StockCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'stock',
description: 'checks stock price',
options: [{ type: CommandOptionType.STRING, name: 'ticker', description: 'the ticker to check', required: true }]
});
}
async run(ctx: CommandContext) {
const tkr = ctx.options.ticker
const req = await fetch(`https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${tkr}&apikey=8O1INVBY11E0GRGC`)
const info = await req.json()
if (Object.keys(info['Global Quote']).length == 0) {
return `stock not found!`
}
const i = info['Global Quote']
return `stock info for ${i['01. symbol']} - OPEN: ${i['02. open']} - PRICE: ${i['05. price']} - % CHANGE: ${i['10. change percent']}`
}
}

@ -2,17 +2,10 @@ import dotenv from 'dotenv'
import { SlashCreator, GatewayServer } from 'slash-create'
import path from 'path'
import CatLoggr from 'cat-loggr/ts'
import {
Client,
GatewayDispatchEvents,
Events,
Guild,
Message,
GuildMember,
TextChannel,
EmbedBuilder
} from 'discord.js'
import { Client, GatewayDispatchEvents, Events, Guild, Message } from 'discord.js'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const client = new Client({ intents: [131071] })
let dotenvPath = path.join(process.cwd(), '.env')
@ -53,72 +46,34 @@ client.on(Events.GuildCreate, async (g: Guild) => {
})
})
// client.on(Events.MessageCreate, async (msg: Message) => {
// if (!msg.guild || msg.author == client.user) return
// const u = await prisma.user.findFirst({
// where: {
// guild_id: msg.guild.id,
// id: msg.author.id
// }
// })
// if (!u) {
// await prisma.user.create({
// data: {
// guild_id: msg.guild.id,
// id: msg.author.id,
// messages: 1
// }
// })
// return
// }
// const newMessagesCount = (u.messages ?? 0) + 1
// await prisma.user.update({
// where: {
// id_guild_id: { id: msg.author.id, guild_id: msg.guild.id }
// },
// data: {
// messages: newMessagesCount
// }
// })
// })
// 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
// const me = new EmbedBuilder({
// title: 'Welcome!',
// description: gc.welcome_message.replace('%USER%', `<@${m.id}>`),
// footer: {
// text: `member #${m.guild.memberCount}`,
// icon_url: 'https://www.giantfreakinrobot.com/wp-content/uploads/2022/08/rick-astley.jpg'
// },
// color: 0x7289da
// })
// await ch.send({ content: `<@${m.id}>`, embeds: [me] })
// }
// })
client.on(Events.MessageCreate, async (msg: Message) => {
if (!msg.guild || msg.author == client.user) return
const u = await prisma.user.findFirst({
where: {
guild_id: msg.guild.id,
id: msg.author.id
}
})
// setInterval(async () => {
// const now = new Date()
// const messages = await prisma.dailyMessage.findMany({
// where: {
// hour: now.getUTCHours(),
// minute: now.getUTCMinutes()
// }
// })
// for (const m of messages) {
// const g = client.guilds.cache.get(m.guild_id)
// if (!g) continue
// const ch = (await g.channels.fetch(m.channel)) as TextChannel
// await ch.send(m.text)
// }
// }, 1000 * 60)
if (!u) {
await prisma.user.create({
data: {
guild_id: msg.guild.id,
id: msg.author.id,
messages: 1
}
})
return
}
const newMessagesCount = (u.messages ?? 0) + 1
await prisma.user.update({
where: {
id_guild_id: { id: msg.author.id, guild_id: msg.guild.id }
},
data: {
messages: newMessagesCount
}
})
})
client.login(process.env.TOKEN)

Loading…
Cancel
Save