Compare commits

..

4 Commits

Author SHA1 Message Date
Sheldan
159326dde3 [maven-release-plugin] prepare release sissi-1.4.22 2023-11-21 00:25:32 +01:00
Sheldan
7124d4e1d8 [SIS-xxx] prepare for release 2023-11-21 00:24:47 +01:00
Sheldan
c6f20d617d [SIS-xxx] adding rendering of current Debra donation information
updating for Debra 2023 campaign
adding internal rest api for debra information
adding a debra button to receive information
2023-11-21 00:23:03 +01:00
Sheldan
7449c05462 [maven-release-plugin] prepare for next development iteration 2023-11-14 23:41:52 +01:00
110 changed files with 1122 additions and 81 deletions

View File

@@ -28,6 +28,7 @@ docker_build_with_restart(
)
docker_build(registry + 'sissi-db-data', 'deployment/image-packaging/src/main/docker/db-data/')
docker_build(registry + 'sissi-rest-api', 'deployment/image-packaging/src/main/docker/rest-api/')
docker_build(registry + 'sissi-template-data', 'deployment/image-packaging/src/main/docker/template-data/')

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.application</groupId>
<artifactId>application</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>executable</artifactId>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi</groupId>
<artifactId>sissi</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.application.module.custom</groupId>
<artifactId>sissi-customizations</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>application</artifactId>
<groupId>dev.sheldan.sissi.application</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.application</groupId>
<artifactId>sissi-modules</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -15,6 +15,19 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -0,0 +1,72 @@
package dev.sheldan.sissi.module.debra.api;
import dev.sheldan.sissi.module.debra.model.api.*;
import dev.sheldan.sissi.module.debra.model.commands.DonationItemModel;
import dev.sheldan.sissi.module.debra.model.commands.DonationsModel;
import dev.sheldan.sissi.module.debra.service.DonationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import static dev.sheldan.sissi.module.debra.config.DebraFeatureConfig.DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME;
@RestController
@RequestMapping(value = "/debra")
public class DebraDonationStatusController {
@Autowired
private DonationService donationService;
@GetMapping(value = "/latestDonations", produces = "application/json")
public DonationStats getLatestDonations() {
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
DonationsResponse donationResponse = donationService.getCachedDonationAmount(serverId);
List<DonationInfo> donations = donationService.getLatestDonations(donationResponse, Integer.MAX_VALUE)
.stream()
.map(DonationInfo::fromDonationItemModel)
.toList();
return DonationStats
.builder()
.totalAmount(donationResponse.getPage().getCollected())
.donations(donations)
.build();
}
@GetMapping(value = "/highestDonations", produces = "application/json")
public DonationStats getHighestDonations() {
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
DonationsResponse donationResponse = donationService.getCachedDonationAmount(serverId);
List<DonationInfo> donations = donationService.getHighestDonations(donationResponse, Integer.MAX_VALUE)
.stream()
.map(DonationInfo::fromDonationItemModel)
.toList();
return DonationStats
.builder()
.totalAmount(donationResponse.getPage().getCollected())
.donations(donations)
.build();
}
@GetMapping(value = "/campaignInfo", produces = "application/json")
public CampaignInfo getCampaignInfo() {
Long serverId = Long.parseLong(System.getenv(DEBRA_DONATION_NOTIFICATION_SERVER_ID_ENV_NAME));
DonationsResponse donationResponse = donationService.getCachedDonationAmount(serverId);
Description pageObject = donationResponse.getPage();
return CampaignInfo
.builder()
.collected(pageObject.getCollected())
.collectedNet(pageObject.getCollectedNet())
.donationCount(donationResponse.getDonationCount())
.currency(pageObject.getCurrency())
.percent(pageObject.getPercent())
.displayName(pageObject.getDisplayName())
.slug(pageObject.getSlug())
.target(pageObject.getTarget())
.build();
}
}

View File

@@ -0,0 +1,91 @@
package dev.sheldan.sissi.module.debra.commands;
import dev.sheldan.abstracto.core.command.UtilityModuleDefinition;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
import dev.sheldan.sissi.module.debra.config.DebraFeatureDefinition;
import dev.sheldan.sissi.module.debra.config.DebraSlashCommandNames;
import dev.sheldan.sissi.module.debra.service.DonationService;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
public class DebraInfoButton extends AbstractConditionableCommand {
private static final String DEBRA_INFO_BUTTON = "debraInfoButton";
private static final String DEBRA_INFO_BUTTON_RESPONSE_TEMPLATE_KEY = "debraInfoButton_response";
private static final String TARGET_CHANNEL_PARAMETER_KEY = "targetChannel";
@Autowired
private SlashCommandParameterService slashCommandParameterService;
@Autowired
private InteractionService interactionService;
@Autowired
private DonationService donationService;
@Override
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
GuildMessageChannel targetChannel = slashCommandParameterService.getCommandOption(TARGET_CHANNEL_PARAMETER_KEY, event, GuildMessageChannel.class);
return donationService.sendDebraInfoButtonMessage(targetChannel)
.thenCompose(unused -> interactionService.replyEmbed(DEBRA_INFO_BUTTON_RESPONSE_TEMPLATE_KEY, event))
.thenApply(interactionHook -> CommandResult.fromSuccess());
}
@Override
public CommandConfiguration getConfiguration() {
HelpInfo helpInfo = HelpInfo
.builder()
.templated(true)
.build();
SlashCommandConfig slashCommandConfig = SlashCommandConfig
.builder()
.enabled(true)
.rootCommandName(DebraSlashCommandNames.DEBRA_INTERNAL)
.commandName("debrainfobutton")
.build();
Parameter targetChannelParameter = Parameter
.builder()
.templated(true)
.name(TARGET_CHANNEL_PARAMETER_KEY)
.type(GuildMessageChannel.class)
.build();
List<Parameter> parameters = Arrays.asList(targetChannelParameter);
return CommandConfiguration.builder()
.name(DEBRA_INFO_BUTTON)
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.slashCommandConfig(slashCommandConfig)
.async(true)
.slashCommandOnly(true)
.parameters(parameters)
.supportsEmbedException(true)
.causesReaction(false)
.help(helpInfo)
.build();
}
@Override
public FeatureDefinition getFeature() {
return DebraFeatureDefinition.DEBRA;
}
}

