Merge remote-tracking branch 'origin/main' into slash
This commit is contained in:
commit
a9338ad88a
10 changed files with 180 additions and 28 deletions
2
mod.ts
2
mod.ts
|
@ -92,7 +92,7 @@ export type {
|
|||
ChannelPayload,
|
||||
FollowedChannel,
|
||||
GuildNewsChannelPayload,
|
||||
GuildChannelCategoryPayload,
|
||||
GuildCategoryChannelPayload,
|
||||
GuildChannelPayload,
|
||||
GuildTextChannelPayload,
|
||||
GuildVoiceChannelPayload,
|
||||
|
|
|
@ -6,7 +6,6 @@ export const guildIntegrationsUpdate: GatewayEventHandler = async (
|
|||
gateway: Gateway,
|
||||
d: GuildIntegrationsUpdatePayload
|
||||
) => {
|
||||
console.log(d)
|
||||
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
|
||||
if (guild === undefined) return
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { CategoryChannel } from '../structures/guildCategoryChannel.ts'
|
|||
import { GuildTextChannel } from '../structures/textChannel.ts'
|
||||
import { VoiceChannel } from '../structures/guildVoiceChannel.ts'
|
||||
import {
|
||||
GuildChannelCategoryPayload,
|
||||
GuildCategoryChannelPayload,
|
||||
GuildTextChannelPayload,
|
||||
GuildVoiceChannelPayload
|
||||
} from '../types/channel.ts'
|
||||
|
@ -16,7 +16,7 @@ import { ChannelsManager } from './channels.ts'
|
|||
export type GuildChannelPayloads =
|
||||
| GuildTextChannelPayload
|
||||
| GuildVoiceChannelPayload
|
||||
| GuildChannelCategoryPayload
|
||||
| GuildCategoryChannelPayload
|
||||
export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel
|
||||
|
||||
export class GuildChannelsManager extends BaseChildManager<
|
||||
|
|
|
@ -1,38 +1,56 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { Channel } from './channel.ts'
|
||||
import { GuildChannelCategoryPayload, Overwrite } from '../types/channel.ts'
|
||||
import {
|
||||
GuildCategoryChannelPayload,
|
||||
ModifyGuildCategoryChannelOption,
|
||||
ModifyGuildCategoryChannelPayload,
|
||||
Overwrite
|
||||
} from '../types/channel.ts'
|
||||
import { Guild } from './guild.ts'
|
||||
import { CHANNEL } from '../types/endpoint.ts'
|
||||
|
||||
export class CategoryChannel extends Channel {
|
||||
guildID: string
|
||||
name: string
|
||||
position: number
|
||||
permissionOverwrites: Overwrite[]
|
||||
nsfw: boolean
|
||||
guild: Guild
|
||||
parentID?: string
|
||||
|
||||
constructor(client: Client, data: GuildChannelCategoryPayload, guild: Guild) {
|
||||
constructor(client: Client, data: GuildCategoryChannelPayload, guild: Guild) {
|
||||
super(client, data)
|
||||
this.guildID = data.guild_id
|
||||
this.name = data.name
|
||||
this.guild = guild
|
||||
this.position = data.position
|
||||
this.permissionOverwrites = data.permission_overwrites
|
||||
this.nsfw = data.nsfw
|
||||
this.parentID = data.parent_id
|
||||
// TODO: Cache in Gateway Event Code
|
||||
// cache.set('guildcategorychannel', this.id, this)
|
||||
}
|
||||
|
||||
readFromData(data: GuildChannelCategoryPayload): void {
|
||||
readFromData(data: GuildCategoryChannelPayload): void {
|
||||
super.readFromData(data)
|
||||
this.guildID = data.guild_id ?? this.guildID
|
||||
this.name = data.name ?? this.name
|
||||
this.position = data.position ?? this.position
|
||||
this.permissionOverwrites =
|
||||
data.permission_overwrites ?? this.permissionOverwrites
|
||||
this.nsfw = data.nsfw ?? this.nsfw
|
||||
this.parentID = data.parent_id ?? this.parentID
|
||||
}
|
||||
|
||||
async edit(
|
||||
options?: ModifyGuildCategoryChannelOption
|
||||
): Promise<CategoryChannel> {
|
||||
const body: ModifyGuildCategoryChannelPayload = {
|
||||
name: options?.name,
|
||||
position: options?.position,
|
||||
permission_overwrites: options?.permissionOverwrites,
|
||||
parent_id: options?.parentID
|
||||
}
|
||||
|
||||
const resp = await this.client.rest.patch(CHANNEL(this.id), body)
|
||||
|
||||
return new CategoryChannel(this.client, resp, this.guild)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { GuildNewsChannelPayload, Overwrite } from '../types/channel.ts'
|
||||
import {
|
||||
GuildNewsChannelPayload,
|
||||
ModifyGuildNewsChannelOption,
|
||||
ModifyGuildNewsChannelPayload,
|
||||
Overwrite
|
||||
} from '../types/channel.ts'
|
||||
import { CHANNEL } from '../types/endpoint.ts'
|
||||
import { Guild } from './guild.ts'
|
||||
import { TextChannel } from './textChannel.ts'
|
||||
|
||||
|
@ -36,4 +42,20 @@ export class NewsChannel extends TextChannel {
|
|||
this.parentID = data.parent_id ?? this.parentID
|
||||
this.topic = data.topic ?? this.topic
|
||||
}
|
||||
|
||||
async edit(options?: ModifyGuildNewsChannelOption): Promise<NewsChannel> {
|
||||
const body: ModifyGuildNewsChannelPayload = {
|
||||
name: options?.name,
|
||||
position: options?.position,
|
||||
permission_overwrites: options?.permissionOverwrites,
|
||||
parent_id: options?.parentID,
|
||||
type: options?.type,
|
||||
topic: options?.topic,
|
||||
nsfw: options?.nsfw
|
||||
}
|
||||
|
||||
const resp = await this.client.rest.patch(CHANNEL(this.id), body)
|
||||
|
||||
return new NewsChannel(this.client, resp, this.guild)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import { VoiceServerUpdateData } from '../gateway/handlers/index.ts'
|
||||
import { VoiceStateOptions } from '../gateway/index.ts'
|
||||
import { Client } from '../models/client.ts'
|
||||
import { GuildVoiceChannelPayload, Overwrite } from '../types/channel.ts'
|
||||
import {
|
||||
GuildVoiceChannelPayload,
|
||||
ModifyVoiceChannelOption,
|
||||
ModifyVoiceChannelPayload,
|
||||
Overwrite
|
||||
} from '../types/channel.ts'
|
||||
import { CHANNEL } from '../types/endpoint.ts'
|
||||
import { Channel } from './channel.ts'
|
||||
import { Guild } from './guild.ts'
|
||||
import { VoiceState } from './voiceState.ts'
|
||||
|
@ -14,7 +20,6 @@ export class VoiceChannel extends Channel {
|
|||
guild: Guild
|
||||
position: number
|
||||
permissionOverwrites: Overwrite[]
|
||||
nsfw: boolean
|
||||
parentID?: string
|
||||
|
||||
constructor(client: Client, data: GuildVoiceChannelPayload, guild: Guild) {
|
||||
|
@ -26,7 +31,6 @@ export class VoiceChannel extends Channel {
|
|||
this.position = data.position
|
||||
this.guild = guild
|
||||
this.permissionOverwrites = data.permission_overwrites
|
||||
this.nsfw = data.nsfw
|
||||
this.parentID = data.parent_id
|
||||
// TODO: Cache in Gateway Event Code
|
||||
// cache.set('guildvoicechannel', this.id, this)
|
||||
|
@ -85,7 +89,21 @@ export class VoiceChannel extends Channel {
|
|||
this.position = data.position ?? this.position
|
||||
this.permissionOverwrites =
|
||||
data.permission_overwrites ?? this.permissionOverwrites
|
||||
this.nsfw = data.nsfw ?? this.nsfw
|
||||
this.parentID = data.parent_id ?? this.parentID
|
||||
}
|
||||
|
||||
async edit(options?: ModifyVoiceChannelOption): Promise<VoiceChannel> {
|
||||
const body: ModifyVoiceChannelPayload = {
|
||||
name: options?.name,
|
||||
position: options?.position,
|
||||
permission_overwrites: options?.permissionOverwrites,
|
||||
parent_id: options?.parentID,
|
||||
bitrate: options?.bitrate,
|
||||
user_limit: options?.userLimit
|
||||
}
|
||||
|
||||
const resp = await this.client.rest.patch(CHANNEL(this.id), body)
|
||||
|
||||
return new VoiceChannel(this.client, resp, this.guild)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,16 @@ import {
|
|||
GuildTextChannelPayload,
|
||||
MessageOption,
|
||||
MessageReference,
|
||||
ModifyGuildTextChannelOption,
|
||||
ModifyGuildTextChannelPayload,
|
||||
Overwrite,
|
||||
TextChannelPayload
|
||||
} from '../types/channel.ts'
|
||||
import { CHANNEL_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts'
|
||||
import {
|
||||
CHANNEL,
|
||||
CHANNEL_MESSAGE,
|
||||
CHANNEL_MESSAGES
|
||||
} from '../types/endpoint.ts'
|
||||
import { Channel } from './channel.ts'
|
||||
import { Embed } from './embed.ts'
|
||||
import { Guild } from './guild.ts'
|
||||
|
@ -164,4 +170,19 @@ export class GuildTextChannel extends TextChannel {
|
|||
this.topic = data.topic ?? this.topic
|
||||
this.rateLimit = data.rate_limit_per_user ?? this.rateLimit
|
||||
}
|
||||
|
||||
async edit(
|
||||
options?: ModifyGuildTextChannelOption
|
||||
): Promise<GuildTextChannel> {
|
||||
const body: ModifyGuildTextChannelPayload = {
|
||||
name: options?.name,
|
||||
position: options?.position,
|
||||
permission_overwrites: options?.permissionOverwrites,
|
||||
parent_id: options?.parentID
|
||||
}
|
||||
|
||||
const resp = await this.client.rest.patch(CHANNEL(this.id), body)
|
||||
|
||||
return new GuildTextChannel(this.client, resp, this.guild)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,12 @@ client.on('channelUpdate', (b: EveryChannelTypes, a: EveryChannelTypes) => {
|
|||
if (b.type === ChannelTypes.GUILD_TEXT) {
|
||||
const before = (b as unknown) as GuildTextChannel
|
||||
const after = (a as unknown) as GuildTextChannel
|
||||
console.log(
|
||||
before.send('', {
|
||||
embed: new Embed({
|
||||
title: 'Channel Update',
|
||||
description: `Name Before: ${before.name}\nName After: ${after.name}`
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -94,6 +92,26 @@ client.on('messageCreate', async (msg: Message) => {
|
|||
})
|
||||
.join('\n') as string
|
||||
msg.channel.send('Channels List:\n' + data)
|
||||
} else if (msg.content === '!messages') {
|
||||
const col = await msg.channel.messages.array()
|
||||
const data = col
|
||||
?.slice(-5)
|
||||
.map((c: Message, i: number) => {
|
||||
return `${i + 1}. ${c.content}`
|
||||
})
|
||||
.join('\n') as string
|
||||
msg.channel.send('Top 5 Message List:\n' + data)
|
||||
} else if (msg.content === '!editChannel') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
const channel = msg.channel as GuildTextChannel
|
||||
const newChannel = await channel.edit({
|
||||
name: 'gggg'
|
||||
})
|
||||
if (newChannel.name === 'gggg') {
|
||||
msg.channel.send('Done!')
|
||||
} else {
|
||||
msg.channel.send('Failed...')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@ export interface GuildChannelPayload extends ChannelPayload {
|
|||
name: string
|
||||
position: number
|
||||
permission_overwrites: Overwrite[]
|
||||
nsfw: boolean
|
||||
parent_id?: string
|
||||
}
|
||||
|
||||
export interface GuildTextChannelPayload
|
||||
extends TextChannelPayload,
|
||||
GuildChannelPayload {
|
||||
nsfw: boolean
|
||||
rate_limit_per_user: number
|
||||
topic?: string
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ export interface GuildNewsChannelPayload
|
|||
extends TextChannelPayload,
|
||||
GuildChannelPayload {
|
||||
topic?: string
|
||||
nsfw: boolean
|
||||
}
|
||||
|
||||
export interface GuildVoiceChannelPayload extends GuildChannelPayload {
|
||||
|
@ -50,10 +51,65 @@ export interface GroupDMChannelPayload extends DMChannelPayload {
|
|||
owner_id: string
|
||||
}
|
||||
|
||||
export interface GuildChannelCategoryPayload
|
||||
export interface GuildCategoryChannelPayload
|
||||
extends ChannelPayload,
|
||||
GuildChannelPayload {}
|
||||
|
||||
export interface ModifyChannelPayload {
|
||||
name?: string
|
||||
position?: number | null
|
||||
permission_overwrites?: Overwrite[] | null
|
||||
parent_id?: string
|
||||
}
|
||||
|
||||
export interface ModifyGuildCategoryChannelPayload
|
||||
extends ModifyChannelPayload {}
|
||||
|
||||
export interface ModifyGuildTextChannelPayload extends ModifyChannelPayload {
|
||||
type?: number
|
||||
topic?: string | null
|
||||
nsfw?: boolean | null
|
||||
rate_limit_per_user?: number | null
|
||||
}
|
||||
|
||||
export interface ModifyGuildNewsChannelPayload extends ModifyChannelPayload {
|
||||
type?: number
|
||||
topic?: string | null
|
||||
nsfw?: boolean | null
|
||||
}
|
||||
|
||||
export interface ModifyVoiceChannelPayload extends ModifyChannelPayload {
|
||||
bitrate?: number | null
|
||||
user_limit?: number | null
|
||||
}
|
||||
|
||||
export interface ModifyChannelOption {
|
||||
name?: string
|
||||
position?: number | null
|
||||
permissionOverwrites?: Overwrite[] | null
|
||||
parentID?: string
|
||||
}
|
||||
|
||||
export interface ModifyGuildCategoryChannelOption extends ModifyChannelOption {}
|
||||
|
||||
export interface ModifyGuildTextChannelOption extends ModifyChannelOption {
|
||||
type?: number
|
||||
topic?: string | null
|
||||
nsfw?: boolean | null
|
||||
rateLimitPerUser?: number | null
|
||||
}
|
||||
|
||||
export interface ModifyGuildNewsChannelOption extends ModifyChannelOption {
|
||||
type?: number
|
||||
topic?: string | null
|
||||
nsfw?: boolean | null
|
||||
}
|
||||
|
||||
export interface ModifyVoiceChannelOption extends ModifyChannelOption {
|
||||
bitrate?: number | null
|
||||
userLimit?: number | null
|
||||
}
|
||||
|
||||
export interface Overwrite {
|
||||
id: string
|
||||
type: number
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
ChannelTypes,
|
||||
DMChannelPayload,
|
||||
GroupDMChannelPayload,
|
||||
GuildChannelCategoryPayload,
|
||||
GuildCategoryChannelPayload,
|
||||
GuildNewsChannelPayload,
|
||||
GuildTextChannelPayload,
|
||||
GuildVoiceChannelPayload,
|
||||
|
@ -41,7 +41,7 @@ export type EveryChannelTypes =
|
|||
|
||||
export type EveryChannelPayloadTypes =
|
||||
| ChannelPayload
|
||||
| GuildChannelCategoryPayload
|
||||
| GuildCategoryChannelPayload
|
||||
| GuildVoiceChannelPayload
|
||||
| EveryTextChannelPayloadTypes
|
||||
|
||||
|
@ -57,7 +57,7 @@ const getChannelByType = (
|
|||
throw new Error('No Guild was provided to construct Channel')
|
||||
return new CategoryChannel(
|
||||
client,
|
||||
data as GuildChannelCategoryPayload,
|
||||
data as GuildCategoryChannelPayload,
|
||||
guild
|
||||
)
|
||||
case ChannelTypes.GUILD_NEWS:
|
||||
|
|
Loading…
Reference in a new issue