added changes requested by Dj
This commit is contained in:
parent
620299462e
commit
4fc5734ccc
4 changed files with 62 additions and 14 deletions
|
@ -2,6 +2,7 @@ import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
import { Guild } from '../../structures/guild.ts'
|
import { Guild } from '../../structures/guild.ts'
|
||||||
import { InviteCreatePayload } from '../../types/gateway.ts'
|
import { InviteCreatePayload } from '../../types/gateway.ts'
|
||||||
import { ChannelPayload, GuildPayload, InvitePayload } from '../../../mod.ts'
|
import { ChannelPayload, GuildPayload, InvitePayload } from '../../../mod.ts'
|
||||||
|
import getChannelByType from '../../utils/getChannelByType.ts'
|
||||||
|
|
||||||
export const inviteCreate: GatewayEventHandler = async (
|
export const inviteCreate: GatewayEventHandler = async (
|
||||||
gateway: Gateway,
|
gateway: Gateway,
|
||||||
|
@ -13,20 +14,27 @@ export const inviteCreate: GatewayEventHandler = async (
|
||||||
// Weird case, shouldn't happen
|
// Weird case, shouldn't happen
|
||||||
if (guild === undefined) return
|
if (guild === undefined) return
|
||||||
|
|
||||||
const cachedChannel = await guild.channels.get(d.channel_id)
|
/**
|
||||||
|
* TODO(DjDeveloperr): Add _get method in BaseChildManager
|
||||||
|
*/
|
||||||
|
const cachedChannel = await gateway.client.channels._get(d.channel_id)
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||||
const cachedGuild: GuildPayload | undefined =
|
const cachedGuild: GuildPayload | undefined =
|
||||||
d.guild_id === undefined
|
d.guild_id === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: await guild.client.guilds._get(d.guild_id)
|
: await guild.client.guilds._get(d.guild_id)
|
||||||
|
|
||||||
const dataConverted: InvitePayload = {
|
const dataConverted: InvitePayload = {
|
||||||
code: d.code,
|
code: d.code,
|
||||||
guild: cachedGuild,
|
guild: cachedGuild,
|
||||||
|
// had to use `as ChannelPayload` because the _get method returned `ChannelPayload | undefined` which errored
|
||||||
channel: cachedChannel as ChannelPayload,
|
channel: cachedChannel as ChannelPayload,
|
||||||
inviter: d.inviter,
|
inviter: d.inviter,
|
||||||
target_user: d.target_user,
|
target_user: d.target_user,
|
||||||
target_user_type: d.target_user_type,
|
target_user_type: d.target_user_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||||
await guild.invites.set(d.code, dataConverted)
|
await guild.invites.set(d.code, dataConverted)
|
||||||
const invite = await guild.invites.get(d.code)
|
const invite = await guild.invites.get(d.code)
|
||||||
|
|
|
@ -15,7 +15,10 @@ export const inviteDelete: GatewayEventHandler = async (
|
||||||
const cachedInvite = await guild.invites.get(d.code)
|
const cachedInvite = await guild.invites.get(d.code)
|
||||||
|
|
||||||
// Should not happen but here we go
|
// Should not happen but here we go
|
||||||
if (cachedInvite === undefined) return
|
if (cachedInvite === undefined) {
|
||||||
|
return gateway.client.emit('inviteDeleteUncached', cachedInvite)
|
||||||
gateway.client.emit('inviteDelete', cachedInvite)
|
} else {
|
||||||
|
await guild.invites.delete(d.code)
|
||||||
|
gateway.client.emit('inviteDelete', cachedInvite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,12 @@ export class InviteManager extends BaseManager<InvitePayload, Invite> {
|
||||||
this.guild = guild
|
this.guild = guild
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async get(key: string): Promise<Invite | undefined> {
|
||||||
|
const raw = await this._get(key)
|
||||||
|
if (raw === undefined) return
|
||||||
|
return new Invite(this.client, raw)
|
||||||
|
}
|
||||||
|
|
||||||
async fetch(id: string): Promise<Invite> {
|
async fetch(id: string): Promise<Invite> {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this.client.rest
|
this.client.rest
|
||||||
|
@ -31,4 +37,4 @@ export class InviteManager extends BaseManager<InvitePayload, Invite> {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
import { Command, CommandClient, Intents, GuildChannel, CommandContext, Extension } from '../../mod.ts'
|
import {
|
||||||
|
Command,
|
||||||
|
CommandClient,
|
||||||
|
Intents,
|
||||||
|
GuildChannel,
|
||||||
|
CommandContext,
|
||||||
|
Extension,
|
||||||
|
} from '../../mod.ts'
|
||||||
|
import { Invite } from '../structures/invite.ts'
|
||||||
import { TOKEN } from './config.ts'
|
import { TOKEN } from './config.ts'
|
||||||
|
|
||||||
const client = new CommandClient({
|
const client = new CommandClient({
|
||||||
prefix: ["pls", "!"],
|
prefix: ['pls', '!'],
|
||||||
spacesAfterPrefix: true,
|
spacesAfterPrefix: true,
|
||||||
mentionPrefix: true
|
mentionPrefix: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('debug', console.log)
|
client.on('debug', console.log)
|
||||||
|
@ -55,10 +63,21 @@ client.on('webhooksUpdate', (guild, channel) => {
|
||||||
console.log(`Webhooks Updated in #${channel.name} from ${guild.name}`)
|
console.log(`Webhooks Updated in #${channel.name} from ${guild.name}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on("commandError", console.error)
|
client.on('inviteCreate', (invite: Invite) => {
|
||||||
|
console.log(`Invite Create: ${invite.code}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on('inviteDelete', (invite: Invite) => {
|
||||||
|
console.log(`Invite Delete: ${invite.code}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on('inviteDeleteUncached', (invite: Invite) => {
|
||||||
|
console.log(`Invite deleted uncached: ${invite}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on('commandError', console.error)
|
||||||
|
|
||||||
class ChannelLog extends Extension {
|
class ChannelLog extends Extension {
|
||||||
|
|
||||||
onChannelCreate(ext: Extension, channel: GuildChannel): void {
|
onChannelCreate(ext: Extension, channel: GuildChannel): void {
|
||||||
console.log(`Channel Created: ${channel.name}`)
|
console.log(`Channel Created: ${channel.name}`)
|
||||||
}
|
}
|
||||||
|
@ -81,15 +100,27 @@ class ChannelLog extends Extension {
|
||||||
client.extensions.load(ChannelLog)
|
client.extensions.load(ChannelLog)
|
||||||
|
|
||||||
client.on('messageDeleteBulk', (channel, messages, uncached) => {
|
client.on('messageDeleteBulk', (channel, messages, uncached) => {
|
||||||
console.log(`=== Message Delete Bulk ===\nMessages: ${messages.map(m => m.id).join(', ')}\nUncached: ${[...uncached.values()].join(', ')}`)
|
console.log(
|
||||||
|
`=== Message Delete Bulk ===\nMessages: ${messages
|
||||||
|
.map((m) => m.id)
|
||||||
|
.join(', ')}\nUncached: ${[...uncached.values()].join(', ')}`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('channelUpdate', (before, after) => {
|
client.on('channelUpdate', (before, after) => {
|
||||||
console.log(`Channel Update: ${(before as GuildChannel).name}, ${(after as GuildChannel).name}`)
|
console.log(
|
||||||
|
`Channel Update: ${(before as GuildChannel).name}, ${
|
||||||
|
(after as GuildChannel).name
|
||||||
|
}`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('typingStart', (user, channel, at, guildData) => {
|
client.on('typingStart', (user, channel, at, guildData) => {
|
||||||
console.log(`${user.tag} started typing in ${channel.id} at ${at}${guildData !== undefined ? `\nGuild: ${guildData.guild.name}` : ''}`)
|
console.log(
|
||||||
|
`${user.tag} started typing in ${channel.id} at ${at}${
|
||||||
|
guildData !== undefined ? `\nGuild: ${guildData.guild.name}` : ''
|
||||||
|
}`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// client.on('raw', (evt: string) => console.log(`EVENT: ${evt}`))
|
// client.on('raw', (evt: string) => console.log(`EVENT: ${evt}`))
|
||||||
|
@ -106,4 +137,4 @@ for (const file of files) {
|
||||||
|
|
||||||
console.log(`Loaded ${client.commands.count} commands!`)
|
console.log(`Loaded ${client.commands.count} commands!`)
|
||||||
|
|
||||||
client.connect(TOKEN, Intents.create(['GUILD_MEMBERS', 'GUILD_PRESENCES']))
|
client.connect(TOKEN, Intents.create(['GUILD_MEMBERS', 'GUILD_PRESENCES']))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue