Skip to content

Commit

Permalink
feat: add AdditionalServerJoinLeaveInformation for additional data
Browse files Browse the repository at this point in the history
fix: SendServerNotificationCondition checked for enable-jda without default
chore: bump to 0.0.41_5.0.0-beta.2
  • Loading branch information
itsmefox committed Dec 21, 2022
1 parent 506c23f commit 8e52075
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Gradle:
```gradle
dependencies {
implementation 'io.viascom.discord.bot:aluna-spring-boot-starter:0.0.40_5.0.0-beta.2'
implementation 'io.viascom.discord.bot:aluna-spring-boot-starter:0.0.41_5.0.0-beta.2'
}
```

Expand All @@ -40,7 +40,7 @@ Maven:
<dependency>
<groupId>io.viascom.discord.bot</groupId>
<artifactId>aluna-spring-boot-starter</artifactId>
<version>0.0.40_5.0.0-beta.2</version>
<version>0.0.41_5.0.0-beta.2</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targetCompatibility = JavaVersion.VERSION_17
ext {
major = 0
minor = 0
patch = 40
patch = 41

isCiServer = System.getenv("GITHUB_ACTIONS") != null || System.getProperty("GITHUB_ACTIONS") != null

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.viascom.discord.bot.aluna.bot.listener

import net.dv8tion.jda.api.entities.Guild
import net.dv8tion.jda.api.entities.MessageEmbed.Field

interface AdditionalServerJoinLeaveInformation {

fun getAdditionalServerJoinInformation(server: Guild): List<Field>
fun getAdditionalServerLeaveInformation(server: Guild): List<Field>

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package io.viascom.discord.bot.aluna.bot.listener

import io.viascom.discord.bot.aluna.configuration.condition.ConditionalOnJdaEnabled
import io.viascom.discord.bot.aluna.configuration.condition.SendServerNotificationCondition
import io.viascom.discord.bot.aluna.property.AlunaProperties
import io.viascom.discord.bot.aluna.util.getGuildTextChannel
Expand All @@ -38,10 +39,12 @@ import org.springframework.stereotype.Component
import java.awt.Color

@Component
@ConditionalOnJdaEnabled
@Conditional(SendServerNotificationCondition::class)
open class ServerNotificationEvent(
private val shardManager: ShardManager,
private val alunaProperties: AlunaProperties
private val alunaProperties: AlunaProperties,
private val additionalInformation: List<AdditionalServerJoinLeaveInformation>
) : ListenerAdapter() {

private val logger: Logger = LoggerFactory.getLogger(javaClass)
Expand Down Expand Up @@ -70,6 +73,14 @@ open class ServerNotificationEvent(
}
}

try {
additionalInformation.flatMap { it.getAdditionalServerJoinInformation(server) }.forEach {
embedMessage.addField(it)
}
} catch (e: Exception) {
logger.warn("Aluna was not able to get additional server information.\n" + e.printStackTrace())
}

val channel = shardManager.getGuildTextChannel(
alunaProperties.notification.serverJoin.server.toString(),
alunaProperties.notification.serverJoin.channel.toString()
Expand Down Expand Up @@ -107,6 +118,14 @@ open class ServerNotificationEvent(
}
}

try {
additionalInformation.flatMap { it.getAdditionalServerLeaveInformation(server) }.forEach {
embedMessage.addField(it)
}
} catch (e: Exception) {
logger.warn("Aluna was not able to get additional server information.\n" + e.printStackTrace())
}

val channel = shardManager.getGuildTextChannel(
alunaProperties.notification.serverLeave.server.toString(),
alunaProperties.notification.serverLeave.channel.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata

class SendServerNotificationCondition : Condition {
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata) =
context.environment.getProperty("aluna.discord.enable-jda", Boolean::class.java) == true && (
context.environment.getProperty("aluna.notification.server-join.enabled", Boolean::class.java) == true ||
context.environment.getProperty("aluna.notification.server-leave.enabled", Boolean::class.java) == true ||
context.environment.getProperty("aluna.notification.bot-ready.enabled", Boolean::class.java) == true)
context.environment.getProperty("aluna.notification.server-join.enabled", Boolean::class.java) == true ||
context.environment.getProperty("aluna.notification.server-leave.enabled", Boolean::class.java) == true
}

0 comments on commit 8e52075

Please sign in to comment.