View File

@@ -113,20 +113,16 @@ public class Donations extends AbstractConditionableCommand {
private MessageToSend getDonationMessageToSend(Long serverId, Integer top, Integer latest) {
DonationsModel donationModel;
try {
DonationsResponse donationResponse = donationService.fetchCurrentDonationAmount(serverId);
donationModel = donationConverter.convertDonationResponse(donationResponse);
if(top != null) {
donationModel.setDonations(donationService.getHighestDonations(donationResponse, top));
donationModel.setType(DonationsModel.DonationType.TOP);
} else if(latest != null) {
donationModel.setType(DonationsModel.DonationType.LATEST);
donationModel.setDonations(donationService.getLatestDonations(donationResponse, latest));
} else {
donationModel.setDonations(new ArrayList<>());
}
} catch (IOException e) {
throw new AbstractoRunTimeException("Failed to load donation amount.", e);
DonationsResponse donationResponse = donationService.fetchCurrentDonationAmount(serverId);
donationModel = donationConverter.convertDonationResponse(donationResponse);
if(top != null) {
donationModel.setDonations(donationService.getHighestDonations(donationResponse, top));
donationModel.setType(DonationsModel.DonationType.TOP);
} else if(latest != null) {
donationModel.setType(DonationsModel.DonationType.LATEST);
donationModel.setDonations(donationService.getLatestDonations(donationResponse, latest));
} else {
donationModel.setDonations(new ArrayList<>());
}
return templateService.renderEmbedTemplate(DONATIONS_RESPONSE_TEMPLATE_KEY, donationModel);
}

View File

@@ -0,0 +1,33 @@
package dev.sheldan.sissi.module.debra.config;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.jsr107.EhcacheCachingProvider;
import org.ehcache.xml.XmlConfiguration;
import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.cache.CacheManager;
import javax.cache.Caching;
import java.net.URL;
@Configuration
public class CacheConfig {
@Bean("donationCacheManager")
public JCacheCacheManager jCacheCacheManager() {
return new JCacheCacheManager(getDonationCacheManager());
}
@Bean
public CacheManager getDonationCacheManager() {
URL myUrl = getClass().getResource("/donation-cache-config.xml");
XmlConfiguration xmlConfig = new XmlConfiguration(myUrl);
org.ehcache.CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig);
EhcacheCachingProvider provider = (EhcacheCachingProvider) Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
return provider.getCacheManager(provider.getDefaultURI(), myCacheManager.getRuntimeConfiguration());
}
}

View File

@@ -2,4 +2,5 @@ package dev.sheldan.sissi.module.debra.config;
public class DebraSlashCommandNames {
public static final String DEBRA = "debra";
public static final String DEBRA_INTERNAL = "debrainternal";
}

View File

@@ -0,0 +1,71 @@
package dev.sheldan.sissi.module.debra.listener;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.ListenerPriority;
import dev.sheldan.abstracto.core.interaction.InteractionService;
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListener;
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerModel;
import dev.sheldan.abstracto.core.interaction.button.listener.ButtonClickedListenerResult;
import dev.sheldan.abstracto.core.service.MessageService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.sissi.module.debra.config.DebraFeatureDefinition;
import dev.sheldan.sissi.module.debra.service.DonationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DebraInfoButtonClickedListener implements ButtonClickedListener {
@Autowired
private MessageService messageService;
@Autowired
private TemplateService templateService;
@Autowired
private InteractionService interactionService;
private static final String DEBRA_INFO_MESSAGE_TEMPLATE_KEY = "debraInfoMessage";
private static final String DEBRA_INFO_MESSAGE_RESPONSE_TEMPLATE_KEY = "debraInfoMessage_response";
@Override
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
MessageToSend messageToSend = templateService.renderEmbedTemplate(DEBRA_INFO_MESSAGE_TEMPLATE_KEY, new Object(), model.getServerId());
messageService.sendMessageToSendToUser(model.getEvent().getUser(), messageToSend).thenAccept(interactionHook -> {
log.info("Send debra info message to user {}", model.getEvent().getUser().getIdLong());
}).exceptionally(throwable -> {
log.error("Failed to send debra info message to user {}", model.getEvent().getUser().getIdLong(), throwable);
return null;
});
MessageToSend responseMessageToSend = templateService.renderEmbedTemplate(DEBRA_INFO_MESSAGE_RESPONSE_TEMPLATE_KEY, new Object(), model.getServerId());
FutureUtils.toSingleFutureGeneric(interactionService.sendMessageToInteraction(responseMessageToSend, model.getEvent().getInteraction().getHook()))
.thenAccept(interactionHook -> {
log.info("Send debra info message response to user {}", model.getEvent().getUser().getIdLong());
}).exceptionally(throwable -> {
log.error("Failed to send debra info message response to user {}", model.getEvent().getUser().getIdLong(), throwable);
return null;
});
return ButtonClickedListenerResult.ACKNOWLEDGED;
}
@Override
public Boolean handlesEvent(ButtonClickedListenerModel model) {
return model.getOrigin().equals(DonationService.DEBRA_INFO_BUTTON_ORIGIN);
}
@Override
public FeatureDefinition getFeature() {
return DebraFeatureDefinition.DEBRA;
}
@Override
public Integer getPriority() {
return ListenerPriority.MEDIUM;
}
}

