Search in sources :

Example 6 with IMessage

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

the class AnnouncementCreator method init.

public Announcement init(MessageReceivedEvent e, String announcementId, GuildSettings settings) {
    if (!hasAnnouncement(e.getGuild().getLongID()) && AnnouncementUtils.announcementExists(announcementId, e)) {
        Announcement toCopy = DatabaseManager.getManager().getAnnouncement(UUID.fromString(announcementId), e.getGuild().getLongID());
        // Copy
        Announcement a = new Announcement(toCopy);
        if (PermissionChecker.botHasMessageManagePerms(e)) {
            IMessage msg = Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), MessageManager.getMessage("Creator.Announcement.Copy.Success", settings), e);
            a.setCreatorMessage(msg);
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
        }
        announcements.add(a);
        return a;
    }
    return getAnnouncement(e.getGuild().getLongID());
}
Also used : Announcement(com.cloudcraftgaming.discal.api.object.announcement.Announcement) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 7 with IMessage

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

the class UserUtils method getIUser.

public static IUser getIUser(String toLookFor, IMessage m, IGuild guild) {
    toLookFor = toLookFor.trim();
    final String lower = toLookFor.toLowerCase();
    IUser res = null;
    if (m != null && !m.getMentions().isEmpty())
        res = m.getMentions().get(0);
    if (toLookFor.matches("<@!?[0-9]+>")) {
        IUser u = guild.getUserByID(Long.parseUnsignedLong(toLookFor.replaceAll("[^0-9]", "")));
        if (u != null) {
            return u;
        }
    }
    List<IUser> users = guild.getUsers().stream().filter(u -> u.getName().toLowerCase().contains(lower) || u.getName().equalsIgnoreCase(lower) || u.getStringID().equals(lower) || u.getDisplayName(guild).toLowerCase().contains(lower) || u.getDisplayName(guild).equalsIgnoreCase(lower)).collect(Collectors.toList());
    if (!users.isEmpty())
        res = users.get(0);
    return res;
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) IGuild(sx.blah.discord.handle.obj.IGuild) IUser(sx.blah.discord.handle.obj.IUser) List(java.util.List) GeneralUtils(com.cloudcraftgaming.discal.api.utils.GeneralUtils) Collectors(java.util.stream.Collectors) MessageReceivedEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser)

Example 8 with IMessage

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

the class CalendarCreator method init.

// Functionals
/**
 * Initiates the CalendarCreator for the guild involved in the event.
 *
 * @param e            The event received upon creation start.
 * @param calendarName The name of the calendar to create.
 * @return The PreCalendar object created.
 */
public PreCalendar init(MessageReceivedEvent e, String calendarName, GuildSettings settings, boolean handleCreatorMessage) {
    long guildId = e.getMessage().getGuild().getLongID();
    if (!hasPreCalendar(guildId)) {
        PreCalendar calendar = new PreCalendar(guildId, calendarName);
        if (handleCreatorMessage) {
            if (PermissionChecker.botHasMessageManagePerms(e)) {
                IMessage msg = Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(calendar, settings), MessageManager.getMessage("Creator.Calendar.Create.Init", settings), e);
                calendar.setCreatorMessage(msg);
            } else {
                Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
            }
        }
        calendars.add(calendar);
        return calendar;
    }
    return getPreCalendar(e.getMessage().getGuild().getLongID());
}
Also used : PreCalendar(com.cloudcraftgaming.discal.api.object.calendar.PreCalendar) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 9 with IMessage

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

the class CalendarCreator method edit.

@SuppressWarnings("SameParameterValue")
public PreCalendar edit(MessageReceivedEvent event, GuildSettings settings, boolean handleCreatorMessage) {
    long guildId = event.getMessage().getGuild().getLongID();
    if (!hasPreCalendar(guildId)) {
        // TODO: Support multiple calendars
        CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);
        try {
            com.google.api.services.calendar.Calendar service;
            if (settings.useExternalCalendar()) {
                service = CalendarAuth.getCalendarService(settings);
            } else {
                service = CalendarAuth.getCalendarService();
            }
            Calendar calendar = service.calendars().get(data.getCalendarAddress()).execute();
            PreCalendar preCalendar = new PreCalendar(guildId, calendar);
            preCalendar.setEditing(true);
            preCalendar.setCalendarId(data.getCalendarAddress());
            if (handleCreatorMessage) {
                if (PermissionChecker.botHasMessageManagePerms(event)) {
                    IMessage msg = Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(preCalendar, settings), MessageManager.getMessage("Creator.Calendar.Edit.Init", settings), event);
                    preCalendar.setCreatorMessage(msg);
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), event);
                }
            }
            calendars.add(preCalendar);
            return preCalendar;
        } catch (Exception e) {
            Logger.getLogger().exception(event.getMessage().getAuthor(), "Failed to init calendar editor", e, this.getClass(), true);
            return null;
        }
    } else {
        return getPreCalendar(guildId);
    }
}
Also used : PreCalendar(com.cloudcraftgaming.discal.api.object.calendar.PreCalendar) CalendarData(com.cloudcraftgaming.discal.api.object.calendar.CalendarData) PreCalendar(com.cloudcraftgaming.discal.api.object.calendar.PreCalendar) Calendar(com.google.api.services.calendar.model.Calendar) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 10 with IMessage

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

the class EventCreator method edit.

public PreEvent edit(MessageReceivedEvent e, String eventId, GuildSettings settings, boolean handleMessage) {
    long guildId = e.getGuild().getLongID();
    if (!hasPreEvent(guildId)) {
        // TODO: Handle multiple calendars...
        try {
            String calId = DatabaseManager.getManager().getMainCalendar(guildId).getCalendarAddress();
            Calendar service;
            if (settings.useExternalCalendar()) {
                service = CalendarAuth.getCalendarService(settings);
            } else {
                service = CalendarAuth.getCalendarService();
            }
            Event calEvent = service.events().get(calId, eventId).execute();
            PreEvent event = new PreEvent(guildId, calEvent);
            event.setEditing(true);
            try {
                event.setTimeZone(service.calendars().get(calId).execute().getTimeZone());
            } catch (IOException e1) {
            // Failed to get tz, ignore safely.
            }
            if (handleMessage) {
                if (PermissionChecker.botHasMessageManagePerms(e)) {
                    IMessage message = Message.sendMessage(EventMessageFormatter.getPreEventEmbed(event, settings), MessageManager.getMessage("Creator.Event.Edit.Init", settings), e);
                    event.setCreatorMessage(message);
                    Message.deleteMessage(e);
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
                }
            }
            events.add(event);
            return event;
        } catch (Exception exc) {
        // Oops
        }
        return null;
    }
    return getPreEvent(guildId);
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent) Calendar(com.google.api.services.calendar.Calendar) IMessage(sx.blah.discord.handle.obj.IMessage) Event(com.google.api.services.calendar.model.Event) MessageReceivedEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent) PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

IMessage (sx.blah.discord.handle.obj.IMessage)46 IUser (sx.blah.discord.handle.obj.IUser)10 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 UserObject (com.github.vaerys.masterobjects.UserObject)4 ArrayList (java.util.ArrayList)4 DiscordException (sx.blah.discord.util.DiscordException)4 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)3 PreEvent (com.cloudcraftgaming.discal.api.object.event.PreEvent)3 CommandObject (com.github.vaerys.commands.CommandObject)3 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)3 GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 RateLimitException (sx.blah.discord.util.RateLimitException)3 PreCalendar (com.cloudcraftgaming.discal.api.object.calendar.PreCalendar)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2