2020-12-10 04:36:36 +00:00
|
|
|
import { Client, Intents } from '../../mod.ts'
|
2020-12-10 06:55:52 +00:00
|
|
|
import { SlashCommandOptionType } from '../types/slash.ts'
|
2020-12-10 04:36:36 +00:00
|
|
|
import { TOKEN } from './config.ts'
|
|
|
|
|
|
|
|
const client = new Client()
|
|
|
|
|
|
|
|
client.on('ready', () => {
|
|
|
|
console.log('Logged in!')
|
2020-12-10 06:55:52 +00:00
|
|
|
client.slash.commands
|
|
|
|
.create(
|
|
|
|
{
|
|
|
|
name: 'eval',
|
|
|
|
description: 'Run some JS code!',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'code',
|
|
|
|
description: 'Code to run',
|
|
|
|
type: SlashCommandOptionType.STRING,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'783319033205751809'
|
|
|
|
)
|
|
|
|
.then(console.log)
|
2020-12-10 04:36:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
client.on('interactionCreate', async (d) => {
|
2020-12-10 06:55:52 +00:00
|
|
|
if (d.name === 'eval') {
|
|
|
|
if (d.user.id !== '422957901716652033') {
|
|
|
|
d.respond({
|
|
|
|
content: 'This command can only be used by owner!'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
const code = d.data.options.find((e) => e.name === 'code')
|
|
|
|
?.value as string
|
|
|
|
try {
|
|
|
|
// eslint-disable-next-line no-eval
|
|
|
|
let evaled = eval(code)
|
|
|
|
if (evaled instanceof Promise) evaled = await evaled
|
|
|
|
if (typeof evaled === 'object') evaled = Deno.inspect(evaled)
|
|
|
|
let res = `${evaled}`.substring(0, 1990)
|
|
|
|
while (client.token !== undefined && res.includes(client.token)) {
|
|
|
|
res = res.replace(client.token, '[REMOVED]')
|
|
|
|
}
|
|
|
|
d.respond({
|
|
|
|
content: '```js\n' + `${res}` + '\n```'
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
d.respond({
|
|
|
|
content: '```js\n' + `${e.stack}` + '\n```'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-12-10 04:36:36 +00:00
|
|
|
await d.respond({
|
2020-12-10 06:55:52 +00:00
|
|
|
content: `Hi, ${d.member.user.username}!`,
|
|
|
|
flags: 64
|
2020-12-10 04:36:36 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
client.connect(TOKEN, Intents.None)
|