main
suhas 1 year ago
parent 813272caef
commit 54d0aa98e3

3535
package-lock.json generated

File diff suppressed because it is too large Load Diff

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

@ -1,39 +0,0 @@
// 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?
welcome_on Boolean @default(false)
users User[]
dailymessages DailyMessage[]
}
model DailyMessage {
id Int @id @default(autoincrement())
text String
guild GuildConfig @relation(fields: [guild_id], references: [id])
guild_id String
hour Int
minute Int
channel String
}
model User {
id String
guild GuildConfig @relation(fields: [guild_id], references: [id])
guild_id String
messages Int @default(0)
@@id([id, guild_id])
}

@ -0,0 +1,31 @@
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,49 +0,0 @@
import { PrismaClient } from '@prisma/client'
import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create'
export default class DailyCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'daily',
description: 'send daily message',
options: [
{
name: 'hour',
description: 'the hour to send the daily message IN UTC!!',
type: CommandOptionType.INTEGER,
min_value: 0,
max_value: 24,
required: true
},
{
name: 'minute',
description: 'the minute to send the daily message IN UTC!!',
type: CommandOptionType.INTEGER,
min_value: 0,
max_value: 59,
required: true
},
{
name: 'message',
description: 'the message to send',
type: CommandOptionType.STRING,
required: true
}
]
})
}
async run(ctx: CommandContext) {
const p = new PrismaClient()
await p.dailyMessage.create({
data: {
hour: ctx.options.hour,
minute: ctx.options.minute,
text: ctx.options.message,
channel: ctx.channelID,
guild_id: ctx.guildID
}
})
return `done!`
}
}

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

@ -1,25 +0,0 @@
import { PrismaClient } from '@prisma/client'
import { SlashCommand, SlashCreator, CommandContext } from 'slash-create'
export default class LeaderboardCommand extends SlashCommand {
constructor(creator: SlashCreator) {
super(creator, {
name: 'leaderboard',
description: 'see top 10 messages'
})
}
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) {
st += `<@${u.id}> - ${u.messages} message(s)\n`
}
ctx.send(st, {allowedMentions: {everyone: false, roles: false, users: false}})
}
}

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

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

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

@ -1,23 +0,0 @@
/* 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=${process.env.ALPHAVANTAGE_KEY}`)
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']}`
}
}

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

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

Loading…
Cancel
Save