Search in sources :

Example 21 with ScheduleEntry

use of ws.nmathe.saber.core.schedule.ScheduleEntry in project Saber-Bot by notem.

the class ParsingUtilities method compileUserList.

/**
 * generates a list of user IDs for a given RSVP category of an event
 * @param entry ScheduleEntry object
 * @param name name of RSVP category
 * @return List of Stings or null if category is invalid
 */
private static List<String> compileUserList(ScheduleEntry entry, String name) {
    List<String> users = null;
    if (name.toLowerCase().equals("no-input")) {
        List<String> rsvped = new ArrayList<>();
        Set<String> keys = entry.getRsvpMembers().keySet();
        for (String key : keys) {
            rsvped.addAll(entry.getRsvpMembersOfType(key));
        }
        JDA shard = Main.getShardManager().getJDA(entry.getGuildId());
        Guild guild = shard.getGuildById(entry.getGuildId());
        Channel channel = shard.getTextChannelById(entry.getChannelId());
        users = guild.getMembers().stream().filter(member -> member.getPermissions(channel).contains(Permission.MESSAGE_READ)).map(member -> member.getUser().getId()).filter(memberId -> !rsvped.contains(memberId)).collect(Collectors.toList());
    } else {
        List<String> members = entry.getRsvpMembers().get(name);
        if (members != null)
            users = entry.getRsvpMembersOfType(name);
    }
    return users;
}
Also used : java.util(java.util) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) ZonedDateTime(java.time.ZonedDateTime) StringUtils(org.apache.commons.lang3.StringUtils) ScheduleEntry(ws.nmathe.saber.core.schedule.ScheduleEntry) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ZoneId(java.time.ZoneId) ChronoUnit(java.time.temporal.ChronoUnit) Matcher(java.util.regex.Matcher) Permission(net.dv8tion.jda.core.Permission) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalTime(java.time.LocalTime) JDA(net.dv8tion.jda.core.JDA) Main(ws.nmathe.saber.Main) Pattern(java.util.regex.Pattern) JDA(net.dv8tion.jda.core.JDA)

Aggregations

ScheduleEntry (ws.nmathe.saber.core.schedule.ScheduleEntry)21 JDA (net.dv8tion.jda.core.JDA)6 Main (ws.nmathe.saber.Main)6 ZonedDateTime (java.time.ZonedDateTime)5 java.util (java.util)5 Message (net.dv8tion.jda.core.entities.Message)5 ZoneId (java.time.ZoneId)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 Permission (net.dv8tion.jda.core.Permission)4 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)4 StringUtils (org.apache.commons.lang3.StringUtils)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ChronoUnit (java.time.temporal.ChronoUnit)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 MessageReceivedEvent (net.dv8tion.jda.core.events.message.MessageReceivedEvent)3 Document (org.bson.Document)3 MessageUtilities (ws.nmathe.saber.utils.MessageUtilities)3 ParsingUtilities (ws.nmathe.saber.utils.ParsingUtilities)3