Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.

Commit 72aa699

Browse files
authored
refactor: change setDynamicVoice and setPresence to async functions (#99)
1 parent cddf5fd commit 72aa699

2 files changed

Lines changed: 56 additions & 56 deletions

File tree

src/events/ticker/dynamic_voice.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {
33
DYNAMIC_VOICE_DELETE_CHANNELS_IN_MINUTES,
44
DYNAMIC_VOICE_INVITE_LIMIT_TIME,
55
DYNAMIC_VOICE_IGNORABLE_CHANNELS,
6-
TICKER_SETTER
6+
TICKER_SETTER,
77
} from '@/defines/values.json'
88
import { getDynamicVoiceCategory, getGuild } from '@/utils'
99
import { Collection, GuildMember, VoiceChannel } from 'discord.js'
1010

11-
export const setDynamicVoice = (client: He4rtClient) => {
11+
export const setDynamicVoice = async (client: He4rtClient) => {
1212
const guild = getGuild(client)
1313

1414
const voiceTimer = 60 * DYNAMIC_VOICE_DELETE_CHANNELS_IN_MINUTES
@@ -26,14 +26,14 @@ export const setDynamicVoice = (client: He4rtClient) => {
2626
channels.forEach(async ([_, channel]) => {
2727
if (channel.parentId !== category.id) return
2828

29-
if (!DYNAMIC_VOICE_IGNORABLE_CHANNELS.some(i => i === channel.name)) {
29+
if (!DYNAMIC_VOICE_IGNORABLE_CHANNELS.some((i) => i === channel.name)) {
3030
const targets = [...(channel.members as Collection<string, GuildMember>)]
31-
31+
3232
const actuallyTime = new Date().valueOf()
3333
const expirationLimitTime = new Date(channel.createdAt).valueOf() + DYNAMIC_VOICE_INVITE_LIMIT_TIME
34-
34+
3535
const debounceTime = actuallyTime > expirationLimitTime
36-
36+
3737
if (targets.length === 0 && debounceTime) {
3838
channel
3939
.delete()

src/events/ticker/presence.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import { He4rtClient, TickerName } from '@/types'
2-
import { ActivityType } from 'discord.js'
3-
import { DISCORD_PRESENCE_IN_MINUTES, TICKER_SETTER } from '@/defines/values.json'
4-
5-
export const setPresence = (client: He4rtClient) => {
6-
const type = ActivityType.Watching as Exclude<ActivityType, ActivityType.Custom>
7-
8-
const activities = [
9-
{
10-
type,
11-
url: 'https://heartdevs.com',
12-
name: 'da comunidade para a comunidade.',
13-
},
14-
{
15-
type,
16-
url: 'https://beacons.ai/heartdevs',
17-
name: 'beacons.ai/heartdevs',
18-
},
19-
{
20-
type,
21-
url: 'https://heartdevs.com',
22-
name: 'heartdevs.com',
23-
},
24-
{
25-
type,
26-
url: 'https://github.com/he4rt',
27-
name: 'github.com/he4rt',
28-
},
29-
{
30-
type,
31-
url: 'https://heartdevs.com',
32-
name: '/apresentar',
33-
},
34-
]
35-
const randomTimer = 60 * DISCORD_PRESENCE_IN_MINUTES
36-
let randomCounterInSeconds = TICKER_SETTER
37-
38-
client.ticker.add(TickerName.DiscordPresence, () => {
39-
--randomCounterInSeconds
40-
41-
if (randomCounterInSeconds <= 0) {
42-
randomCounterInSeconds = randomTimer
43-
44-
client.user.setPresence({
45-
status: 'online',
46-
activities: [activities[Math.floor(Math.random() * activities.length)]],
47-
})
48-
}
49-
})
50-
}
1+
import { He4rtClient, TickerName } from '@/types'
2+
import { ActivityType } from 'discord.js'
3+
import { DISCORD_PRESENCE_IN_MINUTES, TICKER_SETTER } from '@/defines/values.json'
4+
5+
export const setPresence = async (client: He4rtClient) => {
6+
const type = ActivityType.Watching as Exclude<ActivityType, ActivityType.Custom>
7+
8+
const activities = [
9+
{
10+
type,
11+
url: 'https://heartdevs.com',
12+
name: 'da comunidade para a comunidade.',
13+
},
14+
{
15+
type,
16+
url: 'https://beacons.ai/heartdevs',
17+
name: 'beacons.ai/heartdevs',
18+
},
19+
{
20+
type,
21+
url: 'https://heartdevs.com',
22+
name: 'heartdevs.com',
23+
},
24+
{
25+
type,
26+
url: 'https://github.com/he4rt',
27+
name: 'github.com/he4rt',
28+
},
29+
{
30+
type,
31+
url: 'https://heartdevs.com',
32+
name: '/apresentar',
33+
},
34+
]
35+
const randomTimer = 60 * DISCORD_PRESENCE_IN_MINUTES
36+
let randomCounterInSeconds = TICKER_SETTER
37+
38+
client.ticker.add(TickerName.DiscordPresence, () => {
39+
--randomCounterInSeconds
40+
41+
if (randomCounterInSeconds <= 0) {
42+
randomCounterInSeconds = randomTimer
43+
44+
client.user.setPresence({
45+
status: 'online',
46+
activities: [activities[Math.floor(Math.random() * activities.length)]],
47+
})
48+
}
49+
})
50+
}

0 commit comments

Comments
 (0)