Skip to content

Commit ba18351

Browse files
committed
Add error handling for expired sessions or unknown guilds
1 parent c3e9f68 commit ba18351

File tree

20 files changed

+122
-104
lines changed

20 files changed

+122
-104
lines changed

common/src/commonMain/kotlin/net/cakeyfox/common/Constants.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ object Constants {
5353
return "💫 $activity"
5454
}
5555

56+
fun getServerInviteLink(serverId: String): String {
57+
return "https://discord.com/oauth2/authorize?client_id=1006520438865801296&scope=bot+applications.commands&permissions=269872255&guild_id=$serverId"
58+
}
59+
5660
// Website utils
5761
const val DISCORD_AVATAR = "https://cdn.discordapp.com/embed/avatars/0.png"
5862

foxy/src/main/kotlin/net/cakeyfox/foxy/listeners/MessageListener.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import net.cakeyfox.common.FoxyLocale
1414
import net.cakeyfox.foxy.interactions.pretty
1515
import net.cakeyfox.foxy.modules.ServerLogModule
1616
import net.cakeyfox.foxy.utils.PremiumUtils
17-
import net.cakeyfox.foxy.utils.discord.NitroUtils
1817
import net.cakeyfox.foxy.utils.music.AudioLoader
1918
import net.cakeyfox.foxy.utils.music.getOrCreateMusicManager
2019
import net.cakeyfox.foxy.utils.music.joinInAVoiceChannel
@@ -67,9 +66,6 @@ class MessageListener(val foxy: FoxyInstance) : ListenerAdapter() {
6766

6867
processCommandOrMention(event)
6968
processDjFoxyMessage(event)
70-
if (event.member?.isBoosting == true) {
71-
processNitroBoost(event)
72-
}
7369
}
7470
}
7571

@@ -101,20 +97,6 @@ class MessageListener(val foxy: FoxyInstance) : ListenerAdapter() {
10197
link.loadItem(processQuery(raw)).subscribe(AudioLoader(context, manager))
10298
}
10399

104-
private suspend fun processNitroBoost(event: MessageReceivedEvent) {
105-
val member = event.member ?: return
106-
val guildAsFoxyverseGuild = foxy.database.guild.getFoxyverseGuildOrNull(event.guild.id) ?: return
107-
108-
guildAsFoxyverseGuild.serverBenefits?.givePremiumIfBoosted?.let { benefit ->
109-
val redeemChannel = benefit.textChannelToRedeem
110-
if (benefit.isEnabled == true && redeemChannel != null && redeemChannel != event.message.channelId) {
111-
return
112-
}
113-
}
114-
115-
NitroUtils.onBoostActivation(foxy, member)
116-
}
117-
118100
private suspend fun processCommandOrMention(event: MessageReceivedEvent) {
119101
val guild = foxy.database.guild.getGuild(event.guild.id)
120102
val localeKey = DiscordLocale.from(guild.guildSettings.language)

foxy/src/main/kotlin/net/cakeyfox/foxy/utils/discord/NitroUtils.kt

Lines changed: 0 additions & 48 deletions
This file was deleted.

foxy/src/main/kotlin/net/cakeyfox/foxy/website/FoxyWebsite.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import io.ktor.server.application.install
88
import io.ktor.server.engine.embeddedServer
99
import io.ktor.server.netty.Netty
1010
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
11+
import io.ktor.server.plugins.statuspages.StatusPages
12+
import io.ktor.server.response.respondRedirect
1113
import io.ktor.server.sessions.SameSite
1214
import io.ktor.server.sessions.Sessions
1315
import io.ktor.server.sessions.cookie
1416
import io.ktor.server.sessions.sameSite
1517
import kotlinx.serialization.json.Json
1618
import mu.KotlinLogging
19+
import net.cakeyfox.common.Constants
1720
import net.cakeyfox.foxy.FoxyInstance
21+
import net.cakeyfox.foxy.website.utils.DiscordAPIException
1822
import net.cakeyfox.foxy.website.utils.registerAllRoutes
1923
import net.cakeyfox.serializable.data.utils.FoxyConfig
2024
import net.cakeyfox.serializable.data.website.DiscordRole

foxy/src/main/kotlin/net/cakeyfox/foxy/website/routes/api/v1/dashboard/guild/PostAutoRoleSettingsRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class PostAutoRoleSettingsRoute(val server: FoxyWebsite) : BaseRoute("/api/v1/se
2424
?: return htmxRedirect(context.call, Constants.INVITE_LINK)
2525

2626
try {
27-
checkPermissions(server, context, locale) ?: return
27+
checkPermissions(server, context, locale, context.call) ?: return
2828
fun Parameters.getBoolean(name: String) = this[name] == "on"
2929

3030
val params = context.call.receiveParameters()

foxy/src/main/kotlin/net/cakeyfox/foxy/website/routes/api/v1/dashboard/guild/PostGeneralSettingsRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PostGeneralSettingsRoute(val server: FoxyWebsite) :
2626
?: return htmxRedirect(context.call, Constants.INVITE_LINK)
2727

2828
try {
29-
checkPermissions(server, context, locale) ?: return
29+
checkPermissions(server, context, locale, context.call) ?: return
3030

3131
val params = context.call.receiveParameters()
3232
fun Parameters.getBoolean(name: String) = this[name] == "on"

foxy/src/main/kotlin/net/cakeyfox/foxy/website/routes/api/v1/dashboard/guild/PostSaveYouTubeSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PostSaveYouTubeSettings(val server: FoxyWebsite) : BaseRoute("/api/v1/serv
3333
}
3434

3535
try {
36-
checkPermissions(server, context, locale) ?: return
36+
checkPermissions(server, context, locale, context.call) ?: return
3737

3838
val params = context.call.receiveParameters()
3939

foxy/src/main/kotlin/net/cakeyfox/foxy/website/routes/api/v1/dashboard/guild/PostServerLogsSettingsRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PostServerLogsSettingsRoute(val server: FoxyWebsite) : BaseRoute("/api/v1/
2323
?: return htmxRedirect(context.call, Constants.INVITE_LINK)
2424

2525
try {
26-
checkPermissions(server, context, locale) ?: return
26+
checkPermissions(server, context, locale, context.call) ?: return
2727

2828
val params = context.call.receiveParameters()
2929
fun Parameters.getBoolean(name: String) = this[name] == "on"

foxy/src/main/kotlin/net/cakeyfox/foxy/website/routes/api/v1/dashboard/guild/PostWelcomerRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PostWelcomerRoute(val server: FoxyWebsite) :
2323
val guildId = context.call.parameters["guildId"] ?: return
2424

2525
try {
26-
checkPermissions(server, context, locale) ?: return
26+
checkPermissions(server, context, locale, context.call) ?: return
2727

2828
val params = context.call.receiveParameters()
2929
fun Parameters.getBoolean(name: String) = this[name] == "on"

foxy/src/main/kotlin/net/cakeyfox/foxy/website/routes/api/v1/dashboard/guild/PostWelcomerTestRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PostWelcomerTestRoute(val server: FoxyWebsite) :
3737
return context.call.respondRedirect(Constants.INVITE_LINK)
3838
}
3939

40-
val (user, guild, session, guildInfo) = checkPermissions(server, context, locale) ?: return
40+
val (user, guild, session, guildInfo) = checkPermissions(server, context, locale, context.call) ?: return
4141

4242
val bodyAsDiscordMessage = Json.encodeToString(
4343
DiscordMessageBody(

0 commit comments

Comments
 (0)