Skip to content

Commit 784624b

Browse files
committed
Add /notifications command to disable Foxy periodically notifications
1 parent dd1d780 commit 784624b

File tree

10 files changed

+260
-81
lines changed

10 files changed

+260
-81
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package net.cakeyfox.foxy.interactions.vanilla.utils
2+
3+
import net.cakeyfox.common.FoxyEmotes
4+
import net.cakeyfox.foxy.database.data.user.Notifications
5+
import net.cakeyfox.foxy.database.utils.builders.NotificationsBuilder
6+
import net.cakeyfox.foxy.interactions.commands.CommandContext
7+
import net.cakeyfox.foxy.interactions.commands.UnleashedCommandExecutor
8+
import net.cakeyfox.foxy.interactions.pretty
9+
10+
class NotificationExecutor(val action: String) : UnleashedCommandExecutor() {
11+
private data class NotificationConfig(
12+
val getter: (Notifications?) -> Boolean,
13+
val updater: (NotificationsBuilder, Boolean) -> Unit,
14+
val enableMessage: String,
15+
val disableMessage: String
16+
)
17+
18+
override suspend fun execute(context: CommandContext) {
19+
val configs = mapOf(
20+
"tempban" to NotificationConfig(
21+
getter = { it?.disableTempBanNotifications ?: false },
22+
updater = { b, v -> b.disableTempBanNotifications = v },
23+
enableMessage = context.locale["notifications.tempban.enabled"],
24+
disableMessage = context.locale["notifications.tempban.disabled"]
25+
),
26+
27+
"birthday" to NotificationConfig(
28+
getter = { it?.disableBirthdayNotifications ?: false },
29+
updater = { b, v -> b.disableBirthdayNotifications = v },
30+
enableMessage = context.locale["notifications.birthday.enabled"],
31+
disableMessage = context.locale["notifications.birthday.disabled"]
32+
),
33+
34+
"daily_reminder" to NotificationConfig(
35+
getter = { it?.disableDailyReminderNotifications ?: false },
36+
updater = { b, v -> b.disableDailyReminderNotifications = v },
37+
enableMessage = context.locale["notifications.daily_reminder.enabled"],
38+
disableMessage = context.locale["notifications.daily_reminder.disabled"]
39+
),
40+
41+
"daily_tax" to NotificationConfig(
42+
getter = { it?.disableInactivityTaxNotifications ?: false },
43+
updater = { b, v -> b.disableInactivityTaxNotifications = v },
44+
enableMessage = context.locale["notifications.daily_tax.enabled"],
45+
disableMessage = context.locale["notifications.daily_tax.disabled"]
46+
),
47+
48+
"upvote" to NotificationConfig(
49+
getter = { it?.disableUpvoteNotifications ?: false },
50+
updater = { b, v -> b.disableUpvoteNotifications = v },
51+
enableMessage = context.locale["notifications.upvote.enabled"],
52+
disableMessage = context.locale["notifications.upvote.disabled"]
53+
)
54+
)
55+
56+
val userData = context.getAuthorData()
57+
val current = userData.notifications
58+
val config = configs[action] ?: return
59+
val disabled = config.getter(current)
60+
val newValue = !disabled
61+
val message = if (disabled) {
62+
config.enableMessage
63+
} else {
64+
config.disableMessage
65+
}
66+
67+
context.reply(true) {
68+
content = pretty(FoxyEmotes.FoxyWow, message)
69+
}
70+
71+
context.foxy.database.user.updateUser(context.user.id) {
72+
config.updater(this.notifications, newValue)
73+
}
74+
}
75+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.cakeyfox.foxy.interactions.vanilla.utils.declarations
2+
3+
import net.cakeyfox.foxy.interactions.commands.CommandCategory
4+
import net.cakeyfox.foxy.interactions.commands.FoxyCommandDeclarationWrapper
5+
import net.cakeyfox.foxy.interactions.vanilla.utils.NotificationExecutor
6+
7+
class NotificationCommand : FoxyCommandDeclarationWrapper {
8+
override fun create() = slashCommand("notifications", CommandCategory.UTILS) {
9+
subCommand("tempban") {
10+
executor = NotificationExecutor(this.name)
11+
}
12+
13+
subCommand("birthday") {
14+
executor = NotificationExecutor(this.name)
15+
}
16+
17+
subCommand("daily_reminder") {
18+
executor = NotificationExecutor(this.name)
19+
}
20+
21+
subCommand("daily_tax") {
22+
executor = NotificationExecutor(this.name)
23+
}
24+
25+
subCommand("upvote") {
26+
executor = NotificationExecutor(this.name)
27+
}
28+
}
29+
}

foxy/src/main/kotlin/net/cakeyfox/foxy/tasks/BirthdayReminderTask.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import net.cakeyfox.foxy.interactions.pretty
1717
import net.cakeyfox.foxy.utils.RunnableCoroutine
1818
import net.cakeyfox.common.FoxyLocale
1919
import net.cakeyfox.foxy.utils.logging.task
20+
import net.dv8tion.jda.api.components.buttons.ButtonStyle
2021
import java.time.ZoneId
2122
import java.time.ZonedDateTime
2223

@@ -66,15 +67,17 @@ class BirthdayReminderTask(
6667

6768
val discordUser = foxy.shardManager.retrieveUserById(user._id).await()
6869
if (isBirthdayToday && !hasReceivedThisYear) {
69-
foxy.utils.sendDirectMessage(discordUser) {
70-
embed {
71-
title = pretty(
72-
FoxyEmotes.FoxyCake,
73-
locale["birthday.title"]
74-
)
75-
color = Colors.PURPLE
76-
description = locale["birthday.message", FoxyEmotes.FoxyYay]
77-
thumbnail = Constants.FOXY_WOW
70+
if (user.notifications?.disableBirthdayNotifications != true) {
71+
foxy.utils.sendDirectMessage(discordUser) {
72+
embed {
73+
title = pretty(
74+
FoxyEmotes.FoxyCake,
75+
locale["birthday.title"]
76+
)
77+
color = Colors.PURPLE
78+
description = locale["birthday.message", FoxyEmotes.FoxyYay]
79+
thumbnail = Constants.FOXY_WOW
80+
}
7881
}
7982
}
8083

foxy/src/main/kotlin/net/cakeyfox/foxy/tasks/CakeInactivityTaxTask.kt

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -83,34 +83,37 @@ class CakeInactivityTaxTask(
8383
if (daysSinceLastDaily in WARNING_DAYS until TAX_START_DAYS) {
8484
if (user.userCakes.warnedAboutInactivityTax != true) {
8585
val userFromDiscord = foxy.shardManager.retrieveUserById(user._id).await()
86-
foxy.utils.sendDirectMessage(userFromDiscord) {
87-
embed {
88-
title = pretty(
89-
FoxyEmotes.FoxyCry,
90-
locale[
91-
"tax.cakes.warning.title"
86+
if (user.notifications?.disableInactivityTaxNotifications != true) {
87+
foxy.utils.sendDirectMessage(userFromDiscord) {
88+
embed {
89+
title = pretty(
90+
FoxyEmotes.FoxyCry,
91+
locale[
92+
"tax.cakes.warning.title"
93+
]
94+
)
95+
description = locale[
96+
"tax.cakes.warning.description",
97+
user._id,
98+
formattedMinimumAmount,
99+
WARNING_DAYS.toString(),
100+
formattedBalance,
101+
formattedTax
92102
]
103+
thumbnail = Constants.FOXY_CRY
104+
color = Colors.FOXY_DEFAULT
105+
}
106+
107+
actionRow(
108+
linkButton(
109+
FoxyEmotes.FoxyDaily,
110+
locale["tax.cakes.button"],
111+
Constants.DAILY
112+
)
93113
)
94-
description = locale[
95-
"tax.cakes.warning.description",
96-
user._id,
97-
formattedMinimumAmount,
98-
WARNING_DAYS.toString(),
99-
formattedBalance,
100-
formattedTax
101-
]
102-
thumbnail = Constants.FOXY_CRY
103-
color = Colors.FOXY_DEFAULT
104114
}
105-
106-
actionRow(
107-
linkButton(
108-
FoxyEmotes.FoxyDaily,
109-
locale["tax.cakes.button"],
110-
Constants.DAILY
111-
)
112-
)
113115
}
116+
114117
foxy.database.user.updateUser(user._id) {
115118
userCakes.warnedAboutInactivityTax = true
116119
}
@@ -124,25 +127,27 @@ class CakeInactivityTaxTask(
124127
val userFromDiscord = foxy.shardManager.retrieveUserById(user._id).await()
125128
val formattedTax = foxy.utils.formatLongNumber(tax)
126129

127-
foxy.utils.sendDirectMessage(userFromDiscord) {
128-
embed {
129-
title = pretty(FoxyEmotes.FoxyCry, locale["tax.cakes.title"])
130-
description = locale[
131-
"tax.cakes.description",
132-
user._id,
133-
formattedTax
134-
]
135-
thumbnail = Constants.FOXY_CRY
136-
color = Colors.FOXY_DEFAULT
137-
}
130+
if (user.notifications?.disableInactivityTaxNotifications != true) {
131+
foxy.utils.sendDirectMessage(userFromDiscord) {
132+
embed {
133+
title = pretty(FoxyEmotes.FoxyCry, locale["tax.cakes.title"])
134+
description = locale[
135+
"tax.cakes.description",
136+
user._id,
137+
formattedTax
138+
]
139+
thumbnail = Constants.FOXY_CRY
140+
color = Colors.FOXY_DEFAULT
141+
}
138142

139-
actionRow(
140-
linkButton(
141-
FoxyEmotes.FoxyDaily,
142-
locale["tax.cakes.button"],
143-
Constants.DAILY
143+
actionRow(
144+
linkButton(
145+
FoxyEmotes.FoxyDaily,
146+
locale["tax.cakes.button"],
147+
Constants.DAILY
148+
)
144149
)
145-
)
150+
}
146151
}
147152

148153
foxy.database.user.removeCakesFromUser(user._id, tax)

foxy/src/main/kotlin/net/cakeyfox/foxy/tasks/DailyReminderTask.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,26 @@ class DailyReminderTask(
4545
if (user.userCakes.notifiedForDaily == true) return@withPermit
4646
val discordUser = foxy.shardManager.retrieveUserById(user._id).await()
4747

48-
foxy.utils.sendDirectMessage(discordUser) {
49-
embed {
50-
title = pretty(
51-
FoxyEmotes.FoxyHowdy,
52-
locale["dailyReminder.embed.title"]
53-
)
54-
description = locale["dailyReminder.embed.description", user._id]
55-
color = Colors.FOXY_DEFAULT
56-
thumbnail = Constants.DAILY_EMOJI
57-
}
48+
if (user.notifications?.disableDailyReminderNotifications != true) {
49+
foxy.utils.sendDirectMessage(discordUser) {
50+
embed {
51+
title = pretty(
52+
FoxyEmotes.FoxyHowdy,
53+
locale["dailyReminder.embed.title"]
54+
)
55+
description = locale["dailyReminder.embed.description", user._id]
56+
color = Colors.FOXY_DEFAULT
57+
thumbnail = Constants.DAILY_EMOJI
58+
}
5859

59-
actionRow(
60-
linkButton(
61-
FoxyEmotes.FoxyDaily,
62-
locale["dailyReminder.button"],
63-
Constants.DAILY
60+
actionRow(
61+
linkButton(
62+
FoxyEmotes.FoxyDaily,
63+
locale["dailyReminder.button"],
64+
Constants.DAILY
65+
)
6466
)
65-
)
67+
}
6668
}
6769

6870
foxy.database.user.updateUser(user._id) {

foxy/src/main/kotlin/net/cakeyfox/foxy/tasks/UpvoteReminderTask.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,24 @@ class UpvoteReminderTask(
4141
if (user.notifiedForVote == true) return@withPermit
4242
val discordUser = foxy.shardManager.retrieveUserById(user._id).await()
4343

44-
foxy.utils.sendDirectMessage(discordUser) {
45-
embed {
46-
title = pretty(FoxyEmotes.FoxyYay, locale["upvote.reminder.title"])
47-
description = locale["upvote.reminder.message", user._id]
48-
footer(locale["upvote.reminder.footer"])
49-
color = Colors.FOXY_DEFAULT
50-
thumbnail = Constants.FOXY_FUMO
51-
}
44+
if (user.notifications?.disableUpvoteNotifications != true) {
45+
foxy.utils.sendDirectMessage(discordUser) {
46+
embed {
47+
title = pretty(FoxyEmotes.FoxyYay, locale["upvote.reminder.title"])
48+
description = locale["upvote.reminder.message", user._id]
49+
footer(locale["upvote.reminder.footer"])
50+
color = Colors.FOXY_DEFAULT
51+
thumbnail = Constants.FOXY_FUMO
52+
}
5253

53-
actionRow(
54-
linkButton(
55-
FoxyEmotes.FoxyYay,
56-
locale["upvote.reminderButton"],
57-
Constants.UPVOTE_URL
54+
actionRow(
55+
linkButton(
56+
FoxyEmotes.FoxyYay,
57+
locale["upvote.reminderButton"],
58+
Constants.UPVOTE_URL
59+
)
5860
)
59-
)
61+
}
6062
}
6163

6264
foxy.database.user.updateUser(user._id) {

foxy/src/main/kotlin/net/cakeyfox/foxy/utils/AdminUtils.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ object AdminUtils {
4242
try {
4343
val user = foxy.shardManager.retrieveUserById(expiredBan.userId).await()
4444
val bannedBy = foxy.shardManager.retrieveUserById(expiredBan.bannedBy).await()
45-
45+
val userData = foxy.database.user.getFoxyProfile(expiredBan.userId)
4646
foxy.database.guild.removeTempBanFromGuild(guildId, user.id)
4747
guild.unban(user)
4848
.reason("Banimento expirado")
4949
.await()
5050

5151
try {
52+
if (userData.notifications?.disableTempBanNotifications != true) {
53+
sendUnbanDm(foxy, guild, user, bannedBy, expiredBan)
54+
}
55+
5256
val placeholders = getModerationPlaceholders(
5357
foxy,
5458
bannedBy,

resources/locales/br/commands.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ howToUseParams: Parâmetros com * são obrigatórios
99
commands:
1010
earlyAccess: "Esse comando está em beta e apenas usuários premium possuem acesso antecipado. Se você quiser ter acesso a esse comando e muitos outros, você pode se tornar um usuário premium clicando [aqui](https://foxybot.xyz/br/premium)"
1111

12+
notifications:
13+
tempban:
14+
enabled: Agora eu vou te enviar notificações quando seus banimentos expirarem
15+
disabled: Agora eu não vou mais te enviar notificações quando seus banimentos expirarem
16+
birthday:
17+
enabled: Agora eu vou te enviar notificações de aniversário
18+
disabled: Agora eu não vou mais te enviar notificações de aniversário
19+
daily_reminder:
20+
enabled: Agora eu vou te lembrar de pegar seu prêmio diário
21+
disabled: Agora eu não vou mais te lembrar de pegar seu prêmio diário
22+
daily_tax:
23+
enabled: Agora eu vou te enviar notificações sobre a taxa de inatividade
24+
disabled: Agora eu não vou mais te enviar notificações sobre a taxa de inatividade (incluindo quando eu comer seus cakes rs)
25+
upvote:
26+
enabled: Agora eu vou te enviar lembretes para votar em mim!
27+
disabled: Agora eu não vou mais enviar lembretes para votar em mim
28+
1229
clear:
1330
howToUse:
1431
title: Limpando Mensagens do Servidor

0 commit comments

Comments
 (0)