-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚗️ chore: sorry but seriously i forgor what i was doing
- Loading branch information
1 parent
1b7bde4
commit 93b5b06
Showing
58 changed files
with
1,084 additions
and
845 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// deno-lint-ignore-file no-explicit-any | ||
import { Collection } from "./collection.ts"; | ||
|
||
export class CacheManager extends Collection<string, Collection<string, any>> { | ||
constructor() { | ||
super(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import type { | ||
GetChannelMessagesParams, | ||
MessagePayload, | ||
} from "../../../types/mod.ts"; | ||
import type { Client } from "../client/mod.ts"; | ||
import { Message } from "../structures/messages/mod.ts"; | ||
import { BaseManager } from "./base.ts"; | ||
|
||
export class MessagesManager extends BaseManager<MessagePayload, Message> { | ||
constructor(client: Client) { | ||
super(client); | ||
} | ||
|
||
_fill(messages: MessagePayload[]) { | ||
for (const message of messages) { | ||
this.set(message.id!, message); | ||
} | ||
} | ||
|
||
async _fetch( | ||
channelID: string, | ||
id: string, | ||
): Promise<MessagePayload | undefined> { | ||
try { | ||
const resp: MessagePayload | undefined = await this.client.rest.get( | ||
`/channels/${channelID}/messages/${id}`, | ||
); | ||
if (!resp) return; | ||
this.set(id, resp); | ||
return resp; | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
async _fetchBulk( | ||
channelID: string, | ||
options: GetChannelMessagesParams, | ||
): Promise<MessagePayload[] | undefined> { | ||
try { | ||
const query: Record<string, string> = { | ||
...options, | ||
limit: "", | ||
}; | ||
if (options.limit) { | ||
if (options.limit > 100 || options.limit < 1) { | ||
throw new Error("Limit must be in range 1-100"); | ||
} | ||
query.limit = options.limit.toString(); | ||
} else { | ||
delete query.limit; | ||
} | ||
const resp: MessagePayload[] | undefined = await this.client.rest.get( | ||
`/channels/${channelID}/messages`, | ||
{ | ||
query, | ||
}, | ||
); | ||
if (!resp) return; | ||
return resp.map((message) => { | ||
this.set(message.id!, message); | ||
return message; | ||
}); | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
|
||
get( | ||
id: string, | ||
) { | ||
const cached = this._get(id); | ||
if (!cached) return; | ||
return new Message(this.client, cached); | ||
} | ||
async fetch( | ||
channelID: string, | ||
id: string, | ||
) { | ||
try { | ||
const payload = await this._fetch(channelID, id); | ||
if (!payload) return; | ||
return new Message(this.client, payload); | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { GuildMemberPayload } from "../../../../types/mod.ts"; | ||
import type { Client } from "../../client/mod.ts"; | ||
|
||
export class Member { | ||
client: Client; | ||
payload: GuildMemberPayload; | ||
|
||
constructor(client: Client, payload: GuildMemberPayload) { | ||
this.client = client; | ||
this.payload = payload; | ||
if (payload.user) { | ||
this.client.users.set(payload.user.id, payload.user); | ||
} | ||
} | ||
|
||
get id() { | ||
return this.payload.user?.id; | ||
} | ||
get user() { | ||
return this.id ? this.client.users.get(this.id) : undefined; | ||
} | ||
get nick() { | ||
return this.payload.nick ?? this.user?.name; | ||
} | ||
get avatar() { | ||
// TODO: give default avatar | ||
// (also) TODO: give the url instead of hash | ||
return this.payload.avatar ?? this.user?.avatar; | ||
} | ||
get roles() { | ||
return this.payload.roles.map((id) => this.client.roles.get(id)); | ||
} | ||
get joinedAt() { | ||
return Date.parse(this.payload.joined_at); | ||
} | ||
get premiumSince() { | ||
return this.payload.premium_since ?? null; | ||
} | ||
get deaf() { | ||
return this.payload.deaf; | ||
} | ||
get mute() { | ||
return this.payload.mute; | ||
} | ||
get flags() { | ||
// TODO: make flags class | ||
return this.payload.flags; | ||
} | ||
get pending() { | ||
return this.payload.pending ?? false; | ||
} | ||
get permissions() { | ||
// TODO: make permissions class | ||
// also TODO: use roles to calculate permissions - permissions in payload is not available in all cases | ||
return this.payload.permissions; | ||
} | ||
get timeOutEnd() { | ||
return this.payload.communication_disabled_until | ||
? Date.parse(this.payload.communication_disabled_until) | ||
: null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GatewayIntent } from "../../mod.ts"; | ||
import { Client } from "../mod.ts"; | ||
|
||
const token = Deno.env.get("BOT_TOKEN"); | ||
if (!token) { | ||
throw new Error("No token provided"); | ||
} | ||
|
||
Deno.test("client", { | ||
sanitizeOps: false, | ||
}, async (t) => { | ||
await t.step("ready event", async () => { | ||
const client = new Client(token); | ||
await client.connect(); | ||
for await (const _ of client.on("ready")) { | ||
await client.gateway.destroyAll(); | ||
break; | ||
} | ||
}); | ||
|
||
await t.step("guild create event", async () => { | ||
const client = new Client(token, { | ||
intents: GatewayIntent.GUILDS, | ||
}); | ||
await client.connect(); | ||
for await (const [guild] of client.on("guildCreate")) { | ||
if (guild.id === "783319033205751809") { | ||
await client.gateway.destroyAll(); | ||
break; | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { GatewayIntent } from "../../mod.ts"; | ||
import { Client, GuildChannel } from "../mod.ts"; | ||
|
||
const TOKEN = Deno.env.get("BOT_TOKEN"); | ||
if (!TOKEN) { | ||
throw new Error("No token provided"); | ||
} | ||
|
||
const client = new Client(TOKEN, { | ||
intents: GatewayIntent.GUILDS | GatewayIntent.GUILD_MESSAGES, | ||
}); | ||
|
||
client.on("guildCreate", (guild) => { | ||
console.log(guild.name); | ||
}); | ||
|
||
client.on("messageCreate", (msg) => { | ||
if (msg.author.bot) return; | ||
console.log(msg.guild!.id); | ||
msg.channel?.send(`${msg.guild!.id}: ${msg.channel.id}`); | ||
}); | ||
|
||
client.on("channelCreate", (channel) => { | ||
if (channel instanceof GuildChannel) { | ||
console.log(channel.name); | ||
console.log(client.channels.cache.size); | ||
} | ||
}); | ||
|
||
client.on("channelDelete", (channel) => { | ||
if (channel instanceof GuildChannel) { | ||
console.log(channel.name); | ||
console.log(client.channels.cache.size); | ||
} | ||
}); | ||
|
||
client.connect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/[email protected]/assert/mod.ts"; |
Oops, something went wrong.