Search in sources :

Example 1 with AuditableRestAction

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

Example 2 with AuditableRestAction

use of net.dv8tion.jda.api.requests.restaction.AuditableRestAction 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 3 with AuditableRestAction

use of net.dv8tion.jda.api.requests.restaction.AuditableRestAction in project PorkBot by DaMatrix.

the class CommandMuteAll method execute.

@Override
public void execute(GuildMessageReceivedEvent evt, String[] args, String rawContent) {
    Member member = evt.getMember();
    VoiceChannel channel = member.getVoiceState().getChannel();
    if (channel == null) {
        evt.getChannel().sendMessage("You are not connected to a voice channel!").queue();
        return;
    } else if (!member.hasPermission(channel, Permission.VOICE_MUTE_OTHERS)) {
        evt.getChannel().sendMessage("You do not have permission to mute others!").queue();
        return;
    } else if (!evt.getGuild().getMember(evt.getJDA().getSelfUser()).hasPermission(channel, Permission.VOICE_MUTE_OTHERS)) {
        evt.getChannel().sendMessage("Bot does not have permission to mute others!").queue();
        return;
    }
    channel.getMembers().stream().filter(m -> !m.hasPermission(channel, Permission.VOICE_MUTE_OTHERS)).map(this).forEach(AuditableRestAction::queue);
    evt.getChannel().sendMessage(this.word + " all users in " + channel.getName()).queue(Constants.DELETE_LATER);
    if (evt.getGuild().getMember(evt.getJDA().getSelfUser()).hasPermission(evt.getChannel(), Permission.MESSAGE_MANAGE)) {
        evt.getMessage().delete().queue();
    }
}
Also used : AuditableRestAction(net.dv8tion.jda.api.requests.restaction.AuditableRestAction) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Member(net.dv8tion.jda.api.entities.Member)

Example 4 with AuditableRestAction

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

Example 5 with AuditableRestAction

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

Aggregations

Member (net.dv8tion.jda.api.entities.Member)5 AuditableRestAction (net.dv8tion.jda.api.requests.restaction.AuditableRestAction)5 Guild (net.dv8tion.jda.api.entities.Guild)4 MessageAction (net.dv8tion.jda.api.requests.restaction.MessageAction)4 Test (org.junit.jupiter.api.Test)4 Activity (net.dv8tion.jda.api.entities.Activity)3 UserActivityStartEvent (net.dv8tion.jda.api.events.user.UserActivityStartEvent)3 Role (net.dv8tion.jda.api.entities.Role)2 User (net.dv8tion.jda.api.entities.User)2 Message (net.dv8tion.jda.api.entities.Message)1 RichPresence (net.dv8tion.jda.api.entities.RichPresence)1 TextChannel (net.dv8tion.jda.api.entities.TextChannel)1 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)1 UserActivityEndEvent (net.dv8tion.jda.api.events.user.UserActivityEndEvent)1