harmony/test/cmd.ts

155 lines
3.8 KiB
TypeScript
Raw Normal View History

2020-12-02 12:29:52 +00:00
import {
Command,
CommandClient,
Intents,
CommandContext,
2020-12-03 04:42:26 +00:00
Extension,
2021-04-04 05:52:47 +00:00
GuildChannels,
Invite
} from '../mod.ts'
2020-12-02 12:29:52 +00:00
import { TOKEN } from './config.ts'
const client = new CommandClient({
prefix: ['pls', '!'],
spacesAfterPrefix: true,
mentionPrefix: true,
owners: ['422957901716652033']
2020-12-02 12:29:52 +00:00
})
client.on('debug', console.log)
client.on('ready', () => {
console.log(`[Login] Logged in as ${client.user?.tag}!`)
})
client.on('messageDelete', (msg) => {
console.log(`Message Deleted: ${msg.id}, ${msg.author.tag}, ${msg.content}`)
})
client.on('messageUpdate', (before, after) => {
console.log('Message Update')
console.log(`Before: ${before.author.tag}: ${before.content}`)
console.log(`After: ${after.author.tag}: ${after.content}`)
})
client.on('guildMemberAdd', (member) => {
console.log(`Member Join: ${member.user.tag}`)
})
client.on('guildMemberRemove', (member) => {
console.log(`Member Leave: ${member.user.tag}`)
})
client.on('guildRoleCreate', (role) => {
console.log(`Role Create: ${role.name}`)
})
client.on('guildRoleDelete', (role) => {
console.log(`Role Delete: ${role.name}`)
})
client.on('guildRoleUpdate', (role, after) => {
console.log(`Role Update: ${role.name}, ${after.name}`)
})
client.on('guildIntegrationsUpdate', (guild) => {
console.log(`Guild Integrations Update: ${guild.name}`)
})
client.on('webhooksUpdate', (guild, channel) => {
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}`)
})
2021-01-24 16:46:10 +00:00
client.on('inviteDeleteUncached', (invite) => {
2020-12-02 12:29:52 +00:00
console.log(invite)
})
client.on('commandError', console.error)
class ChannelLog extends Extension {
onChannelCreate(ext: Extension, channel: GuildChannels): void {
2020-12-02 12:29:52 +00:00
console.log(`Channel Created: ${channel.name}`)
}
load(): void {
this.listen('channelCreate', this.onChannelCreate)
class Pong extends Command {
name = 'Pong'
execute(ctx: CommandContext): any {
ctx.message.reply('Ping!')
}
}
this.commands.add(Pong)
}
}
client.extensions.load(ChannelLog)
client.on('messageDeleteBulk', (channel, messages, uncached) => {
console.log(
`=== Message Delete Bulk ===\nMessages: ${messages
.map((m) => m.id)
.join(', ')}\nUncached: ${[...uncached.values()].join(', ')}`
)
})
client.on('channelUpdate', (before, after) => {
console.log(
`Channel Update: ${(before as GuildChannels).name}, ${
(after as GuildChannels).name
2020-12-02 12:29:52 +00:00
}`
)
})
client.on('voiceStateAdd', (state) => {
console.log('VC Join', state.user.tag)
2020-12-02 12:29:52 +00:00
})
client.on('voiceStateRemove', (state) => {
console.log('VC Leave', state.user.tag)
2020-12-02 12:29:52 +00:00
})
client.on('messageReactionAdd', (reaction, user) => {
console.log(`${user.tag} reacted with ${reaction.emoji.name}`)
})
client.on('messageReactionRemove', (reaction, user) => {
console.log(`${user.tag} removed reaction ${reaction.emoji.name}`)
})
client.on('messageReactionRemoveEmoji', (message, emoji) => {
console.log(`All ${emoji.name} emoji reactions removed from ${message.id}`)
})
client.on('messageReactionRemoveAll', (message) => {
console.log(`All reactions remove from Message: ${message.id}`)
})
// client.on('raw', (evt: string) => console.log(`EVENT: ${evt}`))
2021-03-26 11:33:21 +00:00
const files = Deno.readDirSync('cmds')
2020-12-02 12:29:52 +00:00
for (const file of files) {
const module = await import(`./cmds/${file.name}`)
// eslint-disable-next-line new-cap
const cmd = new module.default()
client.commands.add(cmd)
console.log(`Loaded command ${cmd.name}!`)
}
console.log(`Loaded ${client.commands.count} commands!`)
client.connect(TOKEN, Intents.create(['GUILD_MEMBERS', 'GUILD_PRESENCES']))