Skip to content

Commit

Permalink
Slash /help, use Eris v9, disable region commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Aug 24, 2021
1 parent db8b635 commit 8732bc0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
10 changes: 5 additions & 5 deletions dashboard/imports/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const mongodb = new MongoClient(mongoUrl === 'dotenv' ? process.env.MONGO_URL ||
mongodb.once('open', () => console.log('GraphQL server connected successfully to MongoDB.'))
const db = mongodb.db('ivebot')

const botClient = new Client(`Bot ${botToken}`, { restMode: true })
const botClient = new Client(`Bot ${botToken}`, { restMode: true, intents: 0 })

// Helper functions.
const getServerSettings = async (id: string): Promise<Document> => {
Expand Down Expand Up @@ -131,7 +131,7 @@ export default {
Query: {
getServerSettings: async (parent: string, { id }: { id: string }, context: ResolverContext) => {
const accessToken = await authenticateRequest(context.req, context.res)
const client = new Client(`Bearer ${accessToken}`, { restMode: true })
const client = new Client(`Bearer ${accessToken}`, { restMode: true, intents: 0 })
const self = await client.getSelf()
const hasPerm = await checkUserGuildPerm(self.id, id, host === self.id)
if (hasPerm) {
Expand All @@ -150,7 +150,7 @@ export default {
},
getUserInfo: async (parent: string, args: {}, context: ResolverContext) => {
const accessToken = await authenticateRequest(context.req, context.res)
const client = new Client(`Bearer ${accessToken}`, { restMode: true })
const client = new Client(`Bearer ${accessToken}`, { restMode: true, intents: 0 })
const self = await client.getSelf()
return {
identifier: `${self.username}#${self.discriminator}`,
Expand All @@ -160,7 +160,7 @@ export default {
},
getUserServers: async (parent: string, args: {}, context: ResolverContext) => {
const accessToken = await authenticateRequest(context.req, context.res)
const client = new Client(`Bearer ${accessToken}`, { restMode: true })
const client = new Client(`Bearer ${accessToken}`, { restMode: true, intents: 0 })
const guilds = await client.getRESTGuilds()
const self = await client.getSelf()
const mutuals = await getMutualPermissionGuilds(self.id, guilds.map(guild => guild.id), host === self.id)
Expand Down Expand Up @@ -192,7 +192,7 @@ export default {
context: ResolverContext
) => {
const accessToken = await authenticateRequest(context.req, context.res)
const client = new Client(`Bearer ${accessToken}`, { restMode: true })
const client = new Client(`Bearer ${accessToken}`, { restMode: true, intents: 0 })
const self = await client.getSelf()
const hasPerm = await checkUserGuildPerm(self.id, id, host === self.id)
if (hasPerm) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"node": ">=12.20.0"
},
"dependencies": {
"eris": "^0.15.1",
"eris": "DonovanDMC/eris#v9-interactions",
"fuse.js": "^6.4.6",
"json5": "^0.5.1",
"mathjs": "^9.4.3",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/admin/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ export const handleMute: Command = {
client.editChannelPermission(
a.id, role.id, 0,
Constants.Permissions.sendMessages | Constants.Permissions.addReactions,
'role'
0
).catch(() => {}) // Ignore error.
} else if (a.type === 2) {
client.editChannelPermission(a.id, role.id, 0, Constants.Permissions.voiceSpeak, 'role')
client.editChannelPermission(a.id, role.id, 0, Constants.Permissions.voiceSpeak, 0)
.catch(() => {}) // Ignore error.
} else if (a.type === 4) {
client.editChannelPermission(
a.id, role.id, 0,
Constants.Permissions.sendMessages |
Constants.Permissions.addReactions | Constants.Permissions.voiceSpeak,
'role'
0
).catch(() => {}) // Ignore error.
}
})
Expand Down
34 changes: 24 additions & 10 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Command as IveBotCommand } from '../imports/types.js'
import { zeroWidthSpace, getInsult } from '../imports/tools.js'
import { Command as IveBotCommand } from '../imports/types.js'
import CommandParser, { Command } from '../client.js'
import { rootURL } from '../config.js'
import { Command } from '../client.js'
import { Client } from 'eris'
import { CommandOptionType } from 'slash-create'

const generalHelp = {
description: `**Jony Ive can do many commands 📡**
Expand Down Expand Up @@ -114,23 +116,35 @@ export const handleHelp: IveBotCommand = {
fullDescription: 'The most innovative halp.',
usage: '/help (command name)',
example: '/help zalgo',
argsRequired: false
argsRequired: false,
slashOptions: [{ // TODO: Should this response be ephemeral?
name: 'command',
description: 'Name of the command to get help on.',
type: CommandOptionType.STRING,
required: false
}]
},
generator: async (message, args, { commandParser }) => {
const commands = commandParser.commands
const command = args.join(' ').split('/').join('').toLowerCase()
slashGenerator: async ({ user, options }, { client, commandParser }) => (
await handleHelp.commonGenerator(user.id, options.command, client, commandParser)
),
generator: async (message, args, { client, commandParser }) => (
await handleHelp.commonGenerator(message.author.id, args.join(' '), client, commandParser)
),
commonGenerator: async (author: string, command: string, client: Client, parser: CommandParser) => {
const commands = parser.commands
const commandName = command.split('/').join('').toLowerCase()
const check = (i: string): boolean => (
// First checks for name, 2nd for aliases.
commands[i].name.toLowerCase() === command ||
(commands[i].aliases && commands[i].aliases.includes(command))
commands[i].name.toLowerCase() === commandName ||
(commands[i].aliases && commands[i].aliases.includes(commandName))
)
// Check if requested for a specific command.
if (Object.keys(commands).find(check)) {
return generateDocs(commands[Object.keys(commands).find(check)])
} else if (args.join(' ')) return { content: 'Incorrect parameters. Run /help for general help.', error: true }
} else if (command) return { content: 'Incorrect parameters. Run /help for general help.', error: true }
// Default help.
try {
const channel = await message.author.getDMChannel()
const channel = await client.getDMChannel(author)
await channel.createMessage({
content: `**IveBot's dashboard**: ${rootURL || 'https://ivebot.now.sh'}/
(Manage Server required to manage a server)`,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const handleServerinfo: Command = {
...boost,
{ name: 'Owner', value: `${owner.username}#${owner.discriminator}`, inline: true },
{ name: 'Owner ID', value: guild.ownerID, inline: true },
{ name: 'Region', value: guild.region, inline: true },
// { name: 'Region', value: guild.region, inline: true },
{
name: 'Created On',
value: moment(guild.createdAt).format('DD/MM/YYYY, hh:mm:ss A'),
Expand Down Expand Up @@ -563,7 +563,7 @@ export const handleListserverregions: Command = ({
).map((value) => value.id).join('`, `') + '`'
})

export const handleChangeserverregion: Command = {
/* export const handleChangeserverregion: Command = {
name: 'changeserverregion',
aliases: ['csr'],
opts: {
Expand All @@ -589,7 +589,7 @@ export const handleChangeserverregion: Command = {
return 'Voice region changed to ' + name + ' \\o/'
} catch (e) { return 'Invalid server voice region.' }
}
}
} */

export const handleEdit: Command = {
name: 'edit',
Expand Down
11 changes: 5 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,11 @@ enquirer@^2.3.5:
dependencies:
ansi-colors "^4.1.1"

eris@^0.15.1:
version "0.15.1"
resolved "https://registry.yarnpkg.com/eris/-/eris-0.15.1.tgz#6b44e6d4675c271def7484725a0edede9e798960"
integrity sha512-IQ3BPW6OjgFoqjdh+irPOa1jFlkotk+WNu2GQQ7QAQfbzQEPZgn+F+hpOxfMUXPHOZMX4sPKLkVDkMHAssBYhw==
eris@DonovanDMC/eris#v9-interactions:
version "0.16.0-dev"
resolved "https://codeload.github.com/DonovanDMC/eris/tar.gz/ba05e5b521811053f8cc4bfa0bfd32f7c6097131"
dependencies:
ws "^7.2.1"
ws "^7.4.6"
optionalDependencies:
opusscript "^0.0.8"
tweetnacl "^1.0.1"
Expand Down Expand Up @@ -3314,7 +3313,7 @@ ws@8.0.0:
resolved "https://registry.yarnpkg.com/ws/-/ws-8.0.0.tgz#550605d13dfc1437c9ec1396975709c6d7ffc57d"
integrity sha512-6AcSIXpBlS0QvCVKk+3cWnWElLsA6SzC0lkQ43ciEglgXJXiCWK3/CGFEJ+Ybgp006CMibamAsqOlxE9s4AvYA==

"ws@^5.2.0 || ^6.0.0 || ^7.0.0", ws@^7.2.1:
"ws@^5.2.0 || ^6.0.0 || ^7.0.0", ws@^7.4.6:
version "7.5.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.3.tgz#160835b63c7d97bfab418fc1b8a9fced2ac01a74"
integrity sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==
Expand Down

0 comments on commit 8732bc0

Please sign in to comment.