View File

@@ -0,0 +1,20 @@
package dev.sheldan.sissi.module.debra.model.api;
import lombok.Builder;
import lombok.Getter;
import java.math.BigDecimal;
import java.math.BigInteger;
@Builder
@Getter
public class CampaignInfo {
private BigInteger donationCount;
private BigDecimal collected;
private BigDecimal target;
private String currency;
private String slug;
private String displayName;
private BigDecimal collectedNet;
private BigDecimal percent;
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.sissi.module.debra.model.api;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -10,11 +11,18 @@ import java.math.BigDecimal;
@Setter
@Builder
public class Description {
@SerializedName("collected")
private BigDecimal collected;
@SerializedName("target")
private BigDecimal target;
@SerializedName("currency")
private String currency;
@SerializedName("slug")
private String slug;
@SerializedName("displayname")
private String displayName;
@SerializedName("collectednet")
private BigDecimal collectedNet;
@SerializedName("percent")
private BigDecimal percent;
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.sissi.module.debra.model.api;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -10,10 +11,16 @@ import java.math.BigDecimal;
@Setter
@Builder
public class Donation {
@SerializedName("amount")
private BigDecimal amount;
@SerializedName("currency")
private String currency;
@SerializedName("text")
private String text;
@SerializedName("anonym")
private Integer anonym;
@SerializedName("firstname")
private String firstname;
@SerializedName("lastname")
private String lastname;
}

View File

@@ -0,0 +1,26 @@
package dev.sheldan.sissi.module.debra.model.api;
import dev.sheldan.sissi.module.debra.model.commands.DonationItemModel;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
@Getter
@Setter
@Builder
public class DonationInfo {
private String firstName;
private BigDecimal donationAmount;
private Boolean anonymous;
public static DonationInfo fromDonationItemModel(DonationItemModel donationItemModel) {
return DonationInfo
.builder()
.donationAmount(donationItemModel.getDonationAmount())
.anonymous(donationItemModel.getAnonymous())
.firstName(donationItemModel.getFirstName())
.build();
}
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.sissi.module.debra.model.api;
import lombok.Builder;
import lombok.Getter;
import java.math.BigDecimal;
import java.util.List;
@Getter
@Builder
public class DonationStats {
private List<DonationInfo> donations;
private BigDecimal totalAmount;
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.sissi.module.debra.model.api;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -11,7 +12,10 @@ import java.util.List;
@Setter
@Builder
public class DonationsResponse {
@SerializedName("page")
private Description page;
@SerializedName("donation_count")
private BigInteger donationCount;
@SerializedName("donations")
private List<Donation> donations;
}

View File

@@ -0,0 +1,12 @@
package dev.sheldan.sissi.module.debra.model.commands;
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Builder
@Getter
@Setter
public class DebraInfoButtonPayload implements ButtonPayload {
}

View File

@@ -0,0 +1,10 @@
package dev.sheldan.sissi.module.debra.model.commands;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class DebraInfoModel {
private String buttonId;
}

View File

@@ -2,10 +2,12 @@ package dev.sheldan.sissi.module.debra.model.commands;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
@Getter
@Setter
@Builder
public class DonationItemModel {
private String firstName;

View File

@@ -0,0 +1,18 @@
package dev.sheldan.sissi.module.debra.service;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
@Component
public class DonationCacheService implements InitializingBean {
@Autowired
private CacheManager cacheManager;
@Override
public void afterPropertiesSet() throws Exception {
cacheManager.getCache("donations");
}
}

View File

@@ -2,8 +2,14 @@ package dev.sheldan.sissi.module.debra.service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.interaction.ComponentPayloadService;
import dev.sheldan.abstracto.core.interaction.ComponentService;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.core.service.PostTargetService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
@@ -13,17 +19,22 @@ import dev.sheldan.sissi.module.debra.config.DebraProperties;
import dev.sheldan.sissi.module.debra.converter.DonationConverter;
import dev.sheldan.sissi.module.debra.model.api.Donation;
import dev.sheldan.sissi.module.debra.model.api.DonationsResponse;
import dev.sheldan.sissi.module.debra.model.commands.DebraInfoButtonPayload;
import dev.sheldan.sissi.module.debra.model.commands.DebraInfoModel;
import dev.sheldan.sissi.module.debra.model.commands.DonationItemModel;
import dev.sheldan.sissi.module.debra.model.commands.DonationsModel;
import dev.sheldan.sissi.module.debra.model.listener.DonationResponseModel;
import dev.sheldan.sissi.module.debra.model.listener.DonationNotificationModel;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal;
@@ -60,10 +71,28 @@ public class DonationService {
@Autowired
private ConfigService configService;
@Autowired
private ChannelService channelService;
@Autowired
private ComponentService componentService;
@Autowired
private ComponentPayloadService componentPayloadService;
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private DonationService self;
private static final String DEBRA_DONATION_NOTIFICATION_TEMPLATE_KEY = "debra_donation_notification";
private static final Pattern MESSAGE_PATTERN = Pattern.compile("(.*) hat (\\d{1,9},\\d{2}) Euro gespendet!<br \\/>Vielen Dank!<br \\/>Nachricht:<br \\/>(.*)");
private static final String DEBRA_INFO_BUTTON_MESSAGE_TEMPLATE_KEY = "debraInfoButton";
public static final String DEBRA_INFO_BUTTON_ORIGIN = "DEBRA_INFO_BUTTON";
public DonationResponseModel parseDonationFromMessage(String message) {
Matcher matcher = MESSAGE_PATTERN.matcher(message);
if (matcher.find()) {
@@ -105,23 +134,32 @@ public class DonationService {
.collect(Collectors.toList());
}
public DonationsResponse fetchCurrentDonationAmount(Long serverId) throws IOException {
Long fetchSize = configService.getLongValueOrConfigDefault(DEBRA_DONATION_API_FETCH_SIZE_KEY, serverId);
Request request = new Request.Builder()
.url(String.format(debraProperties.getDonationAPIUrl(), fetchSize))
.get()
.build();
Response response = okHttpClient.newCall(request).execute();
if(!response.isSuccessful()) {
if (log.isDebugEnabled()) {
log.error("Failed to retrieve urban dictionary definition. Response had code {} with body {}.",
response.code(), response.body());
}
throw new DonationAmountNotFoundException();
}
Gson gson = getGson();
@Cacheable(value = "donation-cache", cacheManager = "donationCacheManager")
public DonationsResponse getCachedDonationAmount(Long serverId) {
return fetchCurrentDonationAmount(serverId);
}
public DonationsResponse fetchCurrentDonationAmount(Long serverId) {
try {
Long fetchSize = configService.getLongValueOrConfigDefault(DEBRA_DONATION_API_FETCH_SIZE_KEY, serverId);
Request request = new Request.Builder()
.url(String.format(debraProperties.getDonationAPIUrl(), fetchSize))
.get()
.build();
Response response = okHttpClient.newCall(request).execute();
if(!response.isSuccessful()) {
if (log.isDebugEnabled()) {
log.error("Failed to retrieve donation response. Response had code {} with body {}.",
response.code(), response.body());
}
throw new DonationAmountNotFoundException();
}
Gson gson = getGson();
return gson.fromJson(response.body().string(), DonationsResponse.class);
} catch (Exception exception) {
throw new AbstractoRunTimeException(exception);
}
return gson.fromJson(response.body().string(), DonationsResponse.class);
}
private Gson getGson() {
@@ -130,7 +168,7 @@ public class DonationService {
.create();
}
private DonationsModel getDonationInfoModel(Long serverId) throws IOException {
private DonationsModel getDonationInfoModel(Long serverId) {
return donationConverter.convertDonationResponse(fetchCurrentDonationAmount(serverId));
}
@@ -148,4 +186,26 @@ public class DonationService {
firstMessage.addAll(secondMessage);
return FutureUtils.toSingleFutureGeneric(firstMessage);
}
public CompletableFuture<Void> sendDebraInfoButtonMessage(GuildMessageChannel guildMessageChannel) {
String buttonId = componentService.generateComponentId();
DebraInfoModel model = DebraInfoModel
.builder()
.buttonId(buttonId)
.build();
MessageToSend messageToSend = templateService.renderEmbedTemplate(DEBRA_INFO_BUTTON_MESSAGE_TEMPLATE_KEY, model, guildMessageChannel.getGuild().getIdLong());
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, guildMessageChannel)).thenAccept(unused -> {
self.persistButtonPayload(guildMessageChannel, buttonId);
});
}
@Transactional
public void persistButtonPayload(GuildMessageChannel guildMessageChannel, String buttonId) {
DebraInfoButtonPayload payload = DebraInfoButtonPayload
.builder()
.build();
AServer server = serverManagementService.loadServer(guildMessageChannel.getGuild().getIdLong());
componentPayloadService.createButtonPayload(buttonId, payload, DEBRA_INFO_BUTTON_ORIGIN, server);
}
}

View File

@@ -5,7 +5,7 @@ abstracto.postTargets.debraDonationNotification.name=debraDonationNotification
abstracto.postTargets.debraDonationNotification2.name=debraDonationNotification2
sissi.debra.websocketURL=ws://spenden.baba.fm:8765/
sissi.debra.donationAPIUrl=https://www.altruja.de/api/page/discord-fuer-debra-2022?details=1&num=%s&ort=0
sissi.debra.donationAPIUrl=https://www.altruja.de/api/page/discord-gg-austria-fuer-debra-2023?details=1&num=%s&ort=0
abstracto.systemConfigs.debraDonationNotificationDelayMillis.name=debraDonationNotificationDelayMillis
abstracto.systemConfigs.debraDonationNotificationDelayMillis.longValue=60000

View File

@@ -0,0 +1,24 @@
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="
http://www.ehcache.org/v3
http://www.ehcache.org/schema/ehcache-core-3.8-1.xsd">
<cache uses-template="default" alias="donation-cache">
<expiry>
<ttl unit="seconds">120</ttl>
</expiry>
<resources>
<heap unit="entries">5</heap>
</resources>
</cache>
<cache-template name="default">
<expiry>
<ttl unit="seconds">600</ttl>
</expiry>
<resources>
<heap>50</heap>
</resources>
</cache-template>
</config>

View File

@@ -0,0 +1,10 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -0,0 +1,20 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
<property name="utilityModule" value="(SELECT id FROM module WHERE name = 'utility')"/>
<property name="debraFeature" value="(SELECT id FROM feature WHERE key = 'debra')"/>
<changeSet author="Sheldan" id="debraInfoButton-command">
<insert tableName="command">
<column name="name" value="debraInfoButton"/>
<column name="module_id" valueComputed="${utilityModule}"/>
<column name="feature_id" valueComputed="${debraFeature}"/>
</insert>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,10 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
<include file="command.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -7,4 +7,5 @@
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
<include file="1.3.6/collection.xml" relativeToChangelogFile="true"/>
<include file="1.4.21/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.application</groupId>
<artifactId>sissi-modules</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.application</groupId>
<artifactId>application</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.application</groupId>
<artifactId>sissi-modules</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>sissi-modules</artifactId>
<groupId>dev.sheldan.sissi.application</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.4.21
version: 1.4.22
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.4.21"
appVersion: "1.4.22"

View File

@@ -0,0 +1,70 @@
{{- if .Values.restApi.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sissi.fullname" . }}-rest-api
spec:
replicas: 1
selector:
matchLabels:
app: rest-api
template:
metadata:
{{- with .Values.restApi.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
app: rest-api
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "sissi.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.restApi.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.restApi.securityContext | nindent 12 }}
image: "{{ .Values.restApi.repository }}/{{ .Values.restApi.image }}:{{ .Values.restApi.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.restApi.pullPolicy }}
env:
- name: SISSI_HOST
value: "{{ include "sissi.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local"
- name: SISSI_PORT
value: "{{ .Values.service.port }}"
ports:
- name: {{ .Values.restApi.service.name }}
containerPort: {{ .Values.restApi.service.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: {{ .Values.restApi.service.port }}
initialDelaySeconds: {{ $.Values.restApi.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ $.Values.restApi.livenessProbe.periodSeconds }}
failureThreshold: {{ $.Values.restApi.livenessProbe.failureThreshold }}
readinessProbe:
httpGet:
path: /
port: {{ .Values.restApi.service.port }}
initialDelaySeconds: {{ $.Values.restApi.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ $.Values.restApi.readinessProbe.periodSeconds }}
failureThreshold: {{ $.Values.restApi.readinessProbe.failureThreshold }}
resources:
{{- toYaml .Values.restApi.resources | nindent 12 }}
{{- with .Values.restApi.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.restApi.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.restApi.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,45 @@
{{- if .Values.restApi.enabled -}}
{{- $servicePort := .Values.restApi.service.port -}}
{{- $serviceName := .Values.restApi.service.name -}}
{{- $ingressPath := .Values.restApi.ingress.path -}}
{{- $ingressPathType := .Values.restApi.ingress.pathType -}}
{{- $extraPaths := .Values.restApi.ingress.extraPaths -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-rest-api
labels:
{{- with .Values.restApi.ingress.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.restApi.ingress.annotations }}
annotations:
{{- range $key, $value := . }}
{{ $key }}: {{ tpl $value $ | quote }}
{{- end }}
{{- end }}
spec:
ingressClassName: nginx
{{- with .Values.restApi.ingress.tls }}
tls:
{{- tpl (toYaml .) $ | nindent 4 }}
{{- end }}
rules:
{{- if .Values.restApi.ingress.hosts }}
{{- range .Values.restApi.ingress.hosts }}
- host: {{ tpl . $ }}
http:
paths:
{{- with $extraPaths }}
{{- toYaml . | nindent 10 }}
{{- end }}
- path: {{ $ingressPath }}
pathType: {{ $ingressPathType }}
backend:
service:
name: {{ $serviceName }}
port:
number: {{ $servicePort }}
{{- end }}
{{- end -}}
{{- end }}

View File

@@ -0,0 +1,12 @@
{{- if .Values.restApi.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.restApi.service.name }}
spec:
selector:
app: rest-api
ports:
- port: {{ .Values.restApi.service.targetPort }}
targetPort: {{ .Values.restApi.service.port }}
{{- end }}

View File

@@ -8,7 +8,7 @@ bot:
repository: harbor.sheldan.dev/sissi
pullPolicy: IfNotPresent
image: sissi-bot
tag: 1.4.21
tag: 1.4.22
livenessProbe:
initialDelaySeconds: 60
periodSeconds: 5
@@ -20,6 +20,49 @@ bot:
propertyConfig:
hikariPoolSize: 10
restApi:
enabled: true
repository: harbor.sheldan.dev/sissi
pullPolicy: IfNotPresent
image: sissi-rest-api
tag: 1.4.20
podAnnotations: {}
podSecurityContext: {}
securityContext: {}
livenessProbe:
initialDelaySeconds: 2
periodSeconds: 5
failureThreshold: 3
readinessProbe:
initialDelaySeconds: 2
periodSeconds: 5
failureThreshold: 3
service:
port: 8080
targetPort: 80
name: rest-api
resources:
limits:
cpu:
memory:
requests:
cpu:
memory:
nodeSelector: {}
tolerations: []
affinity: {}
ingress:
enabled: false
annotations: {}
labels: {}
path: /
pathType: Prefix
hosts:
extraPaths: []
tls: []
templateDeployment:
enabled: true
repository: harbor.sheldan.dev/abstracto
@@ -31,7 +74,7 @@ templateDeploymentData:
repository: harbor.sheldan.dev/sissi
pullPolicy: Always
image: sissi-template-data
tag: 1.4.21
tag: 1.4.22
dbConfigDeployment:
enabled: true
@@ -44,7 +87,7 @@ dbConfigDeploymentData:
repository: harbor.sheldan.dev/sissi
pullPolicy: Always
image: sissi-db-data
tag: 1.4.21
tag: 1.4.22
dbCredentials:
host:

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi</groupId>
<artifactId>deployment</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -797,6 +797,27 @@
</artifactItems>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/docker/rest-api/python</outputDirectory>
<resources>
<resource>
<directory>../../python/modules/rest-api/</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -1,2 +1,2 @@
REGISTRY_PREFIX=harbor.sheldan.dev/sissi/
VERSION=1.4.21
VERSION=1.4.22

View File

@@ -5,6 +5,10 @@ services:
build:
context: sissi
image: ${REGISTRY_PREFIX}sissi-bot:${VERSION:-latest}
rest-api:
build:
context: rest-api
image: ${REGISTRY_PREFIX}sissi-rest-api:${VERSION:-latest}
db-data:
build:
context: db-data

View File

@@ -0,0 +1,9 @@
FROM python:3.10.13-alpine3.18
ADD requirements.txt /
RUN pip install -r requirements.txt
RUN apk --no-cache add msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f
ADD wrapper /
ADD python /python
CMD ["/run.sh"]

View File

@@ -0,0 +1 @@
*

View File

@@ -0,0 +1,16 @@
blinker==1.7.0
certifi==2023.7.22
charset-normalizer==3.3.2
click==8.1.7
Flask==3.0.0
idna==3.4
importlib-metadata==6.8.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
Pillow==10.1.0
requests==2.31.0
urllib3==2.0.7
waitress==2.1.2
Werkzeug==3.0.1
zipp==3.17.0

View File

@@ -0,0 +1,4 @@
#!/bin/sh
echo "Starting python server..."
python3 -u python/main.py

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi</groupId>
<artifactId>sissi</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -13,7 +13,7 @@
<groupId>dev.sheldan.sissi</groupId>
<artifactId>sissi</artifactId>
<name>Sissi</name>
<version>1.4.21</version>
<version>1.4.22</version>
<properties>
<maven.compiler.target>17</maven.compiler.target>
@@ -59,7 +59,7 @@
<scm>
<url>https://maven.pkg.github.com/Sheldan/Sissi</url>
<developerConnection>scm:git:git@github.com:Sheldan/Sissi.git</developerConnection>
<tag>sissi-1.4.21</tag>
<tag>sissi-1.4.22</tag>
</scm>
</project>

View File

@@ -0,0 +1,229 @@
from flask import Flask, send_file, request
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
import requests
import os
import json
import logging
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(encoding='utf-8', level=logging.INFO, format=FORMAT)
app = Flask(__name__)
sissi_host = os.getenv('SISSI_HOST')
sissi_port = os.getenv('SISSI_PORT')
latest_donations_url = f'http://{sissi_host}:{sissi_port}/debra/latestDonations'
highest_donations_url = f'http://{sissi_host}:{sissi_port}/debra/highestDonations'
campaign_info_url = f'http://{sissi_host}:{sissi_port}/debra/campaignInfo'
class ValidationException(Exception):
def __init__(self, provided_value, message):
self.provided_value = provided_value
self.message = message
super().__init__(f'{self.message}: provided value: {provided_value}')
class DonationImageGenerationConstants:
allowed_fonts = ['Andale_Mono', 'Courier_New', 'Impact', 'Trebuchet_MS_Italic',
'Arial', 'Courier_New_Bold', 'Times_New_Roman', 'Verdana',
'Arial_Black', 'Courier_New_Bold_Italic', 'Times_New_Roman_Bold', 'Verdana_Bold',
'Arial_Bold', 'Courier_New_Italic', 'Times_New_Roman_Bold_Italic', 'Verdana_Bold_Italic',
'Arial_Bold_Italic', 'Georgia', 'Times_New_Roman_Italic', 'Verdana_Italic',
'Arial_Italic', 'Georgia_Bold', 'Trebuchet_MS',
'Comic_Sans_MS', 'Georgia_Bold_Italic', 'Trebuchet_MS_Bold',
'Comic_Sans_MS_Bold', 'Georgia_Italic', 'Trebuchet_MS_Bold_Italic']
font_range = (2, 150)
canvas_width_range = (1, 2500)
canvas_height_range = (1, 2500)
donation_count_range = (1, 25)
color_range = (0, 255)
font_default = 'Arial'
font_size_default = 40
canvas_width_default = 1024
canvas_height_default = 300
donation_count_default = 5
r_default = 0
g_default = 0
b_default = 0
class DonationImageGenerationParameters:
validation_message = ''
validation_value = ''
validated = None
def __init__(self, font_name, font_size, canvas_width, canvas_height, donation_count, r, g, b):
self.font_name = font_name
self.font_size = font_size
self.canvas_width = canvas_width
self.canvas_height = canvas_height
self.donation_count = donation_count
self.color = (r, g, b)
def validate(self):
self.validated = True
if self.font_name not in DonationImageGenerationConstants.allowed_fonts:
self.validated = False
self.validation_message = f'Font must be one of ' + ','.join(DonationImageGenerationConstants.allowed_fonts)
self.validation_value = self.font_name
if self.font_size > DonationImageGenerationConstants.font_range[1] or self.font_size < DonationImageGenerationConstants.font_range[0]:
self.validated = False
self.validation_message = f'Font size must be between {DonationImageGenerationConstants.font_range[0]} and {DonationImageGenerationConstants.font_range[1]}'
self.validation_value = self.font_size
if self.canvas_height > DonationImageGenerationConstants.canvas_height_range[1] or self.canvas_height < DonationImageGenerationConstants.canvas_height_range[0]:
self.validated = False
self.validation_message = f'Canvas height must be between {DonationImageGenerationConstants.canvas_height_range[0]} and {DonationImageGenerationConstants.canvas_height_range[1]}'
self.validation_value = self.canvas_height
if self.canvas_width > DonationImageGenerationConstants.canvas_width_range[1] or self.canvas_width < DonationImageGenerationConstants.canvas_width_range[0]:
self.validated = False
self.validation_message = f'Canvas width must be between {DonationImageGenerationConstants.canvas_width_range[0]} and {DonationImageGenerationConstants.color_range[1]}'
self.validation_value = self.canvas_width
if self.donation_count > DonationImageGenerationConstants.donation_count_range[1] or self.donation_count < DonationImageGenerationConstants.donation_count_range[0]:
self.validated = False
self.validation_message = f'Donation count must be between {DonationImageGenerationConstants.donation_count_range[0]} and {DonationImageGenerationConstants.donation_count_range[1]}'
self.validation_value = self.donation_count
if self.color[0] > DonationImageGenerationConstants.color_range[1] or self.color[0] < DonationImageGenerationConstants.color_range[0]:
self.validated = False
self.validation_message = f'Red must be between {DonationImageGenerationConstants.color_range[0]} and {DonationImageGenerationConstants.color_range[1]} inclusively'
self.validation_value = self.color[0]
if self.color[1] > DonationImageGenerationConstants.color_range[1] or self.color[1] < DonationImageGenerationConstants.color_range[0]:
self.validated = False
self.validation_message = f'Green must be between {DonationImageGenerationConstants.color_range[0]} and {DonationImageGenerationConstants.color_range[1]} inclusively'
self.validation_value = self.color[1]
if self.color[2] > DonationImageGenerationConstants.color_range[1] or self.color[2] < DonationImageGenerationConstants.color_range[0]:
self.validated = False
self.validation_message = f'Blue must be between {DonationImageGenerationConstants.color_range[0]} and {DonationImageGenerationConstants.color_range[1]} inclusively'
self.validation_value = self.color[2]
@app.route('/')
def hello():
return 'Hello, World?'
@app.route('/debra/latestDonations')
def latest_donations():
donation_stats = requests.get(latest_donations_url)
logging.info(f'returning latest donations')
return donation_stats.text
@app.route('/debra/highestDonations')
def highest_donations():
donation_stats = requests.get(highest_donations_url)
logging.info(f'returning highest donations')
return donation_stats.text
@app.route('/debra/campaignInfo')
def campaign_info_route():
donation_stats = requests.get(campaign_info_url)
logging.info(f'returning campaign info')
return donation_stats.text
@app.route('/debra/image/help')
def show_image_generation_help():
def make_param(parameters_obj, name, default, values):
parameters_obj[name] = {
'default': default,
'values': values
}
parameters = {}
make_param(parameters, 'font', DonationImageGenerationConstants.font_default, DonationImageGenerationConstants.allowed_fonts)
make_param(parameters, 'fontSize', DonationImageGenerationConstants.font_size_default, DonationImageGenerationConstants.font_range)
make_param(parameters, 'canvasWidth', DonationImageGenerationConstants.canvas_width_default, DonationImageGenerationConstants.canvas_width_range)
make_param(parameters, 'canvasHeight', DonationImageGenerationConstants.canvas_height_default, DonationImageGenerationConstants.canvas_height_range)
make_param(parameters, 'donationCount', DonationImageGenerationConstants.donation_count_default, DonationImageGenerationConstants.donation_count_range)
make_param(parameters, 'r', DonationImageGenerationConstants.r_default, DonationImageGenerationConstants.color_range)
make_param(parameters, 'g', DonationImageGenerationConstants.g_default, DonationImageGenerationConstants.color_range)
make_param(parameters, 'b', DonationImageGenerationConstants.b_default, DonationImageGenerationConstants.color_range)
info_object = {
'parameters': parameters
}
return json.dumps(info_object)
@app.route('/debra/image/info')
def total_donations_image():
campaign_info = json.loads(requests.get(campaign_info_url).text)
logging.info(f'rendering campaign info')
parameters = parse_image_parameters()
if not parameters.validated:
return parameters.validation_message, 400
img = Image.new('RGBA', (parameters.canvas_width, parameters.canvas_height), (255, 0, 0, 0))
d1 = ImageDraw.Draw(img)
font = ImageFont.truetype(f'{parameters.font_name}.ttf', parameters.font_size)
d1.text((0, 0), f"Aktuell {campaign_info['collected']}/{campaign_info['target']}", fill=parameters.color, font=font)
return serve_pil_image(img)
@app.route('/debra/image/latestDonations')
def latest_donation_image():
donation_stats = json.loads(requests.get(latest_donations_url).text)
logging.info(f'rendering latest donations')
parameters = parse_image_parameters()
if not parameters.validated:
return parameters.validation_message, 400
return rendering_donation_image(donation_stats, parameters)
@app.route('/debra/image/highestDonations')
def highest_donation_image():
donation_stats = json.loads(requests.get(highest_donations_url).text)
logging.info(f'rendering highest donations')
parameters = parse_image_parameters()
if not parameters.validated:
return parameters.validation_message, 400
return rendering_donation_image(donation_stats, parameters)
def rendering_donation_image(donation_stats, parameters):
img = Image.new('RGBA', (parameters.canvas_width, parameters.canvas_height), (255, 0, 0, 0))
d1 = ImageDraw.Draw(img)
font = ImageFont.truetype(f'{parameters.font_name}.ttf', parameters.font_size)
donations_to_draw = donation_stats['donations'][:parameters.donation_count]
height = parameters.font_size
it = 0
for donation in donations_to_draw:
name = donation['firstName'] if not donation['anonymous'] else 'anonym'
d1.text((0, height * it), f"{donation['donationAmount']}€ von {name}", fill=parameters.color, font=font)
it += 1
return serve_pil_image(img)
def parse_image_parameters() -> DonationImageGenerationParameters:
font = request.args.get('font', DonationImageGenerationConstants.font_default)
font_size = int(request.args.get('fontSize', DonationImageGenerationConstants.font_size_default))
canvas_width = int(request.args.get('canvasWidth', DonationImageGenerationConstants.canvas_width_default))
canvas_height = int(request.args.get('canvasHeight', DonationImageGenerationConstants.canvas_height_default))
donation_count = int(request.args.get('donationCount', DonationImageGenerationConstants.donation_count_default))
r = int(request.args.get('r', DonationImageGenerationConstants.r_default))
g = int(request.args.get('g', DonationImageGenerationConstants.g_default))
b = int(request.args.get('b', DonationImageGenerationConstants.b_default))
parameters = DonationImageGenerationParameters(font, font_size, canvas_width, canvas_height, donation_count, r, g, b)
parameters.validate()
return parameters
def serve_pil_image(pil_img):
img_io = BytesIO()
pil_img.save(img_io, 'PNG')
img_io.seek(0)
return send_file(img_io, mimetype='image/png')
if __name__ == "__main__":
from waitress import serve
serve(app, host="0.0.0.0", port=8080)

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi</groupId>
<artifactId>sissi</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>customization-templates</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>sissi-templates</artifactId>
<groupId>dev.sheldan.sissi.templates</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>module-templates</artifactId>
<groupId>dev.sheldan.sissi.templates</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -0,0 +1,11 @@
{
<#setting locale="de_DE">
"additionalMessage": "<@safe_include "debraInfoButton_text"/>",
"buttons": [
{
"label": "<@safe_include "debraInfoButton_button_label"/>",
"id": "${buttonId}",
"buttonStyle": "success"
}
]
}

View File

@@ -0,0 +1,6 @@
{
"additionalMessage": "<@safe_include "debraInfoButton_response_text"/>",
"messageConfig": {
"ephemeral": true
}
}

View File

@@ -0,0 +1,4 @@
{
<#setting locale="de_DE">
"additionalMessage": "<@safe_include "debraInfoMessage_text"/>"
}

View File

@@ -0,0 +1,7 @@
{
<#setting locale="de_DE">
"additionalMessage": "<@safe_include "debraInfoMessage_response_text"/>",
"messageConfig": {
"ephemeral": true
}
}

View File

@@ -25,7 +25,7 @@
"buttons": [
{
"label": "<@safe_include "debra_donation_notification_link_button_label"/>",
"url": "http://tiny.cc/schmetterling2022",
"url": "http://tiny.cc/schmetterling2023",
"buttonStyle": "link",
"metaConfig": {
"persistCallback": false

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>module-templates</artifactId>
<groupId>dev.sheldan.sissi.templates</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>sissi-templates</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>module-templates</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>module-templates</artifactId>
<groupId>dev.sheldan.sissi.templates</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -9,7 +9,7 @@
"title": "${title}",
"url": "${url}"
},
"description": "${url}<#if description?has_content>\n${description}</#if>",
"description": "${url?json_string}<#if description?has_content>\n${description?json_string}</#if>",
"footer": {
"text": "${category}"
}

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>templates</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>template-overrides</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>template-overrides</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates</groupId>
<artifactId>template-overrides</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>sissi-templates</artifactId>
<groupId>dev.sheldan.sissi.templates</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>dev.sheldan.sissi.templates.translations</groupId>
<artifactId>customization-translations</artifactId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>sissi-translations</artifactId>
<groupId>dev.sheldan.sissi.templates.translations</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>module-translations</artifactId>
<groupId>dev.sheldan.sissi.templates.translations</groupId>
<version>1.4.21</version>
<version>1.4.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -0,0 +1 @@
Klicke diesen Button um Information über Streaming für Debra zu erhalten.

View File

@@ -1 +1 @@
Aktuell wurden **${donationAmount} Euro** für Debra Austria gespendet. Spende auch du unter https://tiny.cc/schmetterling2022.
Aktuell wurden **${donationAmount} Euro** für Debra Austria gespendet. Spende auch du unter https://tiny.cc/schmetterling2023.

View File

@@ -0,0 +1,25 @@
Vielen Dank, dass du bei unserer Spendenaktion mithelfen willst!
OBS Einrichtung
Wir haben ein Dokument vorbereitet, in dem erklärt wird, wie die Onscreen Notifications eingerichtet werden können.
<https://docs.google.com/document/d/1BFCHdJSoYHzda70XVSTACNdpH5VSc6cRrq2TvKZPF9o/edit>
Grafiken und Overlays
Alle Grafiken von diesem und den letzten Jahren findest du in diesem Ordner. Alles darin darf frei für deine Streams verwendet werden.
<https://drive.google.com/drive/folders/1NamDlOm1vAnHsOKut--FxfVuCpld7jnR?usp=drive_link>
Spendenlink
Wir empfehlen neben dem Einrichten einer 'Kachel' auch, dass ihr einen !spenden Befehl bei eurem Bot (nightbot, moobot, self hosted etc.) hinzufügt.
Bitte verlinke dabei auf <https://tiny.cc/schmetterling2023>
Live-ping am Discord
Damit wir deinen Account zur Going Live Liste hinzufügen können, musst du uns nach der Einrichtung des Streams bescheid geben.
Antworte hierfür auf diese PM mit "Twitchname: " und deinem Twitchaccount.
Kalender
Planst du etwas größeres/spannendes/außergewöhnliche? Trage das Event in den gemeinsamen Kalender ein, damit wir es noch vor dem Stream ankündigen können um ggf. mehr Viewer zu gewinnen.
Alternativ kannst du auch einfach auf diese Nachricht antworten wenn du etwas planst:
<https://calendar.google.com/calendar/u/1?cid=MjhlMWIyYjlmNTkyMjczNzVlYTgxZjU2ZDA2YjBjYTQ0OTliODYwMzlkNWFlOGQzYWFlYzdkNmM1YzBlYmVkMUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t>
Fragen? Probleme?
Falls du noch Fragen oder Probleme hast, antworte einfach auf diese PM. Die Mods bekommen dann eine Nachricht und werden versuchen dich zu unterstütze

View File

@@ -1 +1 @@
Spende auch du für Debra Austria unter http://tiny.cc/schmetterling2022.
Spende auch du für Debra Austria unter http://tiny.cc/schmetterling2023.

View File

@@ -0,0 +1 @@
Creates a message in the target channel, people can use to receive information about Debra.

Some files were not shown because too many files have changed in this diff Show More