2020-12-02 12:29:52 +00:00
|
|
|
import {
|
|
|
|
Client,
|
|
|
|
Intents,
|
|
|
|
Message,
|
|
|
|
ClientPresence,
|
|
|
|
Member,
|
|
|
|
Role,
|
|
|
|
GuildChannel,
|
|
|
|
Embed,
|
|
|
|
Guild,
|
|
|
|
EveryChannelTypes,
|
|
|
|
ChannelTypes,
|
|
|
|
GuildTextChannel
|
|
|
|
} from '../../mod.ts'
|
2020-10-22 15:55:42 +00:00
|
|
|
import { TOKEN } from './config.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-11-06 07:31:53 +00:00
|
|
|
const client = new Client({
|
2020-11-02 07:27:14 +00:00
|
|
|
presence: new ClientPresence({
|
2020-12-02 12:29:52 +00:00
|
|
|
name: 'Pokémon Sword',
|
|
|
|
type: 'COMPETING'
|
|
|
|
})
|
2020-11-06 10:42:00 +00:00
|
|
|
// bot: false,
|
2020-11-06 08:27:56 +00:00
|
|
|
// cache: new RedisCacheAdapter({
|
|
|
|
// hostname: '127.0.0.1',
|
|
|
|
// port: 6379
|
|
|
|
// }) // Defaults to in-memory Caching
|
2020-11-02 07:27:14 +00:00
|
|
|
})
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-11-06 07:31:53 +00:00
|
|
|
client.on('ready', () => {
|
|
|
|
console.log(`[Login] Logged in as ${client.user?.tag}!`)
|
2020-10-25 17:03:53 +00:00
|
|
|
})
|
2020-10-23 16:11:00 +00:00
|
|
|
|
2020-11-06 07:31:53 +00:00
|
|
|
client.on('debug', console.log)
|
2020-10-31 11:45:33 +00:00
|
|
|
|
2020-12-02 12:29:52 +00:00
|
|
|
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}`
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2020-11-06 07:31:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
client.on('messageCreate', async (msg: Message) => {
|
2020-11-03 07:12:22 +00:00
|
|
|
if (msg.author.bot === true) return
|
2020-11-06 10:42:00 +00:00
|
|
|
console.log(`${msg.author.tag}: ${msg.content}`)
|
2020-11-06 08:27:56 +00:00
|
|
|
if (msg.content === '!ping') {
|
2020-11-06 07:31:53 +00:00
|
|
|
msg.reply(`Pong! Ping: ${client.ping}ms`)
|
2020-11-06 08:27:56 +00:00
|
|
|
} else if (msg.content === '!members') {
|
2020-11-03 07:12:22 +00:00
|
|
|
const col = await msg.guild?.members.collection()
|
2020-12-02 12:29:52 +00:00
|
|
|
const data = col
|
|
|
|
?.array()
|
|
|
|
.map((c: Member, i: number) => {
|
|
|
|
return `${i + 1}. ${c.user.tag}`
|
|
|
|
})
|
|
|
|
.join('\n') as string
|
|
|
|
msg.channel.send('Member List:\n' + data)
|
2020-11-06 08:27:56 +00:00
|
|
|
} else if (msg.content === '!guilds') {
|
2020-11-03 07:12:22 +00:00
|
|
|
const guilds = await msg.client.guilds.collection()
|
2020-12-02 12:29:52 +00:00
|
|
|
msg.channel.send(
|
|
|
|
'Guild List:\n' +
|
|
|
|
(guilds
|
|
|
|
.array()
|
|
|
|
.map((c: Guild, i: number) => {
|
|
|
|
return `${i + 1}. ${c.name} - ${c.memberCount} members`
|
|
|
|
})
|
|
|
|
.join('\n') as string)
|
|
|
|
)
|
2020-11-06 08:27:56 +00:00
|
|
|
} else if (msg.content === '!roles') {
|
2020-11-03 07:12:22 +00:00
|
|
|
const col = await msg.guild?.roles.collection()
|
2020-12-02 12:29:52 +00:00
|
|
|
const data = col
|
|
|
|
?.array()
|
|
|
|
.map((c: Role, i: number) => {
|
|
|
|
return `${i + 1}. ${c.name}`
|
|
|
|
})
|
|
|
|
.join('\n') as string
|
|
|
|
msg.channel.send('Roles List:\n' + data)
|
2020-11-06 08:27:56 +00:00
|
|
|
} else if (msg.content === '!channels') {
|
2020-11-03 07:12:22 +00:00
|
|
|
const col = await msg.guild?.channels.array()
|
2020-12-02 12:29:52 +00:00
|
|
|
const data = col
|
|
|
|
?.map((c: GuildChannel, i: number) => {
|
|
|
|
return `${i + 1}. ${c.name}`
|
|
|
|
})
|
|
|
|
.join('\n') as string
|
2020-11-06 08:27:56 +00:00
|
|
|
msg.channel.send('Channels List:\n' + data)
|
2020-10-25 17:03:53 +00:00
|
|
|
}
|
2020-10-25 06:50:32 +00:00
|
|
|
})
|
|
|
|
|
2020-12-04 05:53:10 +00:00
|
|
|
client.connect(TOKEN, Intents.All)
|
|
|
|
|
|
|
|
// OLD: Was a way to reproduce reconnect infinite loop
|
|
|
|
// setTimeout(() => {
|
|
|
|
// console.log('[DEBUG] Reconnect')
|
|
|
|
// client.gateway?.reconnect()
|
|
|
|
// }, 1000 * 4)
|