use of net.dv8tion.jda.api.events.user.UserActivityStartEvent in project Ninbot by Nincodedo.
the class StreamListenerTest method userStartsStreamingNotAlreadyStreamingOnCooldown.
@Test
void userStartsStreamingNotAlreadyStreamingOnCooldown() {
UserActivityStartEvent userActivityStartEvent = mock(UserActivityStartEvent.class);
Member member = mock(Member.class);
Guild guild = mock(Guild.class);
Activity activity = mock(Activity.class);
MessageAction messageAction = mock(MessageAction.class);
AuditableRestAction auditableRestAction = mock(AuditableRestAction.class);
when(configService.getValuesByName("123", ConfigConstants.STREAMING_ANNOUNCE_USERS)).thenReturn(List.of("123"));
when(userActivityStartEvent.getMember()).thenReturn(member);
when(member.getId()).thenReturn("123");
when(userActivityStartEvent.getGuild()).thenReturn(guild);
when(guild.getId()).thenReturn("123");
when(userActivityStartEvent.getNewActivity()).thenReturn(activity);
when(activity.getType()).thenReturn(Activity.ActivityType.STREAMING);
streamListener.onGenericUserPresence(userActivityStartEvent);
verify(messageAction, times(0)).queue();
verify(auditableRestAction, times(0)).queue();
}
use of net.dv8tion.jda.api.events.user.UserActivityStartEvent in project JDA by DV8FromTheWorld.
the class PresenceUpdateHandler method handleActivities.
private void handleActivities(List<Activity> newActivities, @Nullable MemberImpl member, MemberPresenceImpl presence) {
List<Activity> oldActivities = presence.getActivities();
presence.setActivities(newActivities);
if (member == null)
return;
boolean unorderedEquals = Helpers.deepEqualsUnordered(oldActivities, newActivities);
if (unorderedEquals) {
boolean deepEquals = Helpers.deepEquals(oldActivities, newActivities);
if (!deepEquals) {
getJDA().handleEvent(new UserUpdateActivityOrderEvent(getJDA(), responseNumber, oldActivities, member));
}
} else {
getJDA().getEntityBuilder().updateMemberCache(member);
// create modifiable copy
List<Activity> stoppedActivities = new ArrayList<>(oldActivities);
List<Activity> startedActivities = new ArrayList<>();
for (Activity activity : newActivities) {
if (!stoppedActivities.remove(activity))
startedActivities.add(activity);
}
for (Activity activity : startedActivities) {
getJDA().handleEvent(new UserActivityStartEvent(getJDA(), responseNumber, member, activity));
}
for (Activity activity : stoppedActivities) {
getJDA().handleEvent(new UserActivityEndEvent(getJDA(), responseNumber, member, activity));
}
getJDA().handleEvent(new UserUpdateActivitiesEvent(getJDA(), responseNumber, member, oldActivities));
}
}
use of net.dv8tion.jda.api.events.user.UserActivityStartEvent in project Ninbot by Nincodedo.
the class StreamListenerTest method userStartsStreamingNotAlreadyStreamingNoCooldown.
@Test
void userStartsStreamingNotAlreadyStreamingNoCooldown() {
UserActivityStartEvent userActivityStartEvent = mock(UserActivityStartEvent.class);
Member member = mock(Member.class);
Guild guild = mock(Guild.class);
Activity activity = mock(Activity.class);
User user = mock(User.class);
TextChannel textChannel = mock(TextChannel.class);
MessageAction messageAction = mock(MessageAction.class);
Role streamingRole = mock(Role.class);
RichPresence richPresence = mock(RichPresence.class);
AuditableRestAction auditableRestAction = mock(AuditableRestAction.class);
Message message = mock(Message.class);
when(configService.getValuesByName("123", ConfigConstants.STREAMING_ANNOUNCE_USERS)).thenReturn(List.of("123"));
when(configService.getSingleValueByName("123", ConfigConstants.STREAMING_ANNOUNCE_CHANNEL)).thenReturn(Optional.of("123"));
when(configService.getSingleValueByName("123", ConfigConstants.STREAMING_ROLE)).thenReturn(Optional.of("123"));
when(userActivityStartEvent.getMember()).thenReturn(member);
when(member.getUser()).thenReturn(user);
when(member.getId()).thenReturn("123");
when(userActivityStartEvent.getGuild()).thenReturn(guild);
when(guild.getId()).thenReturn("123");
when(userActivityStartEvent.getNewActivity()).thenReturn(activity);
when(activity.getType()).thenReturn(Activity.ActivityType.STREAMING);
when(userActivityStartEvent.getUser()).thenReturn(user);
when(user.getName()).thenReturn("Nin");
when(activity.isRich()).thenReturn(true);
when(activity.asRichPresence()).thenReturn(richPresence);
when(activity.getUrl()).thenReturn("https://twitch.tv/nincodedo");
when(richPresence.getState()).thenReturn("Zeldo Breath of the Wild 2");
when(guild.getLocale()).thenReturn(Locale.ENGLISH);
when(guild.getMember(user)).thenReturn(member);
when(guild.getTextChannelById("123")).thenReturn(textChannel);
when(textChannel.sendMessage(any(Message.class))).thenReturn(messageAction);
when(guild.getRoleById("123")).thenReturn(streamingRole);
when(guild.addRoleToMember(member, streamingRole)).thenReturn(auditableRestAction);
when(textChannel.getLatestMessageId()).thenReturn("123");
when(textChannel.retrieveMessageById("123")).thenReturn(auditableRestAction);
when(auditableRestAction.complete()).thenReturn(message);
when(message.getContentRaw()).thenReturn("some other stream announcement");
streamListener.onGenericUserPresence(userActivityStartEvent);
verify(messageAction, times(1)).queue(any());
verify(auditableRestAction, times(1)).queue();
}
use of net.dv8tion.jda.api.events.user.UserActivityStartEvent in project Ninbot by Nincodedo.
the class StreamListenerTest method userNotStreamingStartsOtherActivity.
@Test
void userNotStreamingStartsOtherActivity() {
UserActivityStartEvent userActivityStartEvent = mock(UserActivityStartEvent.class);
Member member = mock(Member.class);
Guild guild = mock(Guild.class);
Activity activity = mock(Activity.class);
MessageAction messageAction = mock(MessageAction.class);
AuditableRestAction auditableRestAction = mock(AuditableRestAction.class);
when(configService.getValuesByName("123", ConfigConstants.STREAMING_ANNOUNCE_USERS)).thenReturn(List.of("123"));
when(userActivityStartEvent.getMember()).thenReturn(member);
when(member.getId()).thenReturn("123");
when(userActivityStartEvent.getGuild()).thenReturn(guild);
when(guild.getId()).thenReturn("123");
when(userActivityStartEvent.getNewActivity()).thenReturn(activity);
when(activity.getType()).thenReturn(Activity.ActivityType.PLAYING);
streamListener.onGenericUserPresence(userActivityStartEvent);
verify(messageAction, times(0)).queue();
verify(auditableRestAction, times(0)).queue();
}
Aggregations