Skip to content

Commit 42753bc

Browse files
committed
Add Dashboard Command, update constants and TopggStatsSender
1 parent 76e84e2 commit 42753bc

File tree

12 files changed

+109
-26
lines changed

12 files changed

+109
-26
lines changed

buildSrc/src/main/kotlin/Versions.kt

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ object Versions {
1717
const val JDA_KTX = "0.12.0"
1818
const val SHADOW_JAR = "7.1.2"
1919
const val JACKSON = "2.18.0"
20+
const val MONGODB = "5.3.0"
2021
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ object Constants {
1212
const val PREMIUM = "https://foxybot.win/br/premium"
1313
const val DAILY = "https://foxybot.win/br/daily"
1414
const val DAILY_EMOJI = "https://cdn.discordapp.com/emojis/915736630495686696.png?size=2048"
15+
const val DASHBOARD_URL = "https://foxybot.win/br/dashboard"
16+
1517
@OptIn(ExperimentalSerializationApi::class)
1618
val HOCON = Hocon { useArrayPolymorphism = true }
1719
const val SUPPORT_SERVER_ID = "768267522670723094"

foxy/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ dependencies {
2929
implementation("club.minnced:jda-ktx:${Versions.JDA_KTX}")
3030

3131
// MongoDB
32-
implementation("org.mongodb:bson-kotlinx:5.3.0")
33-
implementation("org.mongodb:mongodb-driver-kotlin-coroutine:5.3.0")
32+
implementation("org.mongodb:bson-kotlinx:${Versions.MONGODB}")
33+
implementation("org.mongodb:mongodb-driver-kotlin-coroutine:${Versions.MONGODB}")
3434

3535
// Ktor
3636
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

foxy/src/main/kotlin/net/cakeyfox/foxy/FoxyInstance.kt

+4-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import net.dv8tion.jda.api.utils.ChunkingFilter
3333
import net.dv8tion.jda.api.utils.MemberCachePolicy
3434
import net.dv8tion.jda.api.utils.cache.CacheFlag
3535
import kotlin.concurrent.thread
36-
import kotlin.reflect.jvm.jvmName
3736

3837
class FoxyInstance(
3938
val config: FoxyConfig,
@@ -57,14 +56,12 @@ class FoxyInstance(
5756
private val currentClusterName = if (config.discord.clusters.size < 2) null else currentCluster.name
5857
private val coroutineExecutor = ThreadUtils.createThreadPool("CoroutineExecutor [%d]")
5958

60-
val json = Json {
61-
ignoreUnknownKeys = true
62-
}
59+
val json = Json { ignoreUnknownKeys = true }
6360
val threadPoolManager = ThreadPoolManager()
6461
val coroutineDispatcher = coroutineExecutor.asCoroutineDispatcher()
6562

6663
suspend fun start() {
67-
val logger = KotlinLogging.logger(this::class.jvmName)
64+
val logger = KotlinLogging.logger { }
6865

6966
environment = config.environment
7067
mongoClient = MongoDBClient(this)
@@ -73,13 +70,8 @@ class FoxyInstance(
7370
interactionManager = FoxyComponentManager(this)
7471
artistryClient = ArtistryClient(config, config.others.artistry.key)
7572
httpClient = HttpClient(CIO) {
76-
install(HttpTimeout) {
77-
requestTimeoutMillis = 60_000
78-
}
79-
80-
install(ContentNegotiation) {
81-
json()
82-
}
73+
install(HttpTimeout) { requestTimeoutMillis = 60_000 }
74+
install(ContentNegotiation) { json() }
8375
}
8476

8577
mongoClient.start(this)

foxy/src/main/kotlin/net/cakeyfox/foxy/command/vanilla/dev/ServerInviteRetrieveExecutor.kt

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ServerInviteRetrieveExecutor : FoxyCommandExecutor() {
2929
context.reply(true) {
3030
embed {
3131
title = "Convites do servidor ${guild.name}"
32+
thumbnail = guild.icon
3233
color = Colors.RANDOM
3334
description = invites.take(5)
3435
.joinToString("\n") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package net.cakeyfox.foxy.command.vanilla.utils
2+
3+
import dev.minn.jda.ktx.coroutines.await
4+
import net.cakeyfox.common.Colors
5+
import net.cakeyfox.common.Constants
6+
import net.cakeyfox.common.FoxyEmotes
7+
import net.cakeyfox.foxy.command.FoxyInteractionContext
8+
import net.cakeyfox.foxy.command.structure.FoxyCommandExecutor
9+
import net.cakeyfox.foxy.utils.pretty
10+
import net.dv8tion.jda.api.Permission
11+
12+
class DashboardExecutor : FoxyCommandExecutor() {
13+
override suspend fun execute(context: FoxyInteractionContext) {
14+
if (context.guild == null) {
15+
context.reply(true) {
16+
content = pretty(
17+
FoxyEmotes.FoxyCry,
18+
context.locale["dashboard.guildNotFound"]
19+
)
20+
}
21+
22+
return
23+
}
24+
25+
val userAsMember = context.guild.retrieveMember(context.user).await()
26+
27+
if (!userAsMember.hasPermission(Permission.MANAGE_SERVER)) {
28+
context.reply(true) {
29+
content = pretty(
30+
FoxyEmotes.FoxyCry,
31+
context.locale["dashboard.noPermission"]
32+
)
33+
}
34+
}
35+
36+
context.reply(true) {
37+
embed {
38+
title = pretty(FoxyEmotes.FoxyYay, context.locale["dashboard.embed.title"])
39+
color = Colors.BLURPLE
40+
description = context.locale["dashboard.embed.description", context.guild.name]
41+
}
42+
43+
actionRow(
44+
context.foxy.interactionManager.createLinkButton(
45+
FoxyEmotes.FoxyYay,
46+
context.locale["dashboard.embed.button"],
47+
Constants.DASHBOARD_URL
48+
)
49+
)
50+
}
51+
}
52+
}

foxy/src/main/kotlin/net/cakeyfox/foxy/command/vanilla/utils/PingExecutor.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import net.cakeyfox.foxy.utils.pretty
99
class PingExecutor : FoxyCommandExecutor() {
1010
override suspend fun execute(context: FoxyInteractionContext) {
1111
val gatewayPing = context.jda.gatewayPing
12-
val currentShardId = context.jda.shardInfo.shardId + 1
12+
val currentShardId = context.jda.shardInfo.shardId
1313
val totalShards = context.jda.shardInfo.shardTotal
1414
val minClusterShards = context.foxy.currentCluster.minShard
15-
val maxClusterShards = context.foxy.currentCluster.maxShard
15+
val maxClusterShards = context.foxy.currentCluster.maxShard + 1
1616
val currentClusterId = context.foxy.currentCluster.id
1717
val currentClusterName = context.foxy.currentCluster.name
1818

1919
context.reply {
2020
embed {
21-
title = pretty(FoxyEmotes.FoxyWow, "Pong!")
21+
title = pretty(FoxyEmotes.FoxyWow, "Pong! (Shard: #$currentShardId)")
2222
thumbnail = context.foxy.selfUser.effectiveAvatarUrl
2323
color = Colors.FOXY_DEFAULT
2424

@@ -37,7 +37,7 @@ class PingExecutor : FoxyCommandExecutor() {
3737
field {
3838
name = pretty(FoxyEmotes.FoxyDrinkingCoffee, "Cluster:")
3939
value =
40-
"Cluster $currentClusterId - `${currentClusterName}` **[$minClusterShards-$maxClusterShards]**"
40+
"**Cluster $currentClusterId** - `${currentClusterName}` **($minClusterShards/$maxClusterShards)**"
4141
inline = false
4242
}
4343
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package net.cakeyfox.foxy.command.vanilla.utils.declarations
2+
3+
import net.cakeyfox.foxy.command.structure.FoxyCommandDeclarationWrapper
4+
import net.cakeyfox.foxy.command.vanilla.utils.DashboardExecutor
5+
import net.dv8tion.jda.api.interactions.IntegrationType
6+
import net.dv8tion.jda.api.interactions.InteractionContextType
7+
8+
class DashboardCommand : FoxyCommandDeclarationWrapper {
9+
override fun create() = command(
10+
name = "dashboard",
11+
description = "description",
12+
interactionContexts = listOf(
13+
InteractionContextType.GUILD
14+
),
15+
integrationType = listOf(
16+
IntegrationType.GUILD_INSTALL
17+
),
18+
) {
19+
executor = DashboardExecutor()
20+
}
21+
}

foxy/src/main/kotlin/net/cakeyfox/foxy/utils/analytics/TopggStatsSender.kt

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import io.ktor.client.*
44
import io.ktor.client.request.*
55
import io.ktor.client.statement.*
66
import io.ktor.http.*
7-
import io.ktor.http.content.*
87
import kotlinx.coroutines.*
9-
import kotlinx.serialization.encodeToString
108
import kotlinx.serialization.json.Json
9+
import kotlinx.serialization.json.buildJsonObject
10+
import kotlinx.serialization.json.put
1111
import mu.KotlinLogging
1212
import net.cakeyfox.foxy.FoxyInstance
1313
import net.cakeyfox.serializable.data.cluster.ClusterStats
@@ -88,12 +88,10 @@ class TopggStatsSender(
8888
val response = foxy.httpClient.post("https://top.gg/api/bots/$clientId/stats") {
8989
header("Authorization", token)
9090
accept(ContentType.Application.Json)
91-
setBody(
92-
TextContent(
93-
Json.encodeToString(ClusterStats.TopggBotStats(serverCount)),
94-
ContentType.Application.Json
95-
)
96-
)
91+
setBody(buildJsonObject {
92+
put("server_count", serverCount)
93+
put("shard_count", foxy.config.discord.totalShards)
94+
})
9795
}
9896

9997
if (response.status != HttpStatusCode.OK) {

foxy/src/main/resources/locales/en-us/general.yml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ commands:
55
componentExpired: "Wait, where is it? I can't find the interaction information... It seems to have expired! Run the command again."
66

77
command:
8+
dashboard:
9+
name: "dashboard"
10+
description: "[Utils] Access the current server dashboard"
11+
812
ship:
913
name: "ship"
1014
description: "[Social] Ship two users"

foxy/src/main/resources/locales/pt-br/commands.yml

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
commands:
66
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.win/br/premium)"
77

8+
dashboard:
9+
embed:
10+
title: "Painel de Controle"
11+
description: "Quer deixar o servidor `{0}` incrível e mas não sabe por onde começar? Acesse o painel de controle para configurar o seu servidor!"
12+
button: "Acessar o Painel de Controle"
13+
noPermission: "Você precisa da permissão `Gerenciar Servidor` para utilizar esse comando"
14+
guildNotFound: "Eu preciso estar nesse servidor para isso funcionar!"
15+
816
russianRoulette:
917
embed:
1018
title: "Roleta Russa"

foxy/src/main/resources/locales/pt-br/general.yml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ commands:
66
error: "Ocorreu um erro ao executar o comando, o problema foi reportado! `{0}`"
77

88
command:
9+
dashboard:
10+
name: "dashboard"
11+
description: "[Utilitários] Acesse o painel de configuração do servidor atual"
12+
913
ship:
1014
name: "ship"
1115
description: "[Social] Ship two users"

0 commit comments

Comments
 (0)