mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-25 20:04:01 +00:00
[AB-52] upgrading to alpha 12
adding anonymous reporting reworking message context commands refactoring interaction packages adding post execution handling for message context commands and modals reworking feature mode response fixing setup using component ids storing infraction parameters, for example mute duration, with every infraction adding infractions for more moderation actions creating general method to format a duration string adding infractions command reworking muting to use built-in functionality of discord enabling chunking of members removing manual unmuting feature mode adding ability to update infractions with a command implemented infraction listeners for ban and warn refactored infraction notifications storing log messages to the infraction for editing said log messages
This commit is contained in:
@@ -40,7 +40,11 @@ public class EmoteTrackingListener implements AsyncMessageReceivedListener {
|
||||
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Map<Long, List<Emote>> collect = message.getEmotesBag().stream().collect(Collectors.groupingBy(Emote::getIdLong));
|
||||
Map<Long, List<Emote>> collect = message
|
||||
.getMentions()
|
||||
.getEmotesBag()
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(Emote::getIdLong));
|
||||
collect.values().forEach(groupedEmotes ->
|
||||
trackedEmoteService.addEmoteToRuntimeStorage(groupedEmotes.get(0), guildService.getGuildById(model.getServerId()), (long) groupedEmotes.size())
|
||||
);
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package dev.sheldan.abstracto.statistic.emote.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.core.service.GuildService;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageType;
|
||||
import org.apache.commons.collections4.Bag;
|
||||
import org.apache.commons.collections4.bag.HashBag;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EmoteTrackingListenerTest {
|
||||
|
||||
@InjectMocks
|
||||
private EmoteTrackingListener testUnit;
|
||||
|
||||
@Mock
|
||||
private TrackedEmoteService trackedEmoteService;
|
||||
|
||||
@Mock
|
||||
private GuildService guildService;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@Mock
|
||||
private MessageReceivedModel messageReceivedModel;
|
||||
|
||||
@Mock
|
||||
private Emote emote1;
|
||||
|
||||
@Mock
|
||||
private Emote emote2;
|
||||
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
private static final Long EMOTE_ID = 4L;
|
||||
private static final Long SERVER_ID = 3L;
|
||||
|
||||
@Test
|
||||
public void testExecuteOneEmote() {
|
||||
Bag<Emote> emotesBag = new HashBag<>();
|
||||
emotesBag.add(emote1);
|
||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||
setupMessage();
|
||||
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
||||
when(message.getEmotesBag()).thenReturn(emotesBag);
|
||||
testUnit.execute(messageReceivedModel);
|
||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote1, guild, 1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteOneEmoteMultipleTimes() {
|
||||
Bag<Emote> emotesBag = new HashBag<>();
|
||||
when(emote1.getIdLong()).thenReturn(EMOTE_ID);
|
||||
when(emote2.getIdLong()).thenReturn(EMOTE_ID);
|
||||
emotesBag.add(emote1);
|
||||
emotesBag.add(emote2);
|
||||
setupMessage();
|
||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||
when(message.getEmotesBag()).thenReturn(emotesBag);
|
||||
testUnit.execute(messageReceivedModel);
|
||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(any(Emote.class), eq(guild), eq(2L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteMultipleEmotes() {
|
||||
Bag<Emote> emotesBag = new HashBag<>();
|
||||
when(emote1.getIdLong()).thenReturn(EMOTE_ID);
|
||||
when(emote2.getIdLong()).thenReturn(EMOTE_ID + 1);
|
||||
emotesBag.add(emote1);
|
||||
emotesBag.add(emote2);
|
||||
setupMessage();
|
||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||
when(message.getEmotesBag()).thenReturn(emotesBag);
|
||||
testUnit.execute(messageReceivedModel);
|
||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote1, guild, 1L);
|
||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote2, guild, 1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteNoEmote() {
|
||||
when(message.getEmotesBag()).thenReturn(new HashBag<>());
|
||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||
setupMessage();
|
||||
testUnit.execute(messageReceivedModel);
|
||||
verify(trackedEmoteService, times(0)).addEmoteToRuntimeStorage(any(Emote.class), any(), anyLong());
|
||||
}
|
||||
|
||||
private void setupMessage() {
|
||||
when(message.isFromGuild()).thenReturn(true);
|
||||
when(message.isWebhookMessage()).thenReturn(false);
|
||||
MessageType type = MessageType.DEFAULT;
|
||||
when(message.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFeature() {
|
||||
Assert.assertEquals(StatisticFeatureDefinition.EMOTE_TRACKING, testUnit.getFeature());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user