discord4j.core.event.domain.message.MessageCreateEvent Java Examples
The following examples show how to use
discord4j.core.event.domain.message.MessageCreateEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CalendarCreator.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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(MessageCreateEvent e, String calendarName, GuildSettings settings, boolean handleCreatorMessage) { if (!hasPreCalendar(settings.getGuildID())) { PreCalendar calendar = new PreCalendar(settings.getGuildID(), calendarName); if (handleCreatorMessage) { if (PermissionChecker.botHasMessageManagePerms(e)) { Message msg = MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Calendar.Create.Init", settings), CalendarMessageFormatter.getPreCalendarEmbed(calendar, settings), e); calendar.setCreatorMessage(msg); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e); } } calendars.add(calendar); return calendar; } return getPreCalendar(settings.getGuildID()); }
Example #2
Source File: EventCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleCreate(String[] args, MessageCreateEvent event, CalendarData calendarData, GuildSettings settings) { if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) { if (EventCreator.getCreator().getPreEvent(settings.getGuildID()).getCreatorMessage() != null) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.AlreadyInit", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.AlreadyInit", settings), event); } } else { if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) { PreEvent e; if (args.length == 1) e = EventCreator.getCreator().init(event, settings, true); else e = EventCreator.getCreator().init(event, settings, GeneralUtils.getContent(args, 1), true); if (e.getCreatorMessage() == null) MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Create.Init", settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NoCalendar", settings), event); } } }
Example #3
Source File: BotSupport.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Mono<Void> onMessageCreate(MessageCreateEvent event) { Message message = event.getMessage(); return Mono.justOrEmpty(message.getContent()) .filter(content -> content.startsWith("!status ")) .map(content -> { String status = content.substring("!status ".length()); if (status.equalsIgnoreCase("online")) { return Presence.online(); } else if (status.equalsIgnoreCase("dnd")) { return Presence.doNotDisturb(); } else if (status.equalsIgnoreCase("idle")) { return Presence.idle(); } else if (status.equalsIgnoreCase("invisible")) { return Presence.invisible(); } else { throw new IllegalArgumentException("Invalid argument"); } }) .flatMap(presence -> event.getClient().updatePresence(presence)) .then(); }
Example #4
Source File: AnnouncementCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleEnable(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { if (AnnouncementCreator.getCreator().hasAnnouncement(settings.getGuildID())) { MessageManager.sendMessageAsync(MessageManager.getMessage("Announcement.Enable.Creator", settings), event); } else { String value = args[1]; if (!AnnouncementUtils.announcementExists(value, settings.getGuildID())) { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event); } else { Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value), settings.getGuildID()); a.setEnabled(!a.isEnabled()); DatabaseManager.getManager().updateAnnouncement(a); MessageManager.sendMessageAsync(MessageManager.getMessage("Announcement.Enable.Success", "%value%", a.isEnabled() + "", settings), event); } } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Announcement.Enable.Specify", settings), event); } }
Example #5
Source File: AnnouncementCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleUnsubscribeRewriteArgsOne(MessageCreateEvent event, GuildSettings settings) { Member user = event.getMember().get(); if (AnnouncementCreator.getCreator().hasAnnouncement(settings.getGuildID())) { Announcement a = AnnouncementCreator.getCreator().getAnnouncement(settings.getGuildID()); if (a.getSubscriberUserIds().contains(user.getId().asString())) { a.getSubscriberUserIds().remove(user.getId().asString()); if (a.getCreatorMessage() != null) { MessageManager.deleteMessage(a.getCreatorMessage()); MessageManager.deleteMessage(event); a.setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Self.Success", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Self.Success", settings), event); } } else { // Announcement does not contain user ID if (a.getCreatorMessage() != null) { MessageManager.deleteMessage(a.getCreatorMessage()); MessageManager.deleteMessage(event); a.setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Self.Not", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Self.Not", settings), event); } } } else { // User not creating an announcement MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Unsubscribe.Self.Specify", settings), event); } }
Example #6
Source File: EventCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleSummary(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length > 1) { if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) { String content = GeneralUtils.getContent(args, 1); EventCreator.getCreator().getPreEvent(settings.getGuildID()).setSummary(content); if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Summary.Success.New", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Summary.Success", "%summary%", GeneralUtils.getContent(args, 1), settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event); } } else { if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Summary.Specify", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Summary.Specify", settings), event); } } }
Example #7
Source File: EventCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleRestart(String[] args, MessageCreateEvent event, CalendarData calendarData, GuildSettings settings) { Message msg = null; boolean editing = false; if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) editing = EventCreator.getCreator().getPreEvent(settings.getGuildID()).isEditing(); if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) msg = EventCreator.getCreator().getCreatorMessage(settings.getGuildID()); if (EventCreator.getCreator().terminate(settings.getGuildID())) { if (msg != null) { MessageManager.deleteMessage(msg); MessageManager.deleteMessage(event); } if (!editing) moduleCreate(args, event, calendarData, settings); else moduleEdit(args, event, calendarData, settings); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event); } }
Example #8
Source File: RsvpCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleUnsure(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { String eventId = args[1]; if (EventUtils.eventExists(settings, eventId)) { if (!TimeUtils.inPast(eventId, settings)) { RsvpData data = DatabaseManager.getManager().getRsvpData(settings.getGuildID(), eventId); data.removeCompletely(event.getMember().get().getId().asString()); data.getUndecided().add(event.getMember().get().getId().asString()); DatabaseManager.getManager().updateRsvpData(data); MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.unsure.success", settings), getRsvpEmbed(data, settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.InPast", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.NotExist", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.unsure.specify", settings), event); } }
Example #9
Source File: CalendarCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleCreate(String[] args, MessageCreateEvent event, CalendarData calendarData, GuildSettings settings) { if (CalendarCreator.getCreator().hasPreCalendar(settings.getGuildID())) { if (CalendarCreator.getCreator().getPreCalendar(settings.getGuildID()).getCreatorMessage() != null) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(settings.getGuildID())); CalendarCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Calendar.AlreadyInit", settings), CalendarMessageFormatter.getPreCalendarEmbed(CalendarCreator.getCreator().getPreCalendar(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.AlreadyInit", settings), event); } } else { if (calendarData.getCalendarId().equalsIgnoreCase("primary")) { if (args.length > 1) { String name = GeneralUtils.getContent(args, 1); PreCalendar calendar = CalendarCreator.getCreator().init(event, name, settings, true); if (calendar.getCreatorMessage() != null) MessageManager.deleteMessage(event); else MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.Create.Init", settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.Create.Name", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event); } } }
Example #10
Source File: BotSupport.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Mono<Void> onMessageCreate(MessageCreateEvent event) { Message message = event.getMessage(); String content = message.getContent(); if (content.startsWith("!members ")) { String guildId = content.substring("!members ".length()); return event.getClient().requestMembers(Snowflake.of(guildId)) .doOnNext(member -> log.info("{}", member)) .then(message.getRestChannel().createMessage( MessageCreateRequest.builder() .content("<@" + message.getUserData().id() + "> Done!") .build())) .then(); } return Mono.empty(); }
Example #11
Source File: LinkCalendarCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
/** * Issues the command this Object is responsible for. * * @param args The command arguments. * @param event The event received. * @return <code>true</code> if successful, else <code>false</code>. */ @Override public boolean issueCommand(String[] args, MessageCreateEvent event, GuildSettings settings) { try { //TODO: Handle multiple calendars... CalendarData data = DatabaseManager.getManager().getMainCalendar(event.getGuild().block().getId()); if (data.getCalendarAddress().equalsIgnoreCase("primary")) { //Does not have a calendar. MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event); } else { Calendar cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute(); MessageManager.sendMessageAsync(CalendarMessageFormatter.getCalendarLinkEmbed(cal, settings), event); } } catch (Exception e) { Logger.getLogger().exception(event.getMember().get(), "Failed to connect to Google Cal.", e, true, this.getClass()); MessageManager.sendMessageAsync(MessageManager.getMessage("Notification.Error.Unknown", settings), event); } return false; }
Example #12
Source File: RsvpCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleGoing(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { String eventId = args[1]; if (EventUtils.eventExists(settings, eventId)) { if (!TimeUtils.inPast(eventId, settings)) { RsvpData data = DatabaseManager.getManager().getRsvpData(settings.getGuildID(), eventId); data.removeCompletely(event.getMember().get().getId().asString()); data.getGoingOnTime().add(event.getMember().get().getId().asString()); DatabaseManager.getManager().updateRsvpData(data); MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.going.success", settings), getRsvpEmbed(data, settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.InPast", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.NotExist", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.going.specify", settings), event); } }
Example #13
Source File: DevCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void blockAPIKey(String[] args, MessageCreateEvent event) { if (args.length == 2) { MessageManager.sendMessageAsync("Blocking API key...", event); String key = args[1]; UserAPIAccount account = DatabaseManager.getManager().getAPIAccount(key); account.setBlocked(true); if (DatabaseManager.getManager().updateAPIAccount(account)) MessageManager.sendMessageAsync("Successfully blocked API key!", event); else MessageManager.sendMessageAsync("Error occurred! Could not block API key!", event); } else { MessageManager.sendMessageAsync("Please specify the API KEY!", event); } }
Example #14
Source File: RsvpCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleRemove(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { String eventId = args[1]; if (EventUtils.eventExists(settings, eventId)) { if (!TimeUtils.inPast(eventId, settings)) { RsvpData data = DatabaseManager.getManager().getRsvpData(settings.getGuildID(), eventId); data.removeCompletely(event.getMember().get().getId().asString()); DatabaseManager.getManager().updateRsvpData(data); MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.remove.success", settings), getRsvpEmbed(data, settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.InPast", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.NotExist", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.remove.specify", settings), event); } }
Example #15
Source File: Main.java From lavaplayer with Apache License 2.0 | 6 votes |
private void onMessageReceived(MessageCreateEvent event) { Message message = event.getMessage(); message.getContent().ifPresent(it -> { MessageChannel channel = message.getChannel().block(); if (channel instanceof TextChannel) { String[] command = it.split(" ", 2); if ("~play".equals(command[0]) && command.length == 2) { loadAndPlay((TextChannel) channel, command[1]); } else if ("~skip".equals(command[0])) { skipTrack((TextChannel) channel); } } }); }
Example #16
Source File: EventCreator.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
/** * Initiates the EventCreator for a specific guild. * * @param e The event received upon initialization. * @return The PreEvent for the guild. */ public PreEvent init(MessageCreateEvent e, GuildSettings settings, boolean handleMessage) { if (!hasPreEvent(settings.getGuildID())) { PreEvent event = new PreEvent(settings.getGuildID()); try { //TODO: Handle multiple calendars... String calId = DatabaseManager.getManager().getMainCalendar(settings.getGuildID()).getCalendarAddress(); event.setTimeZone(CalendarAuth.getCalendarService(settings).calendars().get(calId).execute().getTimeZone()); } catch (Exception exc) { //Failed to get timezone, ignore safely. } if (handleMessage) { if (PermissionChecker.botHasMessageManagePerms(e)) { Message message = MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Create.Init", settings), EventMessageFormatter.getPreEventEmbed(event, settings), e); event.setCreatorMessage(message); MessageManager.deleteMessage(e); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e); } } events.add(event); return event; } return getPreEvent(settings.getGuildID()); }
Example #17
Source File: DevCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleLeaveGuild(String[] args, MessageCreateEvent event) { if (args.length == 2) { try { Long.valueOf(args[1]); } catch (NumberFormatException ignore) { MessageManager.sendMessageAsync("Specified ID is not a valid LONG", event); return; } //Check if its on this shard... Guild g = DisCalClient.getClient().getGuildById(Snowflake.of(args[1])).block(); if (g != null) { g.leave().subscribe(); MessageManager.sendMessageAsync("Guild connected to this shard has been left!", event); return; } //Just send this across the network with Pub/Sub... and let the changes propagate JSONObject request = new JSONObject(); request.put("Reason", PubSubReason.HANDLE.name()); request.put("Realm", DisCalRealm.GUILD_LEAVE); request.put("Guild-Id", args[1]); PubSubManager.get().publish(BotSettings.PUBSUB_PREFIX.get() + "/ToClient/All", DisCalClient.clientId(), request); MessageManager.sendMessageAsync("DisCal will leave the specified guild (if connected). Please allow some time for this to propagate across the network!", event); } else { MessageManager.sendMessageAsync("Please specify the ID of the guild to leave with `!dev leave <ID>`", event); } }
Example #18
Source File: RoleUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public static Role getRoleFromID(String id, MessageCreateEvent event) { for (Role r : event.getMessage().getGuild().block().getRoles().toIterable()) { if (id.equals(r.getId().asString()) || id.equals(r.getName())) return r; } return null; }
Example #19
Source File: AnnouncementCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleMinutes(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { String value = args[1]; if (AnnouncementCreator.getCreator().hasAnnouncement(settings.getGuildID())) { try { int minutesOr = Integer.valueOf(value); int minutes = Math.abs(minutesOr); AnnouncementCreator.getCreator().getAnnouncement(settings.getGuildID()).setMinutesBefore(minutes); if (AnnouncementCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(settings.getGuildID())); MessageManager.deleteMessage(event); AnnouncementCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Announcement.Minutes.Success.New", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Minutes.Success", "%minutes%", minutes + "", settings), event); } } catch (NumberFormatException e) { if (AnnouncementCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(settings.getGuildID())); MessageManager.deleteMessage(event); AnnouncementCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Announcement.Minutes.NotInt", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Minutes.NotInt", settings), event); } } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.NotInit", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Minutes.Specify", settings), event); } }
Example #20
Source File: Context.java From Shadbot with GNU General Public License v3.0 | 5 votes |
public Context(MessageCreateEvent event, String prefix) { this.event = event; this.prefix = prefix; final List<String> splittedMsg = StringUtils.split(this.getContent(), 2); this.cmdName = splittedMsg.get(0).substring(prefix.length()).toLowerCase(); this.arg = splittedMsg.size() > 1 ? splittedMsg.get(1).trim() : null; }
Example #21
Source File: RsvpCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleList(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { String eventId = args[1]; if (EventUtils.eventExists(settings, eventId)) { RsvpData data = DatabaseManager.getManager().getRsvpData(settings.getGuildID(), eventId); MessageManager.sendMessageAsync(getRsvpEmbed(data, settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notifications.Event.NoExist", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("RSVP.list.specify", settings), event); } }
Example #22
Source File: CalendarCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleCancel(MessageCreateEvent event, CalendarData calendarData, GuildSettings settings) { if (CalendarCreator.getCreator().hasPreCalendar(settings.getGuildID())) { Message message = CalendarCreator.getCreator().getPreCalendar(settings.getGuildID()).getCreatorMessage(); boolean editing = CalendarCreator.getCreator().getPreCalendar(settings.getGuildID()).isEditing(); if (CalendarCreator.getCreator().terminate(settings.getGuildID())) { if (message != null) { if (!editing) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(settings.getGuildID())); } else { MessageManager.deleteMessage(event); MessageManager.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(settings.getGuildID())); CalendarCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Calendar.Cancel.Edit.Success", settings), event)); } } else { if (!editing) MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.Cancel.Success", settings), event); else MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.Cancel.Edit.Success", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.Cancel.Failure", settings), event); MessageManager.deleteMessage(event); } } else { if (calendarData.getCalendarId().equalsIgnoreCase("primary")) MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.NotInit", settings), event); else MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event); } }
Example #23
Source File: RoleUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean roleExists(String id, MessageCreateEvent event) { for (Role r : event.getMessage().getGuild().block().getRoles().toIterable()) { if (id.equals(r.getId().asString())) return true; } return false; }
Example #24
Source File: AnnouncementCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleEdit(String[] args, MessageCreateEvent event, GuildSettings settings) { if (!AnnouncementCreator.getCreator().hasAnnouncement(settings.getGuildID())) { if (args.length == 2) { String anId = args[1]; if (AnnouncementUtils.announcementExists(anId, settings.getGuildID())) { Announcement announcement = AnnouncementCreator.getCreator().edit(event, anId, settings); if (announcement.getCreatorMessage() == null) { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Edit.Init", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(announcement, settings), event); } else { MessageManager.deleteMessage(event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Edit.Specify", settings), event); } } else { if (AnnouncementCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(settings.getGuildID())); MessageManager.deleteMessage(event); AnnouncementCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Announcement.AlreadyInit", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.AlreadyInit", settings), event); } } }
Example #25
Source File: EventCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleCopy(String[] args, MessageCreateEvent event, CalendarData calendarData, GuildSettings settings) { if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) { if (!EventCreator.getCreator().hasPreEvent(settings.getGuildID())) { if (args.length == 2) { String eventId = args[1]; if (EventUtils.eventExists(settings, eventId)) { PreEvent preEvent = EventCreator.getCreator().init(event, eventId, settings, true); if (preEvent != null) { if (preEvent.getCreatorMessage() == null) { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Copy.Init", settings), EventMessageFormatter.getPreEventEmbed(preEvent, settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notification.Error.Unknown", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotFound", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Copy.Specify", settings), event); } } else { if (EventCreator.getCreator().getPreEvent(settings.getGuildID()).getCreatorMessage() != null) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.AlreadyInit", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.AlreadyInit", settings), event); } } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NoCalendar", settings), event); } }
Example #26
Source File: DisCalCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleBrand(MessageCreateEvent event, GuildSettings settings) { if (PermissionChecker.hasSufficientRole(event)) { if (settings.isPatronGuild()) { settings.setBranded(!settings.isBranded()); DatabaseManager.getManager().updateSettings(settings); MessageManager.sendMessageAsync(MessageManager.getMessage("DisCal.Brand", "%value%", settings.isBranded() + "", settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notification.Patron", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event); } }
Example #27
Source File: EventCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleAttachment(String[] args, MessageCreateEvent event, GuildSettings settings) { if (args.length == 2) { String value = args[1]; if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) { if (value.equalsIgnoreCase("delete") || value.equalsIgnoreCase("remove") || value.equalsIgnoreCase("clear")) { //Delete picture from event EventCreator.getCreator().getPreEvent(settings.getGuildID()).getEventData().setImageLink(null); if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Attachment.Delete", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Attachment.Delete", settings), event); } } else if (ImageUtils.validate(value, settings.isPatronGuild())) { EventCreator.getCreator().getPreEvent(settings.getGuildID()).getEventData().setImageLink(value); if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Attachment.Success", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Attachment.Success", settings), event); } } else { if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) { MessageManager.deleteMessage(event); MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID())); EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Attachment.Failure", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event)); } } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Attachment.Specify", settings), event); } }
Example #28
Source File: EventCreator.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public PreEvent init(MessageCreateEvent e, GuildSettings settings, String summary, boolean handleMessage) { if (!hasPreEvent(settings.getGuildID())) { PreEvent event = new PreEvent(settings.getGuildID()); event.setSummary(summary); try { //TODO: Handle multiple calendars... String calId = DatabaseManager.getManager().getMainCalendar(settings.getGuildID()).getCalendarAddress(); event.setTimeZone(CalendarAuth.getCalendarService(settings).calendars().get(calId).execute().getTimeZone()); } catch (Exception exc) { //Failed to get timezone, ignore safely. } if (handleMessage) { if (PermissionChecker.botHasMessageManagePerms(e)) { Message message = MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Create.Init", settings), EventMessageFormatter.getPreEventEmbed(event, settings), e); event.setCreatorMessage(message); MessageManager.deleteMessage(e); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e); } } events.add(event); return event; } return getPreEvent(settings.getGuildID()); }
Example #29
Source File: AnnouncementCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private void moduleCancel(MessageCreateEvent event, GuildSettings settings) { if (AnnouncementCreator.getCreator().hasAnnouncement(settings.getGuildID())) { Message creatorMessage = AnnouncementCreator.getCreator().getCreatorMessage(settings.getGuildID()); AnnouncementCreator.getCreator().terminate(settings.getGuildID()); if (creatorMessage != null) { MessageManager.deleteMessage(creatorMessage); MessageManager.deleteMessage(event); } MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.Cancel.Success", settings), event); } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Announcement.NotInit", settings), event); } }
Example #30
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks if the specified channel exists. * * @param nameOrId The channel name or ID. * @param event The event received. * @return <code>true</code> if exists, else <code>false</code>. */ public static boolean channelExists(String nameOrId, MessageCreateEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : event.getGuild().block().getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return true; } return false; }