Skip to content

Commit

Permalink
Merge branch 'hotfix/3.11.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nincodedo committed Jan 16, 2023
2 parents 6b9eec5 + b38979c commit 8946b3c
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 37 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/create-release-on-tag-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ on:
tags:
- "*"
jobs:
createRelease:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
discussion_category_name: 'Releases'
buildMaven:
name: Build Maven
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,6 +48,19 @@ jobs:
tags: |
ghcr.io/nincodedo/ninbot:latest
ghcr.io/nincodedo/ninbot:${{ github.sha }}
ghcr.io/nincodedo/ninbot:${{ github.ref_name }}
createRelease:
needs: [buildMaven, buildDocker]
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
discussion_category_name: 'Releases'
deployGKE:
needs: [buildMaven, buildDocker]
name: Deploy GKE
Expand All @@ -72,5 +75,7 @@ jobs:
with:
cluster_name: ninbot-cluster
location: us-central1-c
- name: GKE Update Configs
run: kubectl patch configmap ninbot-config -p '{"data":{"OTEL_RESOURCE_ATTRIBUTES":"service.name=ninbot-${{ github.ref_name }},deployment.environment=PROD", "OTEL_SERVICE_NAME":"ninbot-${{ github.ref_name }}"}}'
- name: GKE Deploy
run: kubectl set image deployment/ninbot ninbot=ghcr.io/nincodedo/ninbot:${{ github.sha }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM maven:3.8.6-eclipse-temurin-19 AS build

ARG open_telemetry_version=v1.20.2
ARG open_telemetry_version=v1.22.1
COPY . ./
RUN mvn -B package -P git-commit
RUN cp ninbot-app/target/ninbot-*.jar ninbot.jar
Expand Down
2 changes: 1 addition & 1 deletion ninbot-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>dev.nincodedo</groupId>
<artifactId>ninbot-shared-parent</artifactId>
<version>3.11.0</version>
<version>3.11.1</version>
<relativePath>../ninbot-shared-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.nincodedo.ninbot.components.channel.voice;

import net.dv8tion.jda.api.sharding.ShardManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ScheduledCleanup {
private final TempVoiceChannelRepository tempVoiceChannelRepository;
private final ShardManager shardManager;

public ScheduledCleanup(TempVoiceChannelRepository tempVoiceChannelRepository, ShardManager shardManager) {
this.tempVoiceChannelRepository = tempVoiceChannelRepository;
this.shardManager = shardManager;
}

@Scheduled(fixedDelay = 12, timeUnit = TimeUnit.HOURS, initialDelay = 1)
public void deleteEmptyTempChannels() {
tempVoiceChannelRepository.findAll().forEach(tempVoiceChannel -> {
var voiceChannel = shardManager.getVoiceChannelById(tempVoiceChannel.getVoiceChannelId());
if (voiceChannel == null) {
tempVoiceChannelRepository.delete(tempVoiceChannel);
} else if (voiceChannel.getMembers().isEmpty()) {
voiceChannel.delete().queue(success -> tempVoiceChannelRepository.delete(tempVoiceChannel));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import dev.nincodedo.nincord.persistence.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class TempVoiceChannelManager extends StatAwareListenerAdapter {

public TempVoiceChannelManager(StatManager statManager,
@Qualifier("statCounterThreadPool") ExecutorService executorService,
TempVoiceChannelRepository tempVoiceChannelRepository,
ComponentService componentService) {
TempVoiceChannelRepository tempVoiceChannelRepository, ComponentService componentService) {
super(statManager, executorService);
this.repository = tempVoiceChannelRepository;
this.componentService = componentService;
Expand All @@ -54,13 +53,10 @@ private void checkIfShouldCreateTempChannel(Guild guild, Member member, AudioCha
if (componentService.isDisabled(componentName, guild.getId()) || channelJoined == null) {
return;
}
log.trace("hasPermission: {}, channel join {} is temp creator: {}", hasManageChannelPermission(guild
), channelJoined
.getName(), channelJoined.getName()
log.trace("hasPermission: {}, channel join {} is temp creator: {}", hasManageChannelPermission(guild),
channelJoined.getName(), channelJoined.getName()
.startsWith(Emojis.PLUS));
if (hasManageChannelPermission(guild) && channelJoined
.getName()
.startsWith(Emojis.PLUS)) {
if (hasManageChannelPermission(guild) && channelJoined.getName().startsWith(Emojis.PLUS)) {
countOneStat(componentName, guild.getId());
createTemporaryChannel(channelJoined, guild, member);
}
Expand All @@ -70,19 +66,16 @@ private void createTemporaryChannel(AudioChannelUnion channelJoined, Guild guild
var channelNameType = channelJoined.getName().substring(2);
var channelName = String.format("%s's %s", member.getEffectiveName().replace(Emojis.PLUS, ""), channelNameType);
log.trace("Creating temporary channel named {} for member {} in server {}", channelName,
FormatLogObject.memberInfo(member),
FormatLogObject.guildName(guild));
FormatLogObject.memberInfo(member), FormatLogObject.guildName(guild));
if (channelJoined.getType() == ChannelType.VOICE) {
var voiceChannel = channelJoined.asVoiceChannel();
voiceChannel.createCopy()
.setName(channelName)
.queue(saveAndMove(guild, member));
voiceChannel.createCopy().setName(channelName).queue(saveAndMove(guild, member));
}
}

Consumer<VoiceChannel> saveAndMove(Guild guild, Member member) {
return voiceChannel -> {
repository.save(new TempVoiceChannel(member.getId(), voiceChannel.getId()));
repository.save(new TempVoiceChannel(voiceChannel.getId(), member.getId()));
guild.moveVoiceMember(member, voiceChannel).queue();
voiceChannel.getPermissionContainer()
.getManager()
Expand All @@ -109,9 +102,8 @@ private boolean isTemporaryChannel(String voiceChannelId) {

private void deleteTemporaryChannel(AudioChannelUnion audioChannel) {
audioChannel.delete()
.queueAfter(10, TimeUnit.SECONDS, success ->
repository.findByVoiceChannelId(audioChannel.getId())
.ifPresent(tempVoiceChannel -> repository.delete(tempVoiceChannel)));
.queueAfter(10, TimeUnit.SECONDS, success -> repository.findByVoiceChannelId(audioChannel.getId())
.ifPresent(repository::delete));
}

private boolean hasManageChannelPermission(Guild guild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ void onGuildVoiceJoin() {
var voiceChannel = Mockito.mock(VoiceChannel.class);

when(joinEvent.getGuild()).thenReturn(guild);
when(guild.getId()).thenReturn("1");
when(guild.getId()).thenReturn("12");
when(guild.getSelfMember()).thenReturn(selfMember);
when(joinEvent.getChannelJoined()).thenReturn(voiceChannelJoined);
when(voiceChannelJoined.asVoiceChannel()).thenReturn(voiceChannel);
when(joinEvent.getMember()).thenReturn(member);
when(voiceChannelJoined.getName()).thenReturn(Emojis.PLUS + " wot");
when(selfMember.hasPermission(any(Permission.class))).thenReturn(true);
when(member.getEffectiveName()).thenReturn("Nincodedo");
when(member.getId()).thenReturn("1");
when(member.getIdLong()).thenReturn(1L);
when(member.getId()).thenReturn("21");
when(member.getIdLong()).thenReturn(21L);
when(voiceChannel.createCopy()).thenReturn(restAction);
when(restAction.setName(anyString())).thenReturn(lastRestAction);
when(guild.moveVoiceMember(member, voiceChannel)).thenReturn(moveVoiceAction);
Expand All @@ -96,6 +96,6 @@ void onGuildVoiceJoin() {
Consumer<VoiceChannel> consumer = lambdaCaptor.getValue();
consumer.accept(voiceChannel);

verify(tempVoiceChannelRepository).save(new TempVoiceChannel(member.getId(), voiceChannelJoined.getId()));
verify(tempVoiceChannelRepository).save(new TempVoiceChannel(voiceChannelJoined.getId(), member.getId()));
}
}
2 changes: 1 addition & 1 deletion ninbot-shared-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>dev.nincodedo</groupId>
<artifactId>ninbot-shared-parent</artifactId>
<version>3.11.0</version>
<version>3.11.1</version>
<packaging>pom</packaging>
<name>Ninbot Shared Parent Pom</name>

Expand Down
2 changes: 1 addition & 1 deletion ninbot-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>dev.nincodedo</groupId>
<artifactId>ninbot-shared-parent</artifactId>
<version>3.11.0</version>
<version>3.11.1</version>
<relativePath>../ninbot-shared-parent</relativePath>
</parent>
<artifactId>ninbot-test-coverage</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion nincord-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>dev.nincodedo</groupId>
<artifactId>ninbot-shared-parent</artifactId>
<version>3.11.0</version>
<version>3.11.1</version>
<relativePath>../ninbot-shared-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>dev.nincodedo</groupId>
<artifactId>ninbot-shared-parent</artifactId>
<version>3.11.0</version>
<version>3.11.1</version>
<relativePath>ninbot-shared-parent</relativePath>
</parent>
<artifactId>ninbot</artifactId>
Expand Down

0 comments on commit 8946b3c

Please sign in to comment.