use of com.cloudcraftgaming.discal.api.object.calendar.PreCalendar in project DisCal-Discord-Bot by NovaFox161.
the class CreatorCleaner method run.
@Override
public void run() {
try {
// 60 minutes
long target = 60 * 1000 * 60;
ArrayList<PreCalendar> cals = new ArrayList<>();
ArrayList<PreEvent> events = new ArrayList<>();
ArrayList<Announcement> ans = new ArrayList<>();
// Run through calendar creator
for (PreCalendar cal : CalendarCreator.getCreator().getAllPreCalendars()) {
long difference = System.currentTimeMillis() - cal.getLastEdit();
if (difference <= target) {
// Last edited 60+ minutes ago, delete from creator and free up RAM.
cals.add(cal);
}
}
// Run through event creator
for (PreEvent event : EventCreator.getCreator().getAllPreEvents()) {
long difference = System.currentTimeMillis() - event.getLastEdit();
if (difference <= target) {
// Last edited 60+ minutes ago, delete from creator and free up RAM.
events.add(event);
}
}
// Run through announcement creator
for (Announcement an : AnnouncementCreator.getCreator().getAllAnnouncements()) {
long difference = System.currentTimeMillis() - an.getLastEdit();
if (difference <= target) {
// Last edited 60+ minutes ago, delete from creator and free up RAM.
ans.add(an);
}
}
// Okay, actually go through it all and delete
for (PreCalendar c : cals) {
CalendarCreator.getCreator().terminate(c.getGuildId());
}
for (PreEvent e : events) {
EventCreator.getCreator().terminate(e.getGuildId());
}
for (Announcement a : ans) {
AnnouncementCreator.getCreator().terminate(a.getGuildId());
}
} catch (Exception e) {
Logger.getLogger().exception(null, "Error in CreatorCleaner", e, this.getClass(), true);
}
}
use of com.cloudcraftgaming.discal.api.object.calendar.PreCalendar 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());
}
use of com.cloudcraftgaming.discal.api.object.calendar.PreCalendar 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);
}
}
use of com.cloudcraftgaming.discal.api.object.calendar.PreCalendar in project DisCal-Discord-Bot by NovaFox161.
the class CalendarCommand method moduleView.
private void moduleView(MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
if (CalendarCreator.getCreator().hasPreCalendar(guildId)) {
PreCalendar preCalendar = CalendarCreator.getCreator().getPreCalendar(guildId);
if (preCalendar.getCreatorMessage() != null) {
Message.deleteMessage(event);
Message.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(guildId));
CalendarCreator.getCreator().setCreatorMessage(Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(CalendarCreator.getCreator().getPreCalendar(guildId), settings), MessageManager.getMessage("Creator.Calendar.Review", settings), event));
} else {
Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(preCalendar, settings), MessageManager.getMessage("Creator.Calendar.Review", settings), event);
}
} else {
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
}
}
}
use of com.cloudcraftgaming.discal.api.object.calendar.PreCalendar in project DisCal-Discord-Bot by NovaFox161.
the class CalendarCommand method moduleEdit.
private void moduleEdit(MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
if (!CalendarCreator.getCreator().hasPreCalendar(guildId)) {
if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) {
PreCalendar calendar = CalendarCreator.getCreator().edit(event, settings, true);
if (calendar.getCreatorMessage() != null) {
Message.deleteMessage(event);
} else {
Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(calendar, settings), MessageManager.getMessage("Creator.Calendar.Edit.Init", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
}
} else {
if (CalendarCreator.getCreator().getPreCalendar(guildId).getCreatorMessage() != null) {
Message.deleteMessage(event);
Message.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(guildId));
CalendarCreator.getCreator().setCreatorMessage(Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(CalendarCreator.getCreator().getPreCalendar(guildId), settings), MessageManager.getMessage("Creator.Calendar.AlreadyInit", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.AlreadyInit", settings), event);
}
}
}
Aggregations