Search in sources :

Example 1 with UserActivityEndEvent

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();
}
Also used : Role(net.dv8tion.jda.api.entities.Role) AuditableRestAction(net.dv8tion.jda.api.requests.restaction.AuditableRestAction) User(net.dv8tion.jda.api.entities.User) UserActivityEndEvent(net.dv8tion.jda.api.events.user.UserActivityEndEvent) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) Test(org.junit.jupiter.api.Test)

Example 2 with UserActivityEndEvent

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));
    }
}
Also used : UserActivityEndEvent(net.dv8tion.jda.api.events.user.UserActivityEndEvent) ArrayList(java.util.ArrayList) UserUpdateActivitiesEvent(net.dv8tion.jda.api.events.user.update.UserUpdateActivitiesEvent) Activity(net.dv8tion.jda.api.entities.Activity) UserUpdateActivityOrderEvent(net.dv8tion.jda.api.events.user.update.UserUpdateActivityOrderEvent) UserActivityStartEvent(net.dv8tion.jda.api.events.user.UserActivityStartEvent)

Aggregations

UserActivityEndEvent (net.dv8tion.jda.api.events.user.UserActivityEndEvent)2 ArrayList (java.util.ArrayList)1 Activity (net.dv8tion.jda.api.entities.Activity)1 Guild (net.dv8tion.jda.api.entities.Guild)1 Member (net.dv8tion.jda.api.entities.Member)1 Role (net.dv8tion.jda.api.entities.Role)1 User (net.dv8tion.jda.api.entities.User)1 UserActivityStartEvent (net.dv8tion.jda.api.events.user.UserActivityStartEvent)1 UserUpdateActivitiesEvent (net.dv8tion.jda.api.events.user.update.UserUpdateActivitiesEvent)1 UserUpdateActivityOrderEvent (net.dv8tion.jda.api.events.user.update.UserUpdateActivityOrderEvent)1 AuditableRestAction (net.dv8tion.jda.api.requests.restaction.AuditableRestAction)1 MessageAction (net.dv8tion.jda.api.requests.restaction.MessageAction)1 Test (org.junit.jupiter.api.Test)1