Change names and format codes
This commit is contained in:
parent
0950279282
commit
5256f05f04
15 changed files with 303 additions and 232 deletions
|
@ -1,41 +1,43 @@
|
|||
import { Client, Message, Intents } from '../mod.ts'
|
||||
|
||||
const client = new Client();
|
||||
const client = new Client()
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log(`Logged in as ${client.user?.tag}!`);
|
||||
});
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user?.tag}!`)
|
||||
})
|
||||
|
||||
client.on("messageCreate", (msg: Message) => {
|
||||
if (msg.content === "!ping") {
|
||||
console.log("Command Used: Ping");
|
||||
msg.reply("pong!");
|
||||
}
|
||||
});
|
||||
client.on('messageCreate', (msg: Message) => {
|
||||
if (msg.content === '!ping') {
|
||||
console.log('Command Used: Ping')
|
||||
msg.reply('pong!')
|
||||
}
|
||||
})
|
||||
|
||||
console.log("discord.deno - ping example");
|
||||
console.log('harmony - ping example')
|
||||
|
||||
const token = prompt("Input Bot Token:");
|
||||
const token = prompt('Input Bot Token:')
|
||||
if (token === null) {
|
||||
console.log("No token provided");
|
||||
Deno.exit();
|
||||
console.log('No token provided')
|
||||
Deno.exit()
|
||||
}
|
||||
|
||||
const intents = prompt("Input Intents (0 = All, 1 = Presence, 2 = Server Members, 3 = None):");
|
||||
if (intents === null || !["0", "1", "2", "3"].includes(intents)) {
|
||||
console.log("No intents provided");
|
||||
Deno.exit();
|
||||
const intents = prompt(
|
||||
'Input Intents (0 = All, 1 = Presence, 2 = Server Members, 3 = None):'
|
||||
)
|
||||
if (intents === null || !['0', '1', '2', '3'].includes(intents)) {
|
||||
console.log('No intents provided')
|
||||
Deno.exit()
|
||||
}
|
||||
|
||||
let ints;
|
||||
if (intents === "0") {
|
||||
ints = Intents.All;
|
||||
} else if (intents === "1") {
|
||||
ints = Intents.Presence;
|
||||
} else if (intents === "2") {
|
||||
ints = Intents.GuildMembers;
|
||||
let ints
|
||||
if (intents === '0') {
|
||||
ints = Intents.All
|
||||
} else if (intents === '1') {
|
||||
ints = Intents.Presence
|
||||
} else if (intents === '2') {
|
||||
ints = Intents.GuildMembers
|
||||
} else {
|
||||
ints = Intents.None;
|
||||
ints = Intents.None
|
||||
}
|
||||
|
||||
client.connect(token, ints);
|
||||
client.connect(token, ints)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name": "discord.deno",
|
||||
"name": "harmony",
|
||||
"version": "1.0.0",
|
||||
"description": "Discord Deno API that is easy to use.",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/Helloyunho/discord.deno.git",
|
||||
"repository": "https://github.com/harmony/harmony.git",
|
||||
"author": "Helloyunho <yunho050840@gmail.com>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||
import cache from '../../models/cache.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { User } from '../../structures/user.ts'
|
||||
import { GuildBanRemovePayload } from '../../types/gateway.ts'
|
||||
|
||||
export const guildBanRemove: GatewayEventHandler = (
|
||||
export const guildBanRemove: GatewayEventHandler = async (
|
||||
gateway: Gateway,
|
||||
d: GuildBanRemovePayload
|
||||
) => {
|
||||
const guild: Guild = cache.get('guild', d.guild_id)
|
||||
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
|
||||
const user: User =
|
||||
cache.get('user', d.user.id) ?? new User(gateway.client, d.user)
|
||||
(await gateway.client.users.get(d.user.id)) ??
|
||||
new User(gateway.client, d.user)
|
||||
|
||||
if (guild !== undefined) {
|
||||
gateway.client.emit('guildBanRemove', guild, user)
|
||||
|
|
|
@ -1,52 +1,63 @@
|
|||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||
import { Guild } from '../../structures/guild.ts'
|
||||
import { GuildPayload, MemberPayload } from "../../types/guild.ts"
|
||||
import { MembersManager } from "../../managers/members.ts"
|
||||
import { GuildChannelPayload } from "../../types/channel.ts"
|
||||
import { RolePayload } from "../../types/role.ts"
|
||||
import { RolesManager } from "../../managers/roles.ts"
|
||||
import { GuildPayload, MemberPayload } from '../../types/guild.ts'
|
||||
import { MembersManager } from '../../managers/members.ts'
|
||||
import { GuildChannelPayload } from '../../types/channel.ts'
|
||||
import { RolePayload } from '../../types/role.ts'
|
||||
import { RolesManager } from '../../managers/roles.ts'
|
||||
|
||||
export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: GuildPayload) => {
|
||||
export const guildCreate: GatewayEventHandler = async (
|
||||
gateway: Gateway,
|
||||
d: GuildPayload
|
||||
) => {
|
||||
let guild: Guild | undefined = await gateway.client.guilds.get(d.id)
|
||||
if (guild !== undefined) {
|
||||
// It was just lazy load, so we don't fire the event as its gonna fire for every guild bot is in
|
||||
await gateway.client.guilds.set(d.id, d)
|
||||
|
||||
if (d.members !== undefined) {
|
||||
const members = new MembersManager(gateway.client, guild)
|
||||
await members.fromPayload(d.members as MemberPayload[])
|
||||
guild.members = members
|
||||
}
|
||||
|
||||
if (d.channels !== undefined) {
|
||||
for (const ch of d.channels as GuildChannelPayload[]) {
|
||||
ch.guild_id = d.id
|
||||
await gateway.client.channels.set(ch.id, ch)
|
||||
}
|
||||
}
|
||||
|
||||
if (d.roles !== undefined) {
|
||||
const roles = new RolesManager(gateway.client, guild)
|
||||
await roles.fromPayload(d.roles as RolePayload[])
|
||||
guild.roles = roles
|
||||
}
|
||||
|
||||
guild.refreshFromData(d)
|
||||
} else {
|
||||
await gateway.client.guilds.set(d.id, d)
|
||||
guild = new Guild(gateway.client, d)
|
||||
|
||||
if ((d as any).members !== undefined) {
|
||||
const members = new MembersManager(gateway.client, guild)
|
||||
await members.fromPayload(d.members as MemberPayload[])
|
||||
guild.members = members
|
||||
}
|
||||
|
||||
if (d.channels !== undefined) {
|
||||
for (const ch of d.channels as GuildChannelPayload[]) {
|
||||
(ch as any).guild_id = d.id
|
||||
;(ch as any).guild_id = d.id
|
||||
await gateway.client.channels.set(ch.id, ch)
|
||||
}
|
||||
}
|
||||
|
||||
if (d.roles !== undefined) {
|
||||
const roles = new RolesManager(gateway.client, guild)
|
||||
await roles.fromPayload(d.roles)
|
||||
guild.roles = roles
|
||||
}
|
||||
|
||||
await guild.roles.fromPayload(d.roles)
|
||||
guild = new Guild(gateway.client, d)
|
||||
gateway.client.emit('guildCreate', guild)
|
||||
|
|
|
@ -10,10 +10,12 @@ export const guildDelte: GatewayEventHandler = async (
|
|||
|
||||
if (guild !== undefined) {
|
||||
guild.refreshFromData(d)
|
||||
|
||||
await guild.members.flush()
|
||||
await guild.channels.flush()
|
||||
await guild.roles.flush()
|
||||
await gateway.client.guilds.delete(d.id)
|
||||
|
||||
gateway.client.emit('guildDelete', guild)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { Emoji } from '../structures/emoji.ts'
|
||||
import { Guild } from '../structures/guild.ts'
|
||||
import { EmojiPayload } from '../types/emoji.ts'
|
||||
import { CHANNEL } from '../types/endpoint.ts'
|
||||
import { GUILD_EMOJI } from '../types/endpoint.ts'
|
||||
import { BaseManager } from './base.ts'
|
||||
|
||||
export class EmojisManager extends BaseManager<EmojiPayload, Emoji> {
|
||||
constructor (client: Client) {
|
||||
super(client, 'emojis', Emoji)
|
||||
guild: Guild
|
||||
|
||||
constructor (client: Client, guild: Guild) {
|
||||
super(client, `emojis:${guild.id}`, Emoji)
|
||||
this.guild = guild
|
||||
}
|
||||
|
||||
async fetch (id: string): Promise<Emoji> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest
|
||||
.get(CHANNEL(id))
|
||||
.get(GUILD_EMOJI(this.guild.id, id))
|
||||
.then(data => {
|
||||
this.set(id, data as EmojiPayload)
|
||||
resolve(new Emoji(this.client, data as EmojiPayload))
|
||||
|
|
|
@ -1,41 +1,49 @@
|
|||
import { Client } from "../models/client.ts";
|
||||
import { Channel } from "../structures/channel.ts";
|
||||
import { Guild } from "../structures/guild.ts";
|
||||
import { CategoryChannel } from "../structures/guildCategoryChannel.ts";
|
||||
import { GuildTextChannel } from "../structures/guildTextChannel.ts";
|
||||
import { VoiceChannel } from "../structures/guildVoiceChannel.ts";
|
||||
import { GuildChannelCategoryPayload, GuildTextChannelPayload, GuildVoiceChannelPayload } from "../types/channel.ts";
|
||||
import { CHANNEL } from "../types/endpoint.ts";
|
||||
import { BaseChildManager } from "./baseChild.ts";
|
||||
import { ChannelsManager } from "./channels.ts";
|
||||
import { Client } from '../models/client.ts'
|
||||
import { Channel } from '../structures/channel.ts'
|
||||
import { Guild } from '../structures/guild.ts'
|
||||
import { CategoryChannel } from '../structures/guildCategoryChannel.ts'
|
||||
import { GuildTextChannel } from '../structures/guildTextChannel.ts'
|
||||
import { VoiceChannel } from '../structures/guildVoiceChannel.ts'
|
||||
import {
|
||||
GuildChannelCategoryPayload,
|
||||
GuildTextChannelPayload,
|
||||
GuildVoiceChannelPayload
|
||||
} from '../types/channel.ts'
|
||||
import { CHANNEL } from '../types/endpoint.ts'
|
||||
import { BaseChildManager } from './baseChild.ts'
|
||||
import { ChannelsManager } from './channels.ts'
|
||||
|
||||
export type GuildChannelPayloads = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload
|
||||
export type GuildChannelPayloads =
|
||||
| GuildTextChannelPayload
|
||||
| GuildVoiceChannelPayload
|
||||
| GuildChannelCategoryPayload
|
||||
export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel
|
||||
|
||||
export class GuildChannelsManager extends BaseChildManager<GuildChannelPayloads, GuildChannel> {
|
||||
export class GuildChannelsManager extends BaseChildManager<
|
||||
GuildChannelPayloads,
|
||||
GuildChannel
|
||||
> {
|
||||
guild: Guild
|
||||
|
||||
constructor(client: Client, parent: ChannelsManager, guild: Guild) {
|
||||
constructor (client: Client, parent: ChannelsManager, guild: Guild) {
|
||||
super(client, parent as any)
|
||||
this.guild = guild
|
||||
}
|
||||
|
||||
async get(id: string): Promise<GuildChannel | undefined> {
|
||||
async get (id: string): Promise<GuildChannel | undefined> {
|
||||
const res = await this.parent.get(id)
|
||||
if (res !== undefined && res.guild.id === this.guild.id) return res
|
||||
else return undefined
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<boolean> {
|
||||
return this.client.rest.delete(CHANNEL(id))
|
||||
async array (): Promise<GuildChannel[]> {
|
||||
const arr = (await this.parent.array()) as Channel[]
|
||||
return arr.filter(
|
||||
(c: any) => c.guild !== undefined && c.guild.id === this.guild.id
|
||||
) as any
|
||||
}
|
||||
|
||||
async array(): Promise<GuildChannel[]> {
|
||||
const arr = await this.parent.array() as Channel[]
|
||||
return arr.filter((c: any) => c.guild !== undefined && c.guild.id === this.guild.id) as any
|
||||
}
|
||||
|
||||
async flush(): Promise<boolean> {
|
||||
async flush (): Promise<boolean> {
|
||||
const arr = await this.array()
|
||||
for (const elem of arr) {
|
||||
this.parent.delete(elem.id)
|
||||
|
|
|
@ -1,27 +1,35 @@
|
|||
import { Client } from "../models/client.ts";
|
||||
import { Guild } from "../structures/guild.ts";
|
||||
import { GUILD } from "../types/endpoint.ts";
|
||||
import { GuildPayload, MemberPayload } from "../types/guild.ts";
|
||||
import { BaseManager } from "./base.ts";
|
||||
import { MembersManager } from "./members.ts";
|
||||
import { Client } from '../models/client.ts'
|
||||
import { Guild } from '../structures/guild.ts'
|
||||
import { GUILD } from '../types/endpoint.ts'
|
||||
import { GuildPayload, MemberPayload } from '../types/guild.ts'
|
||||
import { BaseManager } from './base.ts'
|
||||
import { MembersManager } from './members.ts'
|
||||
|
||||
export class GuildManager extends BaseManager<GuildPayload, Guild> {
|
||||
constructor (client: Client) {
|
||||
super(client, 'guilds', Guild)
|
||||
}
|
||||
|
||||
async fetch(id: string): Promise<Guild> {
|
||||
async fetch (id: string): Promise<Guild> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest.get(GUILD(id)).then(async (data: any) => {
|
||||
this.set(id, data)
|
||||
const guild = new Guild(this.client, data)
|
||||
if ((data as GuildPayload).members !== undefined) {
|
||||
const members = new MembersManager(this.client, guild)
|
||||
await members.fromPayload((data as GuildPayload).members as MemberPayload[])
|
||||
guild.members = members
|
||||
}
|
||||
resolve(guild)
|
||||
}).catch(e => reject(e))
|
||||
this.client.rest
|
||||
.get(GUILD(id))
|
||||
.then(async (data: any) => {
|
||||
this.set(id, data)
|
||||
|
||||
const guild = new Guild(this.client, data)
|
||||
|
||||
if ((data as GuildPayload).members !== undefined) {
|
||||
const members = new MembersManager(this.client, guild)
|
||||
await members.fromPayload(
|
||||
(data as GuildPayload).members as MemberPayload[]
|
||||
)
|
||||
guild.members = members
|
||||
}
|
||||
|
||||
resolve(guild)
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,64 @@
|
|||
import { Client } from "../models/client.ts";
|
||||
import { Message } from "../structures/message.ts";
|
||||
import { MessageMentions } from "../structures/messageMentions.ts";
|
||||
import { TextChannel } from "../structures/textChannel.ts";
|
||||
import { User } from "../structures/user.ts";
|
||||
import { MessagePayload } from "../types/channel.ts";
|
||||
import { CHANNEL_MESSAGE } from "../types/endpoint.ts";
|
||||
import { BaseManager } from "./base.ts";
|
||||
import { Client } from '../models/client.ts'
|
||||
import { Message } from '../structures/message.ts'
|
||||
import { MessageMentions } from '../structures/messageMentions.ts'
|
||||
import { TextChannel } from '../structures/textChannel.ts'
|
||||
import { User } from '../structures/user.ts'
|
||||
import { MessagePayload } from '../types/channel.ts'
|
||||
import { CHANNEL_MESSAGE } from '../types/endpoint.ts'
|
||||
import { BaseManager } from './base.ts'
|
||||
|
||||
export class MessagesManager extends BaseManager<MessagePayload, Message> {
|
||||
constructor (client: Client) {
|
||||
super(client, 'messages', Message)
|
||||
}
|
||||
|
||||
async get(key: string): Promise<Message | undefined> {
|
||||
async get (key: string): Promise<Message | undefined> {
|
||||
const raw = await this._get(key)
|
||||
if (raw === undefined) return
|
||||
|
||||
let channel = await this.client.channels.get(raw.channel_id)
|
||||
if (channel === undefined) channel = await this.client.channels.fetch(raw.channel_id)
|
||||
if (channel === undefined) return
|
||||
if (channel === undefined)
|
||||
channel = await this.client.channels.fetch(raw.channel_id)
|
||||
|
||||
const author = new User(this.client, raw.author)
|
||||
const mentions = new MessageMentions()
|
||||
|
||||
return new this.DataType(this.client, raw, channel, author, mentions) as any
|
||||
}
|
||||
|
||||
async fetch(channelID: string, id: string): Promise<Message> {
|
||||
async fetch (channelID: string, id: string): Promise<Message> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.client.rest.get(CHANNEL_MESSAGE(channelID, id)).then(async data => {
|
||||
this.set(id, data as MessagePayload)
|
||||
let channel: any = await this.client.channels.get<TextChannel>(channelID)
|
||||
if (channel === undefined) channel = await this.client.channels.fetch(channelID)
|
||||
const author = new User(this.client, (data as MessagePayload).author)
|
||||
await this.client.users.set(author.id, (data as MessagePayload).author)
|
||||
// TODO: Make this thing work (MessageMentions)
|
||||
const mentions = new MessageMentions()
|
||||
resolve(new Message(this.client, data as MessagePayload, channel as TextChannel, author, mentions))
|
||||
}).catch(e => reject(e))
|
||||
this.client.rest
|
||||
.get(CHANNEL_MESSAGE(channelID, id))
|
||||
.then(async data => {
|
||||
this.set(id, data as MessagePayload)
|
||||
|
||||
let channel: any = await this.client.channels.get<TextChannel>(
|
||||
channelID
|
||||
)
|
||||
if (channel === undefined)
|
||||
channel = await this.client.channels.fetch(channelID)
|
||||
|
||||
const author = new User(this.client, (data as MessagePayload).author)
|
||||
await this.client.users.set(
|
||||
author.id,
|
||||
(data as MessagePayload).author
|
||||
)
|
||||
|
||||
// TODO: Make this thing work (MessageMentions)
|
||||
const mentions = new MessageMentions()
|
||||
|
||||
resolve(
|
||||
new Message(
|
||||
this.client,
|
||||
data as MessagePayload,
|
||||
channel as TextChannel,
|
||||
author,
|
||||
mentions
|
||||
)
|
||||
)
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,20 +3,24 @@ import { GatewayIntents } from '../types/gateway.ts'
|
|||
import { Gateway } from '../gateway/index.ts'
|
||||
import { RESTManager } from './rest.ts'
|
||||
import EventEmitter from 'https://deno.land/std@0.74.0/node/events.ts'
|
||||
import { DefaultCacheAdapter, ICacheAdapter } from "./cacheAdapter.ts"
|
||||
import { UserManager } from "../managers/users.ts"
|
||||
import { GuildManager } from "../managers/guilds.ts"
|
||||
import { EmojisManager } from "../managers/emojis.ts"
|
||||
import { ChannelsManager } from "../managers/channels.ts"
|
||||
import { MessagesManager } from "../managers/messages.ts"
|
||||
import { ActivityGame, ClientActivity, ClientPresence } from "../structures/presence.ts"
|
||||
import { DefaultCacheAdapter, ICacheAdapter } from './cacheAdapter.ts'
|
||||
import { UserManager } from '../managers/users.ts'
|
||||
import { GuildManager } from '../managers/guilds.ts'
|
||||
import { EmojisManager } from '../managers/emojis.ts'
|
||||
import { ChannelsManager } from '../managers/channels.ts'
|
||||
import { MessagesManager } from '../managers/messages.ts'
|
||||
import {
|
||||
ActivityGame,
|
||||
ClientActivity,
|
||||
ClientPresence
|
||||
} from '../structures/presence.ts'
|
||||
|
||||
/** Some Client Options to modify behaviour */
|
||||
export interface ClientOptions {
|
||||
token?: string
|
||||
intents?: GatewayIntents[]
|
||||
cache?: ICacheAdapter,
|
||||
forceNewSession?: boolean,
|
||||
cache?: ICacheAdapter
|
||||
forceNewSession?: boolean
|
||||
presence?: ClientPresence | ClientActivity | ActivityGame
|
||||
bot?: boolean
|
||||
canary?: boolean
|
||||
|
@ -31,7 +35,7 @@ export class Client extends EventEmitter {
|
|||
user?: User
|
||||
ping = 0
|
||||
token?: string
|
||||
cache: ICacheAdapter = new DefaultCacheAdapter()
|
||||
cache: ICacheAdapter = new DefaultCacheAdapter(this)
|
||||
intents?: GatewayIntents[]
|
||||
forceNewSession?: boolean
|
||||
users: UserManager = new UserManager(this)
|
||||
|
@ -50,7 +54,11 @@ export class Client extends EventEmitter {
|
|||
this.intents = options.intents
|
||||
this.forceNewSession = options.forceNewSession
|
||||
if (options.cache !== undefined) this.cache = options.cache
|
||||
if (options.presence !== undefined) this.presence = options.presence instanceof ClientPresence ? options.presence : new ClientPresence(options.presence)
|
||||
if (options.presence !== undefined)
|
||||
this.presence =
|
||||
options.presence instanceof ClientPresence
|
||||
? options.presence
|
||||
: new ClientPresence(options.presence)
|
||||
if (options.bot === false) this.bot = false
|
||||
if (options.canary === true) this.canary = true
|
||||
}
|
||||
|
@ -68,7 +76,7 @@ export class Client extends EventEmitter {
|
|||
}
|
||||
|
||||
debug (tag: string, msg: string): void {
|
||||
this.emit("debug", `[${tag}] ${msg}`)
|
||||
this.emit('debug', `[${tag}] ${msg}`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,7 @@ export interface CommandTexts {
|
|||
export const DefaultCommandTexts: CommandTexts = {
|
||||
GUILD_ONLY: 'This command can only be used in a Server!',
|
||||
OWNER_ONLY: 'This command can only be used by Bot Owners!',
|
||||
DMS_ONLY: 'This command can only be used in Bot\'s DMs!',
|
||||
DMS_ONLY: "This command can only be used in Bot's DMs!",
|
||||
ERROR: 'An error occured while executing command!'
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ export const massReplace = (text: string, replaces: Replaces): string => {
|
|||
return text
|
||||
}
|
||||
|
||||
export class CommandClient extends Client {
|
||||
export class CommandClient extends Client implements CommandClientOptions {
|
||||
prefix: string | string[]
|
||||
mentionPrefix: boolean
|
||||
getGuildPrefix: (guildID: string) => PrefixReturnType
|
||||
|
@ -58,23 +58,38 @@ export class CommandClient extends Client {
|
|||
commands: CommandsManager = new CommandsManager(this)
|
||||
texts: CommandTexts = DefaultCommandTexts
|
||||
|
||||
constructor(options: CommandClientOptions) {
|
||||
constructor (options: CommandClientOptions) {
|
||||
super(options)
|
||||
this.prefix = options.prefix
|
||||
this.mentionPrefix = options.mentionPrefix === undefined ? false : options.mentionPrefix
|
||||
this.getGuildPrefix = options.getGuildPrefix === undefined ? (id: string) => this.prefix : options.getGuildPrefix
|
||||
this.getUserPrefix = options.getUserPrefix === undefined ? (id: string) => this.prefix : options.getUserPrefix
|
||||
this.spacesAfterPrefix = options.spacesAfterPrefix === undefined ? false : options.spacesAfterPrefix
|
||||
this.betterArgs = options.betterArgs === undefined ? false : options.betterArgs
|
||||
this.mentionPrefix =
|
||||
options.mentionPrefix === undefined ? false : options.mentionPrefix
|
||||
this.getGuildPrefix =
|
||||
options.getGuildPrefix === undefined
|
||||
? (id: string) => this.prefix
|
||||
: options.getGuildPrefix
|
||||
this.getUserPrefix =
|
||||
options.getUserPrefix === undefined
|
||||
? (id: string) => this.prefix
|
||||
: options.getUserPrefix
|
||||
this.spacesAfterPrefix =
|
||||
options.spacesAfterPrefix === undefined
|
||||
? false
|
||||
: options.spacesAfterPrefix
|
||||
this.betterArgs =
|
||||
options.betterArgs === undefined ? false : options.betterArgs
|
||||
this.owners = options.owners === undefined ? [] : options.owners
|
||||
this.allowBots = options.allowBots === undefined ? false : options.allowBots
|
||||
this.allowDMs = options.allowDMs === undefined ? true : options.allowDMs
|
||||
this.caseSensitive = options.caseSensitive === undefined ? false : options.caseSensitive
|
||||
this.caseSensitive =
|
||||
options.caseSensitive === undefined ? false : options.caseSensitive
|
||||
|
||||
this.on('messageCreate', async (msg: Message) => await this.processMessage(msg))
|
||||
this.on(
|
||||
'messageCreate',
|
||||
async (msg: Message) => await this.processMessage(msg)
|
||||
)
|
||||
}
|
||||
|
||||
async processMessage(msg: Message): Promise<any> {
|
||||
async processMessage (msg: Message): Promise<any> {
|
||||
if (!this.allowBots && msg.author.bot === true) return
|
||||
|
||||
let prefix: string | string[] = this.prefix
|
||||
|
@ -113,15 +128,18 @@ export class CommandClient extends Client {
|
|||
}
|
||||
|
||||
if (command.guildOnly === true && msg.guild === undefined) {
|
||||
if (this.texts.GUILD_ONLY !== undefined) return this.sendProcessedText(msg, this.texts.GUILD_ONLY, baseReplaces)
|
||||
if (this.texts.GUILD_ONLY !== undefined)
|
||||
return this.sendProcessedText(msg, this.texts.GUILD_ONLY, baseReplaces)
|
||||
return
|
||||
}
|
||||
if (command.dmOnly === true && msg.guild !== undefined) {
|
||||
if (this.texts.DMS_ONLY !== undefined) return this.sendProcessedText(msg, this.texts.DMS_ONLY, baseReplaces)
|
||||
if (this.texts.DMS_ONLY !== undefined)
|
||||
return this.sendProcessedText(msg, this.texts.DMS_ONLY, baseReplaces)
|
||||
return
|
||||
}
|
||||
if (command.ownerOnly === true && !this.owners.includes(msg.author.id)) {
|
||||
if (this.texts.OWNER_ONLY !== undefined) return this.sendProcessedText(msg, this.texts.OWNER_ONLY, baseReplaces)
|
||||
if (this.texts.OWNER_ONLY !== undefined)
|
||||
return this.sendProcessedText(msg, this.texts.OWNER_ONLY, baseReplaces)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -141,20 +159,29 @@ export class CommandClient extends Client {
|
|||
this.emit('commandUsed', { context: ctx })
|
||||
command.execute(ctx)
|
||||
} catch (e) {
|
||||
if (this.texts.ERROR !== undefined) return this.sendProcessedText(msg, this.texts.ERROR, Object.assign(baseReplaces, { error: e.message }))
|
||||
if (this.texts.ERROR !== undefined)
|
||||
return this.sendProcessedText(
|
||||
msg,
|
||||
this.texts.ERROR,
|
||||
Object.assign(baseReplaces, { error: e.message })
|
||||
)
|
||||
this.emit('commandError', { command, parsed, error: e })
|
||||
}
|
||||
}
|
||||
|
||||
sendProcessedText(msg: Message, text: CommandText, replaces: Replaces): any {
|
||||
if (typeof text === "string") {
|
||||
sendProcessedText (msg: Message, text: CommandText, replaces: Replaces): any {
|
||||
if (typeof text === 'string') {
|
||||
text = massReplace(text, replaces)
|
||||
return msg.channel.send(text)
|
||||
} else {
|
||||
if (text.description !== undefined) text.description = massReplace(text.description, replaces)
|
||||
if (text.title !== undefined) text.description = massReplace(text.title, replaces)
|
||||
if (text.author?.name !== undefined) text.description = massReplace(text.author.name, replaces)
|
||||
if (text.footer?.text !== undefined) text.description = massReplace(text.footer.text, replaces)
|
||||
if (text.description !== undefined)
|
||||
text.description = massReplace(text.description, replaces)
|
||||
if (text.title !== undefined)
|
||||
text.description = massReplace(text.title, replaces)
|
||||
if (text.author?.name !== undefined)
|
||||
text.description = massReplace(text.author.name, replaces)
|
||||
if (text.footer?.text !== undefined)
|
||||
text.description = massReplace(text.footer.text, replaces)
|
||||
return msg.channel.send(text)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { delay } from '../utils/index.ts'
|
||||
import * as baseEndpoints from '../consts/urlsAndVersions.ts'
|
||||
import { Client } from './client.ts'
|
||||
import { getBuildInfo } from "../utils/buildInfo.ts"
|
||||
import { getBuildInfo } from '../utils/buildInfo.ts'
|
||||
|
||||
export enum HttpResponseCode {
|
||||
Ok = 200,
|
||||
|
@ -156,7 +156,7 @@ export class RESTManager {
|
|||
): { [key: string]: any } {
|
||||
const headers: { [key: string]: string } = {
|
||||
Authorization: `Bot ${this.client.token}`,
|
||||
'User-Agent': `DiscordBot (discord.deno)`
|
||||
'User-Agent': `DiscordBot (harmony)`
|
||||
}
|
||||
|
||||
if (this.client.token === undefined) delete headers.Authorization
|
||||
|
@ -190,7 +190,9 @@ export class RESTManager {
|
|||
data.headers['sec-fetch-dest'] = 'empty'
|
||||
data.headers['sec-fetch-mode'] = 'cors'
|
||||
data.headers['sec-fetch-site'] = 'same-origin'
|
||||
data.headers['x-super-properties'] = btoa(JSON.stringify(getBuildInfo(this.client)))
|
||||
data.headers['x-super-properties'] = btoa(
|
||||
JSON.stringify(getBuildInfo(this.client))
|
||||
)
|
||||
delete data.headers['User-Agent']
|
||||
delete data.headers.Authorization
|
||||
headers.credentials = 'include'
|
||||
|
@ -259,10 +261,7 @@ export class RESTManager {
|
|||
|
||||
const requestData = this.createRequestBody(body, method)
|
||||
|
||||
const response = await fetch(
|
||||
urlToUse,
|
||||
requestData
|
||||
)
|
||||
const response = await fetch(urlToUse, requestData)
|
||||
const bucketIDFromHeaders = this.processHeaders(url, response.headers)
|
||||
this.handleStatusCode(response, errorStack)
|
||||
|
||||
|
@ -328,7 +327,8 @@ export class RESTManager {
|
|||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.logErrors(response, errorStack)
|
||||
|
||||
if (status === HttpResponseCode.Unauthorized) throw new Error("Request was not successful. Invalid Token.")
|
||||
if (status === HttpResponseCode.Unauthorized)
|
||||
throw new Error('Request was not successful. Invalid Token.')
|
||||
|
||||
switch (status) {
|
||||
case HttpResponseCode.BadRequest:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
|
||||
// https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
|
||||
import { StatusType } from "../../mod.ts"
|
||||
import { StatusType } from '../../mod.ts'
|
||||
import { EmojiPayload } from './emoji.ts'
|
||||
import { MemberPayload } from './guild.ts'
|
||||
import { ActivityPayload } from './presence.ts'
|
||||
|
@ -122,8 +122,8 @@ export enum UpdateStatus {
|
|||
|
||||
export interface IdentityConnection {
|
||||
$os: 'darwin' | 'windows' | 'linux' | 'custom os'
|
||||
$browser: 'discord.deno'
|
||||
$device: 'discord.deno'
|
||||
$browser: 'harmony'
|
||||
$device: 'harmony'
|
||||
}
|
||||
|
||||
export interface Resume {
|
||||
|
|
|
@ -1,40 +1,53 @@
|
|||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Client } from "../models/client.ts";
|
||||
import { Client } from '../models/client.ts'
|
||||
|
||||
export const getBuildInfo = (client: Client): {
|
||||
os: string
|
||||
os_version: string
|
||||
browser: string
|
||||
browser_version: string
|
||||
browser_user_agent: string
|
||||
client_build_number: number
|
||||
client_event_source: null
|
||||
release_channel: string
|
||||
export const getBuildInfo = (
|
||||
client: Client
|
||||
): {
|
||||
os: string
|
||||
os_version: string
|
||||
browser: string
|
||||
browser_version: string
|
||||
browser_user_agent: string
|
||||
client_build_number: number
|
||||
client_event_source: null
|
||||
release_channel: string
|
||||
} => {
|
||||
const os = 'Windows'
|
||||
const os_version = '10'
|
||||
let client_build_number = 71073
|
||||
const client_event_source = null
|
||||
let release_channel = 'stable'
|
||||
if (client.canary === true) {
|
||||
release_channel = 'canary'
|
||||
client_build_number = 71076
|
||||
}
|
||||
const browser = 'Firefox'
|
||||
const browser_version = '83.0'
|
||||
const browser_user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 ' + browser + '/' + browser_version
|
||||
// TODO: Use current OS properties, but also browser_user_agent accordingly
|
||||
// if (Deno.build.os === 'darwin') os = 'MacOS'
|
||||
// else if (Deno.build.os === 'linux') os = 'Ubuntu'
|
||||
let os = 'Windows'
|
||||
let os_version = '10'
|
||||
let client_build_number = 71073
|
||||
const client_event_source = null
|
||||
let release_channel = 'stable'
|
||||
if (client.canary === true) {
|
||||
release_channel = 'canary'
|
||||
client_build_number = 71076
|
||||
}
|
||||
let browser = 'Firefox'
|
||||
let browser_version = '83.0'
|
||||
let browser_user_agent =
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 ' +
|
||||
browser +
|
||||
'/' +
|
||||
browser_version
|
||||
// TODO: Use current OS properties, but also browser_user_agent accordingly
|
||||
if (Deno.build.os === 'darwin') {
|
||||
os = 'MacOS'
|
||||
os_version = '10.15.6'
|
||||
browser = 'Safari'
|
||||
browser_version = '14.0.1'
|
||||
browser_user_agent =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15'
|
||||
}
|
||||
// else if (Deno.build.os === 'linux') os = 'Ubuntu'
|
||||
|
||||
return {
|
||||
os,
|
||||
os_version,
|
||||
browser,
|
||||
browser_version,
|
||||
browser_user_agent,
|
||||
client_build_number,
|
||||
client_event_source,
|
||||
release_channel,
|
||||
}
|
||||
};
|
||||
return {
|
||||
os,
|
||||
os_version,
|
||||
browser,
|
||||
browser_version,
|
||||
browser_user_agent,
|
||||
client_build_number,
|
||||
client_event_source,
|
||||
release_channel
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { GatewayIntents } from "../types/gateway.ts";
|
||||
import { GatewayIntents } from '../types/gateway.ts'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||
export class Intents {
|
||||
|
@ -18,55 +18,19 @@ export class Intents {
|
|||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
];
|
||||
]
|
||||
|
||||
static Presence: number[] = [
|
||||
GatewayIntents.GUILD_PRESENCES,
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
];
|
||||
GatewayIntents.GUILDS
|
||||
]
|
||||
|
||||
static GuildMembers: number[] = [
|
||||
GatewayIntents.GUILD_MEMBERS,
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
];
|
||||
|
||||
static None: number[] = [
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
GatewayIntents.GUILD_VOICE_STATES
|
||||
]
|
||||
|
||||
static None: number[] = []
|
||||
}
|
Loading…
Reference in a new issue