use of net.dv8tion.jda.api.events.user.UserActivityEndEvent in project Ninbot by Nincodedo.
the class StreamListenerTest method userStopsStreaming.
@Test
void userStopsStreaming() {
UserActivityEndEvent userActivityEndEvent = mock(UserActivityEndEvent.class);
Member member = mock(Member.class);
Guild guild = mock(Guild.class);
MessageAction messageAction = mock(MessageAction.class);
AuditableRestAction auditableRestAction = mock(AuditableRestAction.class);
Role streamingRole = mock(Role.class);
User user = mock(User.class);
when(configService.getSingleValueByName("123", ConfigConstants.STREAMING_ROLE)).thenReturn(Optional.of("123"));
when(userActivityEndEvent.getMember()).thenReturn(member);
when(member.getUser()).thenReturn(user);
when(user.getId()).thenReturn("123");
when(member.getId()).thenReturn("123");
when(userActivityEndEvent.getGuild()).thenReturn(guild);
when(guild.getId()).thenReturn("123");
when(guild.getRoleById("123")).thenReturn(streamingRole);
when(guild.removeRoleFromMember(member, streamingRole)).thenReturn(auditableRestAction);
streamListener.onGenericUserPresence(userActivityEndEvent);
verify(messageAction, times(0)).queue();
verify(auditableRestAction, times(1)).queue();
}
use of net.dv8tion.jda.api.events.user.UserActivityEndEvent 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));
}
}
Aggregations