feat(events:role): added guildRoleCreate, guildRoleDelete, guildRoleUpdate
This commit is contained in:
parent
44303dacb1
commit
5bb87ef1ba
5 changed files with 74 additions and 3 deletions
16
src/gateway/handlers/guildRoleCreate.ts
Normal file
16
src/gateway/handlers/guildRoleCreate.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { GuildRoleCreatePayload } from "../../types/gateway.ts"
|
||||
|
||||
export const guildRoleCreate: GatewayEventHandler = async (
|
||||
gateway: Gateway,
|
||||
d: GuildRoleCreatePayload
|
||||
) => {
|
||||
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
|
||||
// Weird case, shouldn't happen
|
||||
if (guild === undefined) return
|
||||
|
||||
await guild.roles.set(d.role.id, d.role)
|
||||
const role = await guild.roles.get(d.role.id)
|
||||
gateway.client.emit('guildRoleCreate', role)
|
||||
}
|
18
src/gateway/handlers/guildRoleDelete.ts
Normal file
18
src/gateway/handlers/guildRoleDelete.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { GuildRoleDeletePayload } from "../../types/gateway.ts"
|
||||
|
||||
export const guildRoleDelete: GatewayEventHandler = async (
|
||||
gateway: Gateway,
|
||||
d: GuildRoleDeletePayload
|
||||
) => {
|
||||
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
|
||||
// Weird case, shouldn't happen
|
||||
if (guild === undefined) return
|
||||
|
||||
const role = await guild.roles.get(d.role_id)
|
||||
// Shouldn't happen either
|
||||
if(role === undefined) return
|
||||
|
||||
gateway.client.emit('guildRoleDelete', role)
|
||||
}
|
21
src/gateway/handlers/guildRoleUpdate.ts
Normal file
21
src/gateway/handlers/guildRoleUpdate.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { GuildRoleUpdatePayload } from "../../types/gateway.ts"
|
||||
|
||||
export const guildRoleUpdate: GatewayEventHandler = async (
|
||||
gateway: Gateway,
|
||||
d: GuildRoleUpdatePayload
|
||||
) => {
|
||||
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
|
||||
// Weird case, shouldn't happen
|
||||
if (guild === undefined) return
|
||||
|
||||
const role = await guild.roles.get(d.role.id)
|
||||
await guild.roles.set(d.role.id, d.role)
|
||||
const newRole = await guild.roles.get(d.role.id)
|
||||
|
||||
// Shouldn't happen either
|
||||
if(role === undefined) return gateway.client.emit('guildRoleUpdateUncached', newRole)
|
||||
|
||||
gateway.client.emit('guildRoleUpdate', role, newRole)
|
||||
}
|
|
@ -19,6 +19,9 @@ import { guildEmojiUpdate } from "./guildEmojiUpdate.ts"
|
|||
import { guildMemberAdd } from "./guildMemberAdd.ts"
|
||||
import { guildMemberRemove } from "./guildMemberRemove.ts"
|
||||
import { guildMemberUpdate } from "./guildMemberUpdate.ts"
|
||||
import { guildRoleCreate } from "./guildRoleCreate.ts"
|
||||
import { guildRoleDelete } from "./guildRoleDelete.ts"
|
||||
import { guildRoleUpdate } from "./guildRoleUpdate.ts"
|
||||
|
||||
export const gatewayHandlers: {
|
||||
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
||||
|
@ -41,9 +44,9 @@ export const gatewayHandlers: {
|
|||
GUILD_MEMBER_REMOVE: guildMemberRemove,
|
||||
GUILD_MEMBER_UPDATE: guildMemberUpdate,
|
||||
GUILD_MEMBERS_CHUNK: undefined,
|
||||
GUILD_ROLE_CREATE: undefined,
|
||||
GUILD_ROLE_UPDATE: undefined,
|
||||
GUILD_ROLE_DELETE: undefined,
|
||||
GUILD_ROLE_CREATE: guildRoleCreate,
|
||||
GUILD_ROLE_UPDATE: guildRoleUpdate,
|
||||
GUILD_ROLE_DELETE: guildRoleDelete,
|
||||
INVITE_CREATE: undefined,
|
||||
INVITE_DELETE: undefined,
|
||||
MESSAGE_CREATE: messageCreate,
|
||||
|
|
|
@ -4,6 +4,7 @@ import { CommandContext } from "../models/command.ts"
|
|||
import { Extension } from "../models/extensions.ts"
|
||||
import { Member } from "../structures/member.ts"
|
||||
import { Message } from "../structures/message.ts"
|
||||
import { Role } from "../structures/role.ts"
|
||||
import { MessageDeletePayload } from "../types/gateway.ts"
|
||||
import { TOKEN } from './config.ts'
|
||||
|
||||
|
@ -45,6 +46,18 @@ client.on('guildMemberRemove', (member: Member) => {
|
|||
console.log(`Member Leave: ${member.user.tag}`)
|
||||
})
|
||||
|
||||
client.on('guildRoleCreate', (role: Role) => {
|
||||
console.log(`Role Create: ${role.name}`)
|
||||
})
|
||||
|
||||
client.on('guildRoleDelete', (role: Role) => {
|
||||
console.log(`Role Delete: ${role.name}`)
|
||||
})
|
||||
|
||||
client.on('guildRoleUpdate', (role: Role, after: Role) => {
|
||||
console.log(`Role Update: ${role.name}, ${after.name}`)
|
||||
})
|
||||
|
||||
// client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`))
|
||||
|
||||
client.on("commandError", console.error)
|
||||
|
|
Loading…
Reference in a new issue