Search in sources :

Example 21 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementMessageFormatter method getSubscriberNames.

public static String getSubscriberNames(Announcement a) {
    // Loop and get subs without mentions...
    IGuild guild = Main.client.getGuildByID(a.getGuildId());
    StringBuilder userMentions = new StringBuilder();
    for (String userId : a.getSubscriberUserIds()) {
        try {
            IUser user = guild.getUserByID(Long.valueOf(userId));
            if (user != null) {
                userMentions.append(user.getName()).append(" ");
            }
        } catch (Exception e) {
        // User does not exist, safely ignore.
        }
    }
    StringBuilder roleMentions = new StringBuilder();
    Boolean mentionEveryone = false;
    Boolean mentionHere = false;
    for (String roleId : a.getSubscriberRoleIds()) {
        if (roleId.equalsIgnoreCase("everyone")) {
            mentionEveryone = true;
        } else if (roleId.equalsIgnoreCase("here")) {
            mentionHere = true;
        } else {
            try {
                IRole role = guild.getRoleByID(Long.valueOf(roleId));
                if (role != null) {
                    roleMentions.append(role.getName()).append(" ");
                }
            } catch (Exception e) {
            // Role does not exist, safely ignore.
            }
        }
    }
    String message = "Subscribers: " + userMentions + " " + roleMentions;
    if (mentionEveryone) {
        message = message + " " + guild.getEveryoneRole().getName();
    }
    if (mentionHere) {
        message = message + " here";
    }
    return message;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 22 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementMessageFormatter method sendAnnouncementDM.

static void sendAnnouncementDM(Announcement announcement, Event event, IUser user, CalendarData data, GuildSettings settings) {
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal");
    em.withTitle(MessageManager.getMessage("Embed.Announcement.Announce.Title", settings));
    EventData ed = DatabaseManager.getManager().getEventData(announcement.getGuildId(), event.getId());
    if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
        em.withImage(ed.getImageLink());
    }
    if (event.getSummary() != null) {
        String summary = event.getSummary();
        if (summary.length() > 250) {
            summary = summary.substring(0, 250);
            summary = summary + " (continues on Google Calendar View)";
        }
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Summary", settings), summary, true);
    }
    if (event.getDescription() != null) {
        String description = event.getDescription();
        if (description.length() > 250) {
            description = description.substring(0, 250);
            description = description + " (continues on Google Calendar View)";
        }
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Description", settings), description, true);
    }
    if (!settings.usingSimpleAnnouncements()) {
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Date", settings), EventMessageFormatter.getHumanReadableDate(event.getStart(), settings, false), true);
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Time", settings), EventMessageFormatter.getHumanReadableTime(event.getStart(), settings, false), true);
        try {
            Calendar service = CalendarAuth.getCalendarService();
            String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.TimeZone", settings), tz, true);
        } catch (Exception e1) {
            em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.TimeZone", settings), "Unknown *Error Occurred", true);
        }
    } else {
        String start = EventMessageFormatter.getHumanReadableDate(event.getStart(), settings, false) + " at " + EventMessageFormatter.getHumanReadableTime(event.getStart(), settings, false);
        try {
            Calendar service = CalendarAuth.getCalendarService();
            String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
            start = start + " " + tz;
        } catch (Exception e1) {
            start = start + " (TZ UNKNOWN/ERROR)";
        }
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Start", settings), start, false);
    }
    if (event.getLocation() != null && !event.getLocation().equalsIgnoreCase("")) {
        if (event.getLocation().length() > 300) {
            String location = event.getLocation().substring(0, 300).trim() + "... (cont. on Google Cal)";
            em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
        } else {
            em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
        }
    }
    if (!settings.usingSimpleAnnouncements()) {
        em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.EventID", settings), event.getId(), false);
    }
    em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
    em.withUrl(event.getHtmlLink());
    if (!settings.usingSimpleAnnouncements()) {
        em.withFooterText(MessageManager.getMessage("Embed.Announcement.Announce.ID", "%id%", announcement.getAnnouncementId().toString(), settings));
    }
    try {
        EventColor ec = EventColor.fromNameOrHexOrID(event.getColorId());
        em.withColor(ec.getR(), ec.getG(), ec.getB());
    } catch (Exception e) {
        // I dunno, color probably null.
        em.withColor(56, 138, 237);
    }
    IGuild guild = Main.client.getGuildByID(announcement.getGuildId());
    String msg = MessageManager.getMessage("Embed.Announcement.Announce.Dm.Message", "%guild%", guild.getName(), settings);
    Message.sendDirectMessage(msg, em.build(), user);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Calendar(com.google.api.services.calendar.Calendar) EventColor(com.cloudcraftgaming.discal.api.enums.event.EventColor) IGuild(sx.blah.discord.handle.obj.IGuild) EventData(com.cloudcraftgaming.discal.api.object.event.EventData)

Example 23 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.

the class GuildUtils method getGuilds.

public static List<WebGuild> getGuilds(String userId) {
    List<WebGuild> guilds = new ArrayList<>();
    IUser user = Main.client.getUserByID(Long.valueOf(userId));
    for (IGuild g : Main.client.getGuilds()) {
        if (g.getUserByID(Long.valueOf(userId)) != null) {
            WebGuild wg = new WebGuild().fromGuild(g);
            wg.setManageServer(PermissionChecker.hasManageServerRole(g, user));
            wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, user));
            guilds.add(wg);
        }
    }
    return guilds;
}
Also used : ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 24 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.

the class Logger method debug.

public void debug(@Nullable IUser author, String message, @Nullable String info, Class clazz, boolean post) {
    String timeStamp = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Calendar.getInstance().getTime());
    if (Main.client != null) {
        if (post) {
            IUser bot = Main.getSelfUser();
            EmbedBuilder em = new EmbedBuilder();
            assert bot != null;
            em.withAuthorIcon(bot.getAvatarURL());
            if (author != null) {
                em.withAuthorName(author.getName());
                em.withThumbnail(author.getAvatarURL());
            }
            em.withColor(239, 15, 0);
            em.withFooterText(clazz.getName());
            em.appendField("Time", timeStamp, true);
            if (info != null) {
                em.appendField("Additional Info", info, true);
            }
            // Get DisCal guild and channel..
            IGuild guild = Main.client.getGuildByID(266063520112574464L);
            IChannel channel = guild.getChannelByID(302249332244217856L);
            Message.sendMessage(em.build(), "```" + message + "```", channel);
        }
    }
    // ALWAYS LOG TO FILE!
    try {
        FileWriter file = new FileWriter(debugFile, true);
        file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
        if (author != null) {
            file.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
        }
        if (message != null) {
            file.write("message: " + message + MessageUtils.lineBreak);
        }
        if (info != null) {
            file.write("info: " + info + MessageUtils.lineBreak);
        }
        file.close();
    } catch (IOException io) {
        io.printStackTrace();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) FileWriter(java.io.FileWriter) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 25 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project lavaplayer by sedmelluq.

the class Main method onMessageReceived.

@EventSubscriber
public void onMessageReceived(MessageReceivedEvent event) {
    IMessage message = event.getMessage();
    String[] command = message.getContent().split(" ", 2);
    IGuild guild = message.getGuild();
    if (guild != null) {
        if ("~play".equals(command[0]) && command.length == 2) {
            loadAndPlay(message.getChannel(), command[1]);
        } else if ("~skip".equals(command[0])) {
            skipTrack(message.getChannel());
        }
    }
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) IGuild(sx.blah.discord.handle.obj.IGuild) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Aggregations

IGuild (sx.blah.discord.handle.obj.IGuild)31 IUser (sx.blah.discord.handle.obj.IUser)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 IChannel (sx.blah.discord.handle.obj.IChannel)7 ArrayList (java.util.ArrayList)5 IRole (sx.blah.discord.handle.obj.IRole)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 DiscordException (sx.blah.discord.util.DiscordException)4 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)3 HashMap (java.util.HashMap)3 List (java.util.List)3 MissingPermissionsException (sx.blah.discord.util.MissingPermissionsException)3 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)2 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)2 Calendar (com.google.api.services.calendar.Calendar)2 Language (enums.Language)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2