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());
}
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;
}
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());
}
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);
}
}
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);
}
Aggregations