mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-02-11 05:58:26 -06:00
Further code cleanups!!!!
This commit is contained in:
@@ -96,9 +96,9 @@ public class CalendarAuth {
|
||||
}
|
||||
|
||||
private static Credential authorize(GuildSettings g) throws Exception {
|
||||
if (g.getEncryptedAccessToken().equalsIgnoreCase("N/a")) {
|
||||
if (g.getEncryptedAccessToken().equalsIgnoreCase("N/a"))
|
||||
throw new IllegalAccessException("Guild does not have proper access token!");
|
||||
}
|
||||
|
||||
|
||||
AESEncryption encryption = new AESEncryption(g);
|
||||
String accessToken = Authorization.getAuth().requestNewAccessToken(g, encryption);
|
||||
|
||||
@@ -22,9 +22,9 @@ public class KeyGenerator {
|
||||
|
||||
for (int i = 0; i < numChars; ++i) {
|
||||
// reseed rand once you've used up all available entropy bits
|
||||
if ((i % 10) == 0) {
|
||||
if ((i % 10) == 0)
|
||||
rand.setSeed(secRand.nextLong()); // 64 bits of random!
|
||||
}
|
||||
|
||||
buff[i] = VALID_CHARACTERS[rand.nextInt(VALID_CHARACTERS.length)];
|
||||
}
|
||||
return new String(buff);
|
||||
@@ -37,9 +37,9 @@ public class KeyGenerator {
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
// reseed rand once you've used up all available entropy bits
|
||||
if ((i % 10) == 0) {
|
||||
if ((i % 10) == 0)
|
||||
rand.setSeed(secRand.nextLong()); // 64 bits of random!
|
||||
}
|
||||
|
||||
buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
|
||||
}
|
||||
return "e" + new String(buff);
|
||||
@@ -52,9 +52,9 @@ public class KeyGenerator {
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
// reseed rand once you've used up all available entropy bits
|
||||
if ((i % 10) == 0) {
|
||||
if ((i % 10) == 0)
|
||||
rand.setSeed(secRand.nextLong()); // 64 bits of random!
|
||||
}
|
||||
|
||||
buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
|
||||
}
|
||||
return "a" + new String(buff);
|
||||
|
||||
@@ -56,9 +56,9 @@ public abstract class Database {
|
||||
* @throws SQLException if the connection cannot be closed
|
||||
*/
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (connection == null) {
|
||||
if (connection == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
connection.close();
|
||||
return true;
|
||||
}
|
||||
@@ -74,9 +74,9 @@ public abstract class Database {
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (!checkConnection()) {
|
||||
if (!checkConnection())
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
return statement.executeQuery(query);
|
||||
@@ -93,9 +93,9 @@ public abstract class Database {
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (!checkConnection()) {
|
||||
if (!checkConnection())
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
return statement.executeUpdate(query);
|
||||
|
||||
@@ -35,9 +35,9 @@ public class DatabaseManager {
|
||||
* @return The instance of the {@link DatabaseManager}
|
||||
*/
|
||||
public static DatabaseManager getManager() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new DatabaseManager();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -217,9 +217,9 @@ public class DatabaseManager {
|
||||
}
|
||||
|
||||
public boolean updateSettings(GuildSettings settings) {
|
||||
if (settings.getPrivateKey().equalsIgnoreCase("N/a")) {
|
||||
if (settings.getPrivateKey().equalsIgnoreCase("N/a"))
|
||||
settings.setPrivateKey(KeyGenerator.csRandomAlphaNumericString(16));
|
||||
}
|
||||
|
||||
try {
|
||||
if (databaseInfo.getMySQL().checkConnection()) {
|
||||
String dataTableName = String.format("%sguild_settings", databaseInfo.getPrefix());
|
||||
@@ -684,7 +684,7 @@ public class DatabaseManager {
|
||||
return calData;
|
||||
}
|
||||
|
||||
public CalendarData getCalendar(long guildId, Integer calendarNumber) {
|
||||
public CalendarData getCalendar(long guildId, int calendarNumber) {
|
||||
CalendarData calData = new CalendarData(guildId, calendarNumber);
|
||||
try {
|
||||
if (databaseInfo.getMySQL().checkConnection()) {
|
||||
@@ -759,7 +759,7 @@ public class DatabaseManager {
|
||||
return calendars;
|
||||
}
|
||||
|
||||
public Integer getCalendarCount() {
|
||||
public int getCalendarCount() {
|
||||
int amount = -1;
|
||||
try {
|
||||
if (databaseInfo.getMySQL().checkConnection()) {
|
||||
@@ -769,11 +769,11 @@ public class DatabaseManager {
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
if (res.next()) {
|
||||
if (res.next())
|
||||
amount = res.getInt(1);
|
||||
} else {
|
||||
else
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
|
||||
res.close();
|
||||
statement.close();
|
||||
@@ -787,9 +787,9 @@ public class DatabaseManager {
|
||||
public EventData getEventData(long guildId, String eventId) {
|
||||
EventData data = new EventData(guildId);
|
||||
|
||||
if (eventId.contains("_")) {
|
||||
if (eventId.contains("_"))
|
||||
eventId = eventId.split("_")[0];
|
||||
}
|
||||
|
||||
|
||||
data.setEventId(eventId);
|
||||
|
||||
@@ -1153,11 +1153,10 @@ public class DatabaseManager {
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
if (res.next()) {
|
||||
if (res.next())
|
||||
amount = res.getInt(1);
|
||||
} else {
|
||||
else
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
res.close();
|
||||
statement.close();
|
||||
@@ -1220,10 +1219,9 @@ public class DatabaseManager {
|
||||
String eventTable = String.format("%sevents", databaseInfo.getPrefix());
|
||||
|
||||
//Check if recurring...
|
||||
if (eventId.contains("_")) {
|
||||
//Don't delete if child event of recurring event.
|
||||
return false;
|
||||
}
|
||||
if (eventId.contains("_"))
|
||||
return false; //Don't delete if child event of recurring event.
|
||||
|
||||
|
||||
String query = "DELETE FROM " + eventTable + " WHERE EVENT_ID = ?";
|
||||
PreparedStatement preparedStmt = databaseInfo.getConnection().prepareStatement(query);
|
||||
|
||||
@@ -26,8 +26,7 @@ public class MySQL extends Database {
|
||||
* @param username Username
|
||||
* @param password Password
|
||||
*/
|
||||
public MySQL(String hostname, String port, String prefix, String username,
|
||||
String password) {
|
||||
public MySQL(String hostname, String port, String prefix, String username, String password) {
|
||||
this(hostname, port, null, prefix, username, password);
|
||||
}
|
||||
|
||||
@@ -50,20 +49,17 @@ public class MySQL extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException,
|
||||
ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection())
|
||||
return connection;
|
||||
}
|
||||
String connectionURL = "jdbc:mysql://"
|
||||
+ this.hostname + ":" + this.port;
|
||||
if (database != null) {
|
||||
|
||||
String connectionURL = "jdbc:mysql://" + this.hostname + ":" + this.port;
|
||||
if (database != null)
|
||||
connectionURL = connectionURL + "/" + this.database + "?autoReconnect=true&useSSL=false";
|
||||
}
|
||||
|
||||
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
connection = DriverManager.getConnection(connectionURL,
|
||||
this.user, this.password);
|
||||
connection = DriverManager.getConnection(connectionURL, this.user, this.password);
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,14 +26,14 @@ public class SQLite extends Database {
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
if (checkConnection())
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
File dataFolder = new File("sqlite-db/");
|
||||
if (!dataFolder.exists()) {
|
||||
if (!dataFolder.exists())
|
||||
dataFolder.mkdirs();
|
||||
}
|
||||
|
||||
|
||||
File file = new File(dataFolder, dbLocation);
|
||||
if (!(file.exists())) {
|
||||
@@ -44,10 +44,7 @@ public class SQLite extends Database {
|
||||
}
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
connection = DriverManager
|
||||
.getConnection("jdbc:sqlite:"
|
||||
+ dataFolder + "/"
|
||||
+ dbLocation);
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder + "/" + dbLocation);
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public enum EventColor {
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -39,15 +39,15 @@ public enum EventColor {
|
||||
return hex;
|
||||
}
|
||||
|
||||
public Integer getR() {
|
||||
public int getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public Integer getG() {
|
||||
public int getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public Integer getB() {
|
||||
public int getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -58,10 +58,9 @@ public enum EventColor {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
Integer i = Integer.valueOf(nameOrHexOrId);
|
||||
if (c.getId().equals(i)) {
|
||||
int i = Integer.valueOf(nameOrHexOrId);
|
||||
if (c.getId() == i)
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
//Not number, just ignore.
|
||||
}
|
||||
@@ -72,9 +71,8 @@ public enum EventColor {
|
||||
|
||||
public static boolean exists(Integer id) {
|
||||
for (EventColor c : values()) {
|
||||
if (c.getId().equals(id)) {
|
||||
if (c.getId() == id)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -85,10 +83,9 @@ public enum EventColor {
|
||||
return c;
|
||||
} else {
|
||||
try {
|
||||
Integer i = Integer.valueOf(nameOrHexOrID);
|
||||
if (c.getId().equals(i)) {
|
||||
int i = Integer.valueOf(nameOrHexOrID);
|
||||
if (c.getId() == i)
|
||||
return c;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
//Not number, just ignore.
|
||||
}
|
||||
@@ -99,9 +96,8 @@ public enum EventColor {
|
||||
|
||||
public static EventColor fromId(Integer id) {
|
||||
for (EventColor c : values()) {
|
||||
if (c.getId().equals(id)) {
|
||||
if (c.getId() == id)
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import sx.blah.discord.util.RequestBuffer;
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public class Message {
|
||||
/**
|
||||
* Sends a message via Discord as DisCal.
|
||||
@@ -173,9 +174,9 @@ public class Message {
|
||||
try {
|
||||
return RequestBuffer.request(() -> {
|
||||
try {
|
||||
if (!event.getMessage().isDeleted()) {
|
||||
if (!event.getMessage().isDeleted())
|
||||
event.getMessage().delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (DiscordException | MissingPermissionsException e) {
|
||||
//Failed to delete
|
||||
@@ -191,9 +192,9 @@ public class Message {
|
||||
try {
|
||||
return RequestBuffer.request(() -> {
|
||||
try {
|
||||
if (!message.isDeleted()) {
|
||||
if (!message.isDeleted())
|
||||
message.delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (DiscordException | MissingPermissionsException e) {
|
||||
//Failed to delete.
|
||||
@@ -209,9 +210,9 @@ public class Message {
|
||||
try {
|
||||
return RequestBuffer.request(() -> {
|
||||
try {
|
||||
if (message != null && !message.isDeleted()) {
|
||||
if (message != null && !message.isDeleted())
|
||||
message.edit(content);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (DiscordException | MissingPermissionsException e) {
|
||||
//Failed to edit.
|
||||
@@ -227,9 +228,9 @@ public class Message {
|
||||
try {
|
||||
return RequestBuffer.request(() -> {
|
||||
try {
|
||||
if (!message.isDeleted()) {
|
||||
if (!message.isDeleted())
|
||||
message.edit(content, embed);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (DiscordException | MissingPermissionsException e) {
|
||||
//Failed to edit.
|
||||
|
||||
@@ -39,18 +39,18 @@ public class MessageManager {
|
||||
|
||||
public static boolean isSupported(String _value) {
|
||||
for (String l : langs.keySet()) {
|
||||
if (l.equalsIgnoreCase(_value)) {
|
||||
if (l.equalsIgnoreCase(_value))
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getValidLang(String _value) {
|
||||
for (String l : langs.keySet()) {
|
||||
if (l.equalsIgnoreCase(_value)) {
|
||||
if (l.equalsIgnoreCase(_value))
|
||||
return l;
|
||||
}
|
||||
|
||||
}
|
||||
return "ENGLISH";
|
||||
}
|
||||
@@ -59,11 +59,11 @@ public class MessageManager {
|
||||
public static String getMessage(String key, GuildSettings settings) {
|
||||
Map<String, String> messages;
|
||||
|
||||
if (settings.getLang() != null && langs.containsKey(settings.getLang())) {
|
||||
if (settings.getLang() != null && langs.containsKey(settings.getLang()))
|
||||
messages = langs.get(settings.getLang());
|
||||
} else {
|
||||
else
|
||||
messages = langs.get("ENGLISH");
|
||||
}
|
||||
|
||||
|
||||
return messages.getOrDefault(key, "***FAILSAFE MESSAGE*** MESSAGE NOT FOUND!! Message requested: " + key).replace("%lb%", MessageUtils.lineBreak);
|
||||
}
|
||||
@@ -71,11 +71,11 @@ public class MessageManager {
|
||||
public static String getMessage(String key, String var, String replace, GuildSettings settings) {
|
||||
Map<String, String> messages;
|
||||
|
||||
if (settings.getLang() != null && langs.containsKey(settings.getLang())) {
|
||||
if (settings.getLang() != null && langs.containsKey(settings.getLang()))
|
||||
messages = langs.get(settings.getLang());
|
||||
} else {
|
||||
else
|
||||
messages = langs.get("ENGLISH");
|
||||
}
|
||||
|
||||
return messages.getOrDefault(key, "***FAILSAFE MESSAGE*** MESSAGE NOT FOUND!! Message requested: " + key).replace(var, replace).replace("%lb%", MessageUtils.lineBreak);
|
||||
}
|
||||
}
|
||||
@@ -49,24 +49,24 @@ public class CalendarMessageFormatter {
|
||||
em.withAuthorIcon(DisCalAPI.getAPI().iconUrl);
|
||||
em.withAuthorName("DisCal");
|
||||
em.withTitle(MessageManager.getMessage("Embed.Calendar.Pre.Title", settings));
|
||||
if (calendar.getSummary() != null) {
|
||||
if (calendar.getSummary() != null)
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Summary", settings), calendar.getSummary(), true);
|
||||
} else {
|
||||
else
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Summary", settings), "***UNSET***", true);
|
||||
}
|
||||
if (calendar.getDescription() != null) {
|
||||
|
||||
if (calendar.getDescription() != null)
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Description", settings), calendar.getDescription(), false);
|
||||
} else {
|
||||
else
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Description", settings), "***UNSET***", false);
|
||||
}
|
||||
if (calendar.getTimezone() != null) {
|
||||
|
||||
if (calendar.getTimezone() != null)
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.TimeZone", settings), calendar.getTimezone(), true);
|
||||
} else {
|
||||
else
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.TimeZone", settings), "***UNSET***", true);
|
||||
}
|
||||
if (calendar.isEditing()) {
|
||||
|
||||
if (calendar.isEditing())
|
||||
em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.CalendarId", settings), calendar.getCalendarId(), false);
|
||||
} //No else needed, just don't post it.
|
||||
|
||||
|
||||
em.withFooterText(MessageManager.getMessage("Embed.Calendar.Pre.Key", settings));
|
||||
em.withColor(56, 138, 237);
|
||||
|
||||
@@ -45,9 +45,9 @@ public class Authorization {
|
||||
} //Prevent initialization.
|
||||
|
||||
public static Authorization getAuth() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new Authorization();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ public class PollManager {
|
||||
}
|
||||
|
||||
public static PollManager getManager() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new PollManager();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public enum BotSettings {
|
||||
return val;
|
||||
}
|
||||
|
||||
public void set(String val) {
|
||||
this.val = val;
|
||||
public void set(String _val) {
|
||||
val = _val;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class GuildSettings {
|
||||
|
||||
private boolean patronGuild;
|
||||
private boolean devGuild;
|
||||
private Integer maxCalendars;
|
||||
private int maxCalendars;
|
||||
|
||||
private boolean twelveHour;
|
||||
private boolean branded;
|
||||
@@ -105,7 +105,7 @@ public class GuildSettings {
|
||||
return devGuild;
|
||||
}
|
||||
|
||||
public Integer getMaxCalendars() {
|
||||
public int getMaxCalendars() {
|
||||
return maxCalendars;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class GuildSettings {
|
||||
|
||||
public String getDmAnnouncementsString() {
|
||||
StringBuilder users = new StringBuilder();
|
||||
Integer i = 0;
|
||||
int i = 0;
|
||||
for (String sub : dmAnnouncements) {
|
||||
if (i == 0) {
|
||||
users = new StringBuilder(sub);
|
||||
|
||||
@@ -331,7 +331,7 @@ public class Announcement {
|
||||
*
|
||||
* @param _minutesBefore The minutes before the event to announce for.
|
||||
*/
|
||||
public void setMinutesBefore(Integer _minutesBefore) {
|
||||
public void setMinutesBefore(int _minutesBefore) {
|
||||
minutesBefore = _minutesBefore;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ package com.cloudcraftgaming.discal.api.object.announcement;
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
public class AnnouncementCreatorResponse {
|
||||
private final Boolean successful;
|
||||
private final boolean successful;
|
||||
|
||||
private Announcement announcement;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class AnnouncementCreatorResponse {
|
||||
*
|
||||
* @param _successful Whether or not the creator was successful.
|
||||
*/
|
||||
public AnnouncementCreatorResponse(Boolean _successful) {
|
||||
public AnnouncementCreatorResponse(boolean _successful) {
|
||||
successful = _successful;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class AnnouncementCreatorResponse {
|
||||
* @param _successful Whether or not the creator was successful.
|
||||
* @param _announcement The announcement involved.
|
||||
*/
|
||||
public AnnouncementCreatorResponse(Boolean _successful, Announcement _announcement) {
|
||||
public AnnouncementCreatorResponse(boolean _successful, Announcement _announcement) {
|
||||
successful = _successful;
|
||||
announcement = _announcement;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class AnnouncementCreatorResponse {
|
||||
*
|
||||
* @return Whether or not the creator was successful.
|
||||
*/
|
||||
public Boolean isSuccessful() {
|
||||
public boolean isSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import sx.blah.discord.handle.obj.IMessage;
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
public class CalendarCreatorResponse {
|
||||
private final Boolean successful;
|
||||
private final boolean successful;
|
||||
|
||||
private boolean edited;
|
||||
private IMessage creatorMessage;
|
||||
@@ -20,7 +20,7 @@ public class CalendarCreatorResponse {
|
||||
*
|
||||
* @param _successful Whether or not the creation was successful.
|
||||
*/
|
||||
public CalendarCreatorResponse(Boolean _successful) {
|
||||
public CalendarCreatorResponse(boolean _successful) {
|
||||
successful = _successful;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class CalendarCreatorResponse {
|
||||
* @param _successful Whether or not the creation was successful.
|
||||
* @param _calendar The calendar created.
|
||||
*/
|
||||
public CalendarCreatorResponse(Boolean _successful, Calendar _calendar) {
|
||||
public CalendarCreatorResponse(boolean _successful, Calendar _calendar) {
|
||||
successful = _successful;
|
||||
calendar = _calendar;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class CalendarCreatorResponse {
|
||||
*
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
public Boolean isSuccessful() {
|
||||
public boolean isSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ package com.cloudcraftgaming.discal.api.object.calendar;
|
||||
*/
|
||||
public class CalendarData {
|
||||
private final long guildId;
|
||||
private final Integer calendarNumber;
|
||||
private final int calendarNumber;
|
||||
|
||||
private String calendarId;
|
||||
private String calendarAddress;
|
||||
|
||||
private boolean external;
|
||||
|
||||
public CalendarData(long _guildID, Integer _calendarNumber) {
|
||||
public CalendarData(long _guildID, int _calendarNumber) {
|
||||
guildId = _guildID;
|
||||
calendarNumber = _calendarNumber;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CalendarData {
|
||||
return guildId;
|
||||
}
|
||||
|
||||
public Integer getCalendarNumber() {
|
||||
public int getCalendarNumber() {
|
||||
return calendarNumber;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,12 +41,12 @@ public class PreCalendar {
|
||||
guildId = _guildId;
|
||||
summary = calendar.getSummary();
|
||||
|
||||
if (calendar.getDescription() != null) {
|
||||
if (calendar.getDescription() != null)
|
||||
description = calendar.getDescription();
|
||||
}
|
||||
if (calendar.getTimeZone() != null) {
|
||||
|
||||
if (calendar.getTimeZone() != null)
|
||||
timezone = calendar.getTimeZone();
|
||||
}
|
||||
|
||||
|
||||
editing = false;
|
||||
|
||||
@@ -159,7 +159,7 @@ public class PreCalendar {
|
||||
*
|
||||
* @return <code>true</code> if required data set, otherwise <code>false</code>.
|
||||
*/
|
||||
public Boolean hasRequiredValues() {
|
||||
public boolean hasRequiredValues() {
|
||||
return summary != null && timezone != null;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import sx.blah.discord.handle.obj.IMessage;
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
public class EventCreatorResponse {
|
||||
private final Boolean successful;
|
||||
private final boolean successful;
|
||||
|
||||
private IMessage creatorMessage;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class EventCreatorResponse {
|
||||
*
|
||||
* @param _successful Whether or not the Creator was successful.
|
||||
*/
|
||||
public EventCreatorResponse(Boolean _successful) {
|
||||
public EventCreatorResponse(boolean _successful) {
|
||||
successful = _successful;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class EventCreatorResponse {
|
||||
* @param _successful Whether or not the Creator was successful.
|
||||
* @param _event The Event that was created.
|
||||
*/
|
||||
public EventCreatorResponse(Boolean _successful, Event _event) {
|
||||
public EventCreatorResponse(boolean _successful, Event _event) {
|
||||
successful = _successful;
|
||||
event = _event;
|
||||
edited = false;
|
||||
@@ -44,7 +44,7 @@ public class EventCreatorResponse {
|
||||
*
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
public Boolean isSuccessful() {
|
||||
public boolean isSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,15 +83,15 @@ public class PreEvent {
|
||||
recurrence.fromRRule(e.getRecurrence().get(0));
|
||||
}
|
||||
|
||||
if (e.getSummary() != null) {
|
||||
if (e.getSummary() != null)
|
||||
summary = e.getSummary();
|
||||
}
|
||||
if (e.getDescription() != null) {
|
||||
|
||||
if (e.getDescription() != null)
|
||||
description = e.getDescription();
|
||||
}
|
||||
if (e.getLocation() != null) {
|
||||
|
||||
if (e.getLocation() != null)
|
||||
location = e.getLocation();
|
||||
}
|
||||
|
||||
|
||||
startDateTime = e.getStart();
|
||||
endDateTime = e.getEnd();
|
||||
@@ -367,7 +367,7 @@ public class PreEvent {
|
||||
*
|
||||
* @return <code>true</code> if required values set, otherwise <code>false</code>.
|
||||
*/
|
||||
public Boolean hasRequiredValues() {
|
||||
public boolean hasRequiredValues() {
|
||||
return startDateTime != null && endDateTime != null;
|
||||
}
|
||||
}
|
||||
@@ -56,12 +56,10 @@ public class Recurrence {
|
||||
*/
|
||||
public String toRRule() {
|
||||
String rrule = "RRULE:FREQ=" + frequency.name() + ";INTERVAL=" + interval;
|
||||
if (count < 1) {
|
||||
//Infinite
|
||||
return rrule;
|
||||
} else {
|
||||
if (count < 1)
|
||||
return rrule; //Infinite
|
||||
else
|
||||
return rrule + ";COUNT=" + count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,13 +68,11 @@ public class Recurrence {
|
||||
* @return Human readable string of the settings.
|
||||
*/
|
||||
public String toHumanReadable() {
|
||||
String humanRead = "Frequency: " + frequency.name() + MessageUtils.lineBreak +
|
||||
"Interval: " + interval;
|
||||
if (count < 1) {
|
||||
String humanRead = "Frequency: " + frequency.name() + MessageUtils.lineBreak + "Interval: " + interval;
|
||||
if (count < 1)
|
||||
return humanRead + MessageUtils.lineBreak + "Amount: Infinite";
|
||||
} else {
|
||||
else
|
||||
return humanRead + MessageUtils.lineBreak + "Amount: " + count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,9 +113,9 @@ public class Recurrence {
|
||||
for (String c : contents) {
|
||||
if (c.contains("FREQ=")) {
|
||||
String freq = c.replaceAll("FREQ=", "");
|
||||
if (EventFrequency.isValid(freq)) {
|
||||
if (EventFrequency.isValid(freq))
|
||||
frequency = EventFrequency.fromValue(freq);
|
||||
}
|
||||
|
||||
} else if (c.contains("INTERVAL=")) {
|
||||
String inter = c.replaceAll("INTERVAL=", "");
|
||||
try {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RsvpData {
|
||||
|
||||
public String getGoingOnTimeString() {
|
||||
StringBuilder goingString = new StringBuilder();
|
||||
Integer i = 0;
|
||||
int i = 0;
|
||||
for (String u : goingOnTime) {
|
||||
if (i == 0) {
|
||||
goingString = new StringBuilder(u);
|
||||
@@ -68,7 +68,7 @@ public class RsvpData {
|
||||
|
||||
public String getGoingLateString() {
|
||||
StringBuilder goingString = new StringBuilder();
|
||||
Integer i = 0;
|
||||
int i = 0;
|
||||
for (String u : goingLate) {
|
||||
if (i == 0) {
|
||||
goingString = new StringBuilder(u);
|
||||
@@ -82,7 +82,7 @@ public class RsvpData {
|
||||
|
||||
public String getNotGoingString() {
|
||||
StringBuilder going = new StringBuilder();
|
||||
Integer i = 0;
|
||||
int i = 0;
|
||||
for (String u : notGoing) {
|
||||
if (i == 0) {
|
||||
going = new StringBuilder(u);
|
||||
@@ -96,7 +96,7 @@ public class RsvpData {
|
||||
|
||||
public String getUndecidedString() {
|
||||
StringBuilder going = new StringBuilder();
|
||||
Integer i = 0;
|
||||
int i = 0;
|
||||
for (String u : undecided) {
|
||||
if (i == 0) {
|
||||
going = new StringBuilder(u);
|
||||
|
||||
@@ -57,11 +57,11 @@ public class WebRole {
|
||||
|
||||
managed = r.isManaged();
|
||||
|
||||
if (r.isEveryoneRole() && settings.getControlRole().equalsIgnoreCase("everyone")) {
|
||||
if (r.isEveryoneRole() && settings.getControlRole().equalsIgnoreCase("everyone"))
|
||||
controlRole = true;
|
||||
} else {
|
||||
else
|
||||
controlRole = settings.getControlRole().equalsIgnoreCase(String.valueOf(id));
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ public class AnnouncementUtils {
|
||||
*/
|
||||
public static Boolean announcementExists(String value, MessageReceivedEvent event) {
|
||||
for (Announcement a : DatabaseManager.getManager().getAnnouncements(event.getGuild().getLongID())) {
|
||||
if (a.getAnnouncementId().toString().equals(value)) {
|
||||
if (a.getAnnouncementId().toString().equals(value))
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CalendarUtils {
|
||||
* @param data The BotData of the Guild whose deleting their calendar.
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
public static Boolean deleteCalendar(CalendarData data, GuildSettings settings) {
|
||||
public static boolean deleteCalendar(CalendarData data, GuildSettings settings) {
|
||||
try {
|
||||
//Only delete if the calendar is stored on DisCal's account.
|
||||
if (!data.getCalendarAddress().equalsIgnoreCase("primary") && !settings.useExternalCalendar()) {
|
||||
|
||||
@@ -62,11 +62,11 @@ public class EventUtils {
|
||||
pe.setSummary(event.getSummary());
|
||||
pe.setDescription(event.getDescription());
|
||||
pe.setLocation(event.getLocation());
|
||||
if (event.getColorId() != null) {
|
||||
if (event.getColorId() != null)
|
||||
pe.setColor(EventColor.fromNameOrHexOrID(event.getColorId()));
|
||||
} else {
|
||||
else
|
||||
pe.setColor(EventColor.RED);
|
||||
}
|
||||
|
||||
pe.setEventData(DatabaseManager.getManager().getEventData(guildId, event.getId()));
|
||||
|
||||
return pe;
|
||||
|
||||
@@ -37,9 +37,9 @@ public class PermissionChecker {
|
||||
|
||||
if (role != null) {
|
||||
for (IRole r : sender.getRolesForGuild(event.getMessage().getGuild())) {
|
||||
if (r.getStringID().equals(role.getStringID()) || r.getPosition() > role.getPosition()) {
|
||||
if (r.getStringID().equals(role.getStringID()) || r.getPosition() > role.getPosition())
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
@@ -74,9 +74,9 @@ public class PermissionChecker {
|
||||
|
||||
if (role != null) {
|
||||
for (IRole r : user.getRolesForGuild(guild)) {
|
||||
if (r.getStringID().equals(role.getStringID()) || r.getPosition() > role.getPosition()) {
|
||||
if (r.getStringID().equals(role.getStringID()) || r.getPosition() > role.getPosition())
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
@@ -95,8 +95,7 @@ public class PermissionChecker {
|
||||
}
|
||||
|
||||
public static boolean hasManageServerRole(MessageReceivedEvent event) {
|
||||
return event.getMessage().getAuthor().getPermissionsForGuild(event.getMessage().getGuild()).contains(
|
||||
Permissions.MANAGE_SERVER);
|
||||
return event.getMessage().getAuthor().getPermissionsForGuild(event.getMessage().getGuild()).contains(Permissions.MANAGE_SERVER);
|
||||
}
|
||||
|
||||
public static boolean hasManageServerRole(IGuild g, IUser u) {
|
||||
@@ -112,9 +111,9 @@ public class PermissionChecker {
|
||||
public static boolean isCorrectChannel(MessageReceivedEvent event) {
|
||||
try {
|
||||
GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuild().getLongID());
|
||||
if (settings.getDiscalChannel().equalsIgnoreCase("all")) {
|
||||
if (settings.getDiscalChannel().equalsIgnoreCase("all"))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
IChannel channel = null;
|
||||
for (IChannel c : event.getMessage().getGuild().getChannels()) {
|
||||
@@ -124,9 +123,9 @@ public class PermissionChecker {
|
||||
}
|
||||
}
|
||||
|
||||
if (channel != null) {
|
||||
if (channel != null)
|
||||
return event.getMessage().getChannel().getStringID().equals(channel.getStringID());
|
||||
}
|
||||
|
||||
|
||||
//If we got here, the channel no longer exists, reset data and return true.
|
||||
settings.setDiscalChannel("all");
|
||||
|
||||
@@ -42,11 +42,10 @@ public class TimeUtils {
|
||||
}
|
||||
|
||||
private static boolean inPast(Event event) {
|
||||
if (event.getStart().getDateTime() != null) {
|
||||
if (event.getStart().getDateTime() != null)
|
||||
return event.getStart().getDateTime().getValue() <= System.currentTimeMillis();
|
||||
} else {
|
||||
else
|
||||
return event.getStart().getDate().getValue() <= System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inPast(String eventId, GuildSettings settings) {
|
||||
|
||||
@@ -28,9 +28,8 @@ public class Logger {
|
||||
} //Prevent initialization
|
||||
|
||||
public static Logger getLogger() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new Logger();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -82,14 +81,14 @@ public class Logger {
|
||||
|
||||
if (post) {
|
||||
String shortError = error;
|
||||
if (error.length() > 1250) {
|
||||
if (error.length() > 1250)
|
||||
shortError = error.substring(0, 1250);
|
||||
}
|
||||
|
||||
|
||||
EmbedBuilder em = new EmbedBuilder();
|
||||
if (bot != null) {
|
||||
if (bot != null)
|
||||
em.withAuthorIcon(bot.getAvatarURL());
|
||||
}
|
||||
|
||||
if (author != null) {
|
||||
em.withAuthorName(author.getName());
|
||||
em.withThumbnail(author.getAvatarURL());
|
||||
@@ -100,15 +99,14 @@ public class Logger {
|
||||
//Send to discord!
|
||||
em.appendField("Time", timeStamp, true);
|
||||
if (e.getMessage() != null) {
|
||||
if (e.getMessage().length() > 1024) {
|
||||
if (e.getMessage().length() > 1024)
|
||||
em.appendField("Exception", e.getMessage().substring(0, 1024), true);
|
||||
} else {
|
||||
else
|
||||
em.appendField("Exception", e.getMessage(), true);
|
||||
}
|
||||
}
|
||||
if (message != null) {
|
||||
if (message != null)
|
||||
em.appendField("Message", message, true);
|
||||
}
|
||||
|
||||
|
||||
//Get DisCal guild and channel..
|
||||
IGuild guild = DisCalAPI.getAPI().getClient().getGuildByID(266063520112574464L);
|
||||
@@ -122,12 +120,12 @@ public class Logger {
|
||||
try {
|
||||
FileWriter exceptions = new FileWriter(exceptionsFile, true);
|
||||
exceptions.write("ERROR --- " + timeStamp + " ---" + MessageUtils.lineBreak);
|
||||
if (author != null) {
|
||||
if (author != null)
|
||||
exceptions.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
|
||||
}
|
||||
if (message != null) {
|
||||
|
||||
if (message != null)
|
||||
exceptions.write("message: " + message + MessageUtils.lineBreak);
|
||||
}
|
||||
|
||||
exceptions.write(error + MessageUtils.lineBreak);
|
||||
exceptions.close();
|
||||
} catch (IOException io) {
|
||||
@@ -153,9 +151,9 @@ public class Logger {
|
||||
|
||||
|
||||
em.appendField("Time", timeStamp, true);
|
||||
if (info != null) {
|
||||
if (info != null)
|
||||
em.appendField("Additional Info", info, true);
|
||||
}
|
||||
|
||||
|
||||
//Get DisCal guild and channel..
|
||||
IGuild guild = DisCalAPI.getAPI().getClient().getGuildByID(266063520112574464L);
|
||||
@@ -169,15 +167,15 @@ public class Logger {
|
||||
try {
|
||||
FileWriter file = new FileWriter(debugFile, true);
|
||||
file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
|
||||
if (author != null) {
|
||||
if (author != null)
|
||||
file.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
|
||||
}
|
||||
if (message != null) {
|
||||
|
||||
if (message != null)
|
||||
file.write("message: " + message + MessageUtils.lineBreak);
|
||||
}
|
||||
if (info != null) {
|
||||
|
||||
if (info != null)
|
||||
file.write("info: " + info + MessageUtils.lineBreak);
|
||||
}
|
||||
|
||||
file.close();
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
@@ -190,9 +188,9 @@ public class Logger {
|
||||
try {
|
||||
FileWriter file = new FileWriter(debugFile, true);
|
||||
file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
|
||||
if (message != null) {
|
||||
if (message != null)
|
||||
file.write("info: " + message + MessageUtils.lineBreak);
|
||||
}
|
||||
|
||||
file.close();
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
|
||||
@@ -37,9 +37,8 @@ public class CalendarCreator {
|
||||
* @return The instance of the CalendarCreator.
|
||||
*/
|
||||
public static CalendarCreator getCreator() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new CalendarCreator();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -223,9 +222,8 @@ public class CalendarCreator {
|
||||
}
|
||||
|
||||
public IMessage getCreatorMessage(long guildId) {
|
||||
if (hasPreCalendar(guildId)) {
|
||||
if (hasPreCalendar(guildId))
|
||||
return getPreCalendar(guildId).getCreatorMessage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -243,9 +241,8 @@ public class CalendarCreator {
|
||||
*/
|
||||
public Boolean hasPreCalendar(long guildId) {
|
||||
for (PreCalendar c : calendars) {
|
||||
if (c.getGuildId() == guildId) {
|
||||
if (c.getGuildId() == guildId)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -256,10 +253,7 @@ public class CalendarCreator {
|
||||
|
||||
//Setters
|
||||
public void setCreatorMessage(IMessage msg) {
|
||||
if (msg != null) {
|
||||
if (hasPreCalendar(msg.getGuild().getLongID())) {
|
||||
getPreCalendar(msg.getGuild().getLongID()).setCreatorMessage(msg);
|
||||
}
|
||||
}
|
||||
if (msg != null && hasPreCalendar(msg.getGuild().getLongID()))
|
||||
getPreCalendar(msg.getGuild().getLongID()).setCreatorMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,8 @@ public class EventCreator {
|
||||
* @return The instance of the EventCreator
|
||||
*/
|
||||
public static EventCreator getCreator() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new EventCreator();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -163,7 +162,7 @@ public class EventCreator {
|
||||
|
||||
try {
|
||||
event.setTimeZone(service.calendars().get(calId).execute().getTimeZone());
|
||||
} catch (IOException e1) {
|
||||
} catch (IOException ignore) {
|
||||
//Failed to get tz, ignore safely.
|
||||
}
|
||||
|
||||
@@ -193,7 +192,7 @@ public class EventCreator {
|
||||
* @param e The event received upon termination.
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
public Boolean terminate(MessageReceivedEvent e) {
|
||||
public boolean terminate(MessageReceivedEvent e) {
|
||||
if (hasPreEvent(e.getGuild().getLongID())) {
|
||||
events.remove(getPreEvent(e.getGuild().getLongID()));
|
||||
return true;
|
||||
@@ -226,12 +225,11 @@ public class EventCreator {
|
||||
event.setStart(preEvent.getStartDateTime().setTimeZone(preEvent.getTimeZone()));
|
||||
event.setEnd(preEvent.getEndDateTime().setTimeZone(preEvent.getTimeZone()));
|
||||
event.setVisibility("public");
|
||||
if (!preEvent.getColor().equals(EventColor.NONE)) {
|
||||
if (!preEvent.getColor().equals(EventColor.NONE))
|
||||
event.setColorId(String.valueOf(preEvent.getColor().getId()));
|
||||
}
|
||||
if (preEvent.getLocation() != null && !preEvent.getLocation().equalsIgnoreCase("")) {
|
||||
|
||||
if (preEvent.getLocation() != null && !preEvent.getLocation().equalsIgnoreCase(""))
|
||||
event.setLocation(preEvent.getLocation());
|
||||
}
|
||||
|
||||
|
||||
//Set recurrence
|
||||
@@ -308,9 +306,8 @@ public class EventCreator {
|
||||
}
|
||||
|
||||
public IMessage getCreatorMessage(long guildId) {
|
||||
if (hasPreEvent(guildId)) {
|
||||
if (hasPreEvent(guildId))
|
||||
return getPreEvent(guildId).getCreatorMessage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -326,11 +323,10 @@ public class EventCreator {
|
||||
* @param guildId The ID of the guild.
|
||||
* @return <code>true</code> if a PreEvent exists, otherwise <code>false</code>.
|
||||
*/
|
||||
public Boolean hasPreEvent(long guildId) {
|
||||
public boolean hasPreEvent(long guildId) {
|
||||
for (PreEvent e : events) {
|
||||
if (e.getGuildId() == guildId) {
|
||||
if (e.getGuildId() == guildId)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -341,10 +337,7 @@ public class EventCreator {
|
||||
|
||||
//Setters
|
||||
public void setCreatorMessage(IMessage msg) {
|
||||
if (msg != null) {
|
||||
if (hasPreEvent(msg.getGuild().getLongID())) {
|
||||
getPreEvent(msg.getGuild().getLongID()).setCreatorMessage(msg);
|
||||
}
|
||||
}
|
||||
if (msg != null && hasPreEvent(msg.getGuild().getLongID()))
|
||||
getPreEvent(msg.getGuild().getLongID()).setCreatorMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -113,9 +113,9 @@ public class EventMessageFormatter {
|
||||
em.withAuthorName("DisCal");
|
||||
em.withTitle(MessageManager.getMessage("Embed.Event.Condensed.Title", settings));
|
||||
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
|
||||
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
|
||||
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink()))
|
||||
em.withThumbnail(ed.getImageLink());
|
||||
}
|
||||
|
||||
if (event.getSummary() != null) {
|
||||
String summary = event.getSummary();
|
||||
if (summary.length() > 250) {
|
||||
@@ -165,9 +165,9 @@ public class EventMessageFormatter {
|
||||
//TODO: find out why this is happening
|
||||
Logger.getLogger().exception(null, "[Event] Failed to handle event image. Is event null?", e, EventMessageFormatter.class, true);
|
||||
}
|
||||
if (event.isEditing()) {
|
||||
if (event.isEditing())
|
||||
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Id", settings), event.getEventId(), false);
|
||||
}
|
||||
|
||||
if (event.getSummary() != null) {
|
||||
String summary = event.getSummary();
|
||||
if (summary.length() > 250) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class UpdateDisPwData {
|
||||
|
||||
private static void updateSiteBotMeta() {
|
||||
try {
|
||||
Integer serverCount = DisCalAPI.getAPI().getClient().getGuilds().size();
|
||||
int serverCount = DisCalAPI.getAPI().getClient().getGuilds().size();
|
||||
|
||||
JSONObject json = new JSONObject().put("server_count", serverCount);
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ public class AnnouncementCreator {
|
||||
* @param e The event received upon termination.
|
||||
* @return Whether or not the Creator was successfully terminated.
|
||||
*/
|
||||
public Boolean terminate(MessageReceivedEvent e) {
|
||||
public boolean terminate(MessageReceivedEvent e) {
|
||||
if (hasAnnouncement(e.getGuild().getLongID())) {
|
||||
announcements.remove(getAnnouncement(e.getGuild().getLongID()));
|
||||
return true;
|
||||
@@ -158,9 +158,8 @@ public class AnnouncementCreator {
|
||||
}
|
||||
|
||||
public IMessage getCreatorMessage(long guildId) {
|
||||
if (hasAnnouncement(guildId)) {
|
||||
if (hasAnnouncement(guildId))
|
||||
return getAnnouncement(guildId).getCreatorMessage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -170,11 +169,8 @@ public class AnnouncementCreator {
|
||||
|
||||
//Setters
|
||||
public void setCreatorMessage(IMessage message) {
|
||||
if (message != null) {
|
||||
if (hasCreatorMessage(message.getGuild().getLongID())) {
|
||||
getAnnouncement(message.getGuild().getLongID()).setCreatorMessage(message);
|
||||
}
|
||||
}
|
||||
if (message != null && hasCreatorMessage(message.getGuild().getLongID()))
|
||||
getAnnouncement(message.getGuild().getLongID()).setCreatorMessage(message);
|
||||
}
|
||||
|
||||
//Booleans/Checkers
|
||||
@@ -183,16 +179,15 @@ public class AnnouncementCreator {
|
||||
* @param guildId The ID of the guild.
|
||||
* @return <code>true</code> if active, else <code>false</code>.
|
||||
*/
|
||||
public Boolean hasAnnouncement(long guildId) {
|
||||
public boolean hasAnnouncement(long guildId) {
|
||||
for (Announcement a : announcements) {
|
||||
if (a.getGuildId() == guildId) {
|
||||
if (a.getGuildId() == guildId)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean hasCreatorMessage(long guildId) {
|
||||
public boolean hasCreatorMessage(long guildId) {
|
||||
return hasAnnouncement(guildId) && getAnnouncement(guildId).getCreatorMessage() != null;
|
||||
}
|
||||
}
|
||||
@@ -353,9 +353,8 @@ public class AnnouncementMessageFormatter {
|
||||
for (String userId : a.getSubscriberUserIds()) {
|
||||
try {
|
||||
IUser user = guild.getUserByID(Long.valueOf(userId));
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
userMentions.append(user.getName()).append(" ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//User does not exist, safely ignore.
|
||||
}
|
||||
@@ -372,22 +371,20 @@ public class AnnouncementMessageFormatter {
|
||||
} else {
|
||||
try {
|
||||
IRole role = guild.getRoleByID(Long.valueOf(roleId));
|
||||
if (role != null) {
|
||||
if (role != null)
|
||||
roleMentions.append(role.getName()).append(" ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignore) {
|
||||
//Role does not exist, safely ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String message = "Subscribers: " + userMentions + " " + roleMentions;
|
||||
if (mentionEveryone) {
|
||||
if (mentionEveryone)
|
||||
message = message + " " + guild.getEveryoneRole().getName();
|
||||
}
|
||||
if (mentionHere) {
|
||||
|
||||
if (mentionHere)
|
||||
message = message + " here";
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
@@ -416,25 +413,23 @@ public class AnnouncementMessageFormatter {
|
||||
} else {
|
||||
try {
|
||||
IRole role = guild.getRoleByID(Long.valueOf(roleId));
|
||||
if (role != null) {
|
||||
if (role != null)
|
||||
roleMentions.append(role.mention()).append(" ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//Role does not exist, safely ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!mentionEveryone && !mentionHere && userMentions.toString().equals("") && roleMentions.toString().equals("")) {
|
||||
if (!mentionEveryone && !mentionHere && userMentions.toString().equals("") && roleMentions.toString().equals(""))
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
String message = "Subscribers: " + userMentions + " " + roleMentions;
|
||||
if (mentionEveryone) {
|
||||
if (mentionEveryone)
|
||||
message = message + " " + guild.getEveryoneRole().mention();
|
||||
}
|
||||
if (mentionHere) {
|
||||
|
||||
if (mentionHere)
|
||||
message = message + " @here";
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AddCalendarCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (settings.isDevGuild() || settings.isPatronGuild()) {
|
||||
if (PermissionChecker.hasManageServerRole(event)) {
|
||||
if (args.length == 0) {
|
||||
|
||||
@@ -106,38 +106,34 @@ public class AnnouncementCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length < 1) {
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Args.Few", settings), event);
|
||||
} else {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCreate(event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "confirm":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleConfirm(event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "cancel":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCancel(event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "delete":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleDelete(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "view":
|
||||
case "review":
|
||||
@@ -185,18 +181,16 @@ public class AnnouncementCommand implements ICommand {
|
||||
moduleColor(args, event, settings);
|
||||
break;
|
||||
case "copy":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCopy(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "edit":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleEdit(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Args.Invalid", settings), event);
|
||||
@@ -212,11 +206,10 @@ public class AnnouncementCommand implements ICommand {
|
||||
|
||||
if (!AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
|
||||
AnnouncementCreator.getCreator().init(event, settings);
|
||||
if (!AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
|
||||
if (!AnnouncementCreator.getCreator().hasCreatorMessage(guildId))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Create.Init", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.deleteMessage(event);
|
||||
}
|
||||
} else {
|
||||
if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
|
||||
Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
|
||||
@@ -302,6 +295,7 @@ public class AnnouncementCommand implements ICommand {
|
||||
Message.deleteMessage(creatorMessage);
|
||||
Message.deleteMessage(event);
|
||||
}
|
||||
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Cancel.Success", settings), event);
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.NotInit", settings), event);
|
||||
@@ -389,45 +383,33 @@ public class AnnouncementCommand implements ICommand {
|
||||
} else if (args.length == 2) {
|
||||
String value = args[1];
|
||||
if (AnnouncementUtils.announcementExists(value, event)) {
|
||||
Announcement a = DatabaseManager.getManager()
|
||||
.getAnnouncement(UUID.fromString(value), guildId);
|
||||
Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value), guildId);
|
||||
String senderId = event.getMessage().getAuthor().getStringID();
|
||||
if (!a.getSubscriberUserIds().contains(senderId)) {
|
||||
a.getSubscriberUserIds().add(senderId);
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage("You have subscribed to the announcement with the ID: `" + value + "`"
|
||||
+ MessageUtils.lineBreak + "To unsubscribe use `!announcement unsubscribe <id>`", event);
|
||||
Message.sendMessage("You have subscribed to the announcement with the ID: `" + value + "`" + MessageUtils.lineBreak + "To unsubscribe use `!announcement unsubscribe <id>`", event);
|
||||
} else {
|
||||
Message.sendMessage("You are already subscribed to that event!", event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?",
|
||||
event);
|
||||
Message.sendMessage("Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?", event);
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
String value1 = args[1];
|
||||
String value2 = args[2];
|
||||
if (AnnouncementUtils.announcementExists(value1, event)) {
|
||||
Announcement a = DatabaseManager.getManager()
|
||||
.getAnnouncement(UUID.fromString(value1), guildId);
|
||||
IUser user = event.getMessage().getGuild()
|
||||
.getUserByID(UserUtils.getUser(value2, event.getMessage()));
|
||||
Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value1), guildId);
|
||||
IUser user = event.getMessage().getGuild().getUserByID(UserUtils.getUser(value2, event.getMessage()));
|
||||
if (user != null) {
|
||||
//Valid user, let's add that user to the announcement.
|
||||
if (!a.getSubscriberUserIds().contains(user.getStringID())) {
|
||||
String username = user.getDisplayName(event.getMessage().getGuild());
|
||||
a.getSubscriberUserIds().add(user.getStringID());
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"`" + username + "` has been subscribed to the announcement with the ID `" + a
|
||||
.getAnnouncementId() + "`" + MessageUtils.lineBreak
|
||||
+ "To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>",
|
||||
event);
|
||||
Message.sendMessage("`" + username + "` has been subscribed to the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>", event);
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"That user is already subscribed to the specified announcement! To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>`",
|
||||
event);
|
||||
Message.sendMessage("That user is already subscribed to the specified announcement! To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>`", event);
|
||||
}
|
||||
} else if (value2.equalsIgnoreCase("everyone") || value2.equalsIgnoreCase("here")) {
|
||||
//Here or everyone is to be subscribed...
|
||||
@@ -435,15 +417,9 @@ public class AnnouncementCommand implements ICommand {
|
||||
if (!a.getSubscriberRoleIds().contains(men)) {
|
||||
a.getSubscriberRoleIds().add(men);
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"`" + men + "` has been subscribed to the announcement with the ID `" + a
|
||||
.getAnnouncementId() + "`" + MessageUtils.lineBreak
|
||||
+ "To unsubscribe them use `!announcement unsubscribe <announcement ID> <value>",
|
||||
event);
|
||||
Message.sendMessage("`" + men + "` has been subscribed to the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To unsubscribe them use `!announcement unsubscribe <announcement ID> <value>", event);
|
||||
} else {
|
||||
Message.sendMessage(men
|
||||
+ " is already subscribed to the specified announcement! To unsubscribe them use `!announcement unsubscribe <announcement ID> <value>`",
|
||||
event);
|
||||
Message.sendMessage(men + " is already subscribed to the specified announcement! To unsubscribe them use `!announcement unsubscribe <announcement ID> <value>`", event);
|
||||
}
|
||||
} else {
|
||||
//User does not exist, see if a role.
|
||||
@@ -454,31 +430,20 @@ public class AnnouncementCommand implements ICommand {
|
||||
String roleName = role.getName();
|
||||
a.getSubscriberRoleIds().add(role.getStringID());
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"`" + roleName + "` has been subscribed to the announcement with the ID `" + a
|
||||
.getAnnouncementId() + "`" + MessageUtils.lineBreak
|
||||
+ "To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>",
|
||||
event);
|
||||
Message.sendMessage("`" + roleName + "` has been subscribed to the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>", event);
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"That role is already subscribed to the specified announcement! To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>`",
|
||||
event);
|
||||
Message.sendMessage("That role is already subscribed to the specified announcement! To unsubscribe them use `!announcement unsubscribe <announcement ID> <mention>`", event);
|
||||
}
|
||||
} else {
|
||||
//Role does not exist...
|
||||
Message.sendMessage("Role or user not found! Are you sure you typed them correctly?",
|
||||
event);
|
||||
Message.sendMessage("Role or user not found! Are you sure you typed them correctly?", event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?",
|
||||
event);
|
||||
Message.sendMessage("Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?", event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"Please use `!announcement subscribe <ID>` or `!announcement subscribe <ID> <user mention/role mention/here/everyone>`",
|
||||
event);
|
||||
Message.sendMessage("Please use `!announcement subscribe <ID>` or `!announcement subscribe <ID> <user mention/role mention/here/everyone>`", event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,22 +629,20 @@ public class AnnouncementCommand implements ICommand {
|
||||
em.withDesc(MessageManager.getMessage("Embed.Announcement.Subscribe.Users", "%users%", subscribedUsers.toString(), settings) + MessageUtils.lineBreak + MessageManager.getMessage("Embed.Announcement.Subscribe.Roles", "%roles%", subscribedRoles.toString(), settings));
|
||||
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Subscribe.Footer", "%id%", a.getAnnouncementId().toString(), settings));
|
||||
Message.sendMessage(em.build(), event);
|
||||
if (updateDb) {
|
||||
if (updateDb)
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event);
|
||||
}
|
||||
}
|
||||
|
||||
private void moduleSubscribeRewrite(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length == 1) {
|
||||
if (args.length == 1)
|
||||
moduleSubscribeRewriteArgsOne(event, settings);
|
||||
} else if (args.length == 2) {
|
||||
else if (args.length == 2)
|
||||
moduleSubscribeRewriteArgsTwo(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
moduleSubscribeRewriteArgsThree(args, event, settings);
|
||||
}
|
||||
}
|
||||
|
||||
private void moduleUnsubscribeRewriteArgsOne(MessageReceivedEvent event, GuildSettings settings) {
|
||||
@@ -862,9 +825,8 @@ public class AnnouncementCommand implements ICommand {
|
||||
em.withDesc(MessageManager.getMessage("Embed.Announcement.Unsubscribe.Users", "%users%", subscribedUsers.toString(), settings) + MessageUtils.lineBreak + MessageManager.getMessage("Embed.Announcement.Unsubscribe.Roles", "%roles%", subscribedRoles.toString(), settings));
|
||||
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Unsubscribe.Footer", "%id%", a.getAnnouncementId().toString(), settings));
|
||||
Message.sendMessage(em.build(), event);
|
||||
if (updateDb) {
|
||||
if (updateDb)
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Announcement", settings), event);
|
||||
}
|
||||
@@ -872,13 +834,12 @@ public class AnnouncementCommand implements ICommand {
|
||||
}
|
||||
|
||||
private void moduleUnsubscribeRewrite(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length == 1) {
|
||||
if (args.length == 1)
|
||||
moduleUnsubscribeRewriteArgsOne(event, settings);
|
||||
} else if (args.length == 2) {
|
||||
else if (args.length == 2)
|
||||
moduleUnsubscribeRewriteArgsTwo(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
moduleUnsubscribeRewriteArgsThree(args, event, settings);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -886,35 +847,27 @@ public class AnnouncementCommand implements ICommand {
|
||||
private void moduleUnsubscribe(String[] args, MessageReceivedEvent event) {
|
||||
long guildId = event.getGuild().getLongID();
|
||||
if (args.length == 1) {
|
||||
Message.sendMessage("Please specify the ID of the announcement you wish to unsubscribe from!",
|
||||
event);
|
||||
Message.sendMessage("Please specify the ID of the announcement you wish to unsubscribe from!", event);
|
||||
} else if (args.length == 2) {
|
||||
String value = args[1];
|
||||
if (AnnouncementUtils.announcementExists(value, event)) {
|
||||
Announcement a = DatabaseManager.getManager()
|
||||
.getAnnouncement(UUID.fromString(value), guildId);
|
||||
Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value), guildId);
|
||||
String senderId = event.getMessage().getAuthor().getStringID();
|
||||
if (a.getSubscriberUserIds().contains(senderId)) {
|
||||
a.getSubscriberUserIds().remove(senderId);
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"You have unsubscribed to the announcement with the ID: `" + value + "`"
|
||||
+ MessageUtils.lineBreak + "To re-subscribe use `!announcement subscribe <id>`",
|
||||
event);
|
||||
Message.sendMessage("You have unsubscribed to the announcement with the ID: `" + value + "`" + MessageUtils.lineBreak + "To re-subscribe use `!announcement subscribe <id>`", event);
|
||||
} else {
|
||||
Message.sendMessage("You are not subscribed to this event!", event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?",
|
||||
event);
|
||||
Message.sendMessage("Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?", event);
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
String value1 = args[1];
|
||||
String value2 = args[2];
|
||||
if (AnnouncementUtils.announcementExists(value1, event)) {
|
||||
Announcement a = DatabaseManager.getManager()
|
||||
.getAnnouncement(UUID.fromString(value1), guildId);
|
||||
Announcement a = DatabaseManager.getManager().getAnnouncement(UUID.fromString(value1), guildId);
|
||||
IUser user = UserUtils.getUserFromMention(value2, event);
|
||||
if (user != null) {
|
||||
//Valid user, let's add that user to the announcement.
|
||||
@@ -922,15 +875,9 @@ public class AnnouncementCommand implements ICommand {
|
||||
String username = user.getDisplayName(event.getMessage().getGuild());
|
||||
a.getSubscriberUserIds().remove(user.getStringID());
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"`" + username + "` has been unsubscribed from the announcement with the ID `" + a
|
||||
.getAnnouncementId() + "`" + MessageUtils.lineBreak
|
||||
+ "To re-subscribe them use `!announcement subscribe <announcement ID> <mention>",
|
||||
event);
|
||||
Message.sendMessage("`" + username + "` has been unsubscribed from the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To re-subscribe them use `!announcement subscribe <announcement ID> <mention>", event);
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"That user is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <mention>`",
|
||||
event);
|
||||
Message.sendMessage("That user is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <mention>`", event);
|
||||
}
|
||||
} else if (value2.equalsIgnoreCase("everyone") || value2.equalsIgnoreCase("here")) {
|
||||
//Here or everyone is to be mentioned...
|
||||
@@ -938,15 +885,9 @@ public class AnnouncementCommand implements ICommand {
|
||||
if (a.getSubscriberRoleIds().contains(men)) {
|
||||
a.getSubscriberRoleIds().remove(men);
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"`" + men + "` has been unsubscribed from the announcement with the ID `" + a
|
||||
.getAnnouncementId() + "`" + MessageUtils.lineBreak
|
||||
+ "To re-subscribe them use `!announcement subscribe <announcement ID> <value>",
|
||||
event);
|
||||
Message.sendMessage("`" + men + "` has been unsubscribed from the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To re-subscribe them use `!announcement subscribe <announcement ID> <value>", event);
|
||||
} else {
|
||||
Message.sendMessage(men
|
||||
+ " is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <value>`",
|
||||
event);
|
||||
Message.sendMessage(men + " is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <value>`", event);
|
||||
}
|
||||
} else {
|
||||
//User does not exist, see if a role.
|
||||
@@ -957,31 +898,20 @@ public class AnnouncementCommand implements ICommand {
|
||||
String roleName = role.getName();
|
||||
a.getSubscriberRoleIds().remove(role.getStringID());
|
||||
DatabaseManager.getManager().updateAnnouncement(a);
|
||||
Message.sendMessage(
|
||||
"`" + roleName + "` has been unsubscribed from the announcement with the ID `" + a
|
||||
.getAnnouncementId() + "`" + MessageUtils.lineBreak
|
||||
+ "To re-subscribe them use `!announcement subscribe <announcement ID> <mention>",
|
||||
event);
|
||||
Message.sendMessage("`" + roleName + "` has been unsubscribed from the announcement with the ID `" + a.getAnnouncementId() + "`" + MessageUtils.lineBreak + "To re-subscribe them use `!announcement subscribe <announcement ID> <mention>", event);
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"That role is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <mention>`",
|
||||
event);
|
||||
Message.sendMessage("That role is not subscribed to the specified announcement! To subscribe them use `!announcement unsubscribe <announcement ID> <mention>`", event);
|
||||
}
|
||||
} else {
|
||||
//Role does not exist...
|
||||
Message.sendMessage("Role or user not found! Are you sure you typed them correctly?",
|
||||
event);
|
||||
Message.sendMessage("Role or user not found! Are you sure you typed them correctly?", event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?",
|
||||
event);
|
||||
Message.sendMessage("Hmm.. it seems the specified announcement does not exist, are you sure you wrote the ID correctly?", event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(
|
||||
"Please use `!announcement unsubscribe <ID>` or `!announcement unsubscribe <ID> <user mention/role mention/here/everyone>`",
|
||||
event);
|
||||
Message.sendMessage("Please use `!announcement unsubscribe <ID>` or `!announcement unsubscribe <ID> <user mention/role mention/here/everyone>`", event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1082,8 +1012,8 @@ public class AnnouncementCommand implements ICommand {
|
||||
String value = args[1];
|
||||
if (AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
|
||||
try {
|
||||
Integer minutesOr = Integer.valueOf(value);
|
||||
Integer minutes = Math.abs(minutesOr);
|
||||
int minutesOr = Integer.valueOf(value);
|
||||
int minutes = Math.abs(minutesOr);
|
||||
AnnouncementCreator.getCreator().getAnnouncement(guildId).setMinutesBefore(minutes);
|
||||
if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
|
||||
Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
|
||||
@@ -1172,8 +1102,7 @@ public class AnnouncementCommand implements ICommand {
|
||||
if (args.length == 2) {
|
||||
String value = args[1];
|
||||
if (AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
|
||||
if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType()
|
||||
.equals(AnnouncementType.SPECIFIC)) {
|
||||
if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
|
||||
if (EventUtils.eventExists(settings, value)) {
|
||||
AnnouncementCreator.getCreator().getAnnouncement(guildId).setEventId(value);
|
||||
if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
|
||||
@@ -1192,8 +1121,7 @@ public class AnnouncementCommand implements ICommand {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.CannotFind.Event", settings), event);
|
||||
}
|
||||
}
|
||||
} else if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType()
|
||||
.equals(AnnouncementType.RECUR)) {
|
||||
} else if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType().equals(AnnouncementType.RECUR)) {
|
||||
if (EventUtils.eventExists(settings, value)) {
|
||||
if (value.contains("_")) {
|
||||
String[] stuff = value.split("_");
|
||||
@@ -1326,8 +1254,7 @@ public class AnnouncementCommand implements ICommand {
|
||||
if (AnnouncementCreator.getCreator().hasCreatorMessage(guildId)) {
|
||||
Message.deleteMessage(AnnouncementCreator.getCreator().getCreatorMessage(guildId));
|
||||
Message.deleteMessage(event);
|
||||
AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator
|
||||
.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Channel.Success.New", settings), event));
|
||||
AnnouncementCreator.getCreator().setCreatorMessage(Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(AnnouncementCreator.getCreator().getAnnouncement(guildId), settings), MessageManager.getMessage("Creator.Announcement.Channel.Success.New", settings), event));
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Announcement.Channel.Success", "%channel%", c.getName(), settings), event);
|
||||
}
|
||||
@@ -1362,8 +1289,7 @@ public class AnnouncementCommand implements ICommand {
|
||||
if (args.length == 2) {
|
||||
String value = args[1];
|
||||
if (AnnouncementCreator.getCreator().hasAnnouncement(guildId)) {
|
||||
if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType()
|
||||
.equals(AnnouncementType.COLOR)) {
|
||||
if (AnnouncementCreator.getCreator().getAnnouncement(guildId).getAnnouncementType().equals(AnnouncementType.COLOR)) {
|
||||
if (EventColor.exists(value)) {
|
||||
EventColor color = EventColor.fromNameOrHexOrID(value);
|
||||
AnnouncementCreator.getCreator().getAnnouncement(guildId).setEventColor(color);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CalendarCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length < 1) {
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Args.Few", settings), event);
|
||||
} else {
|
||||
@@ -97,18 +97,16 @@ public class CalendarCommand implements ICommand {
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCreate(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "cancel":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCancel(event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "view":
|
||||
moduleView(event, calendarData, settings);
|
||||
@@ -117,25 +115,22 @@ public class CalendarCommand implements ICommand {
|
||||
moduleView(event, calendarData, settings);
|
||||
break;
|
||||
case "confirm":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleConfirm(event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "delete":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleDelete(event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "remove":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleDelete(event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
moduleSummary(args, event, calendarData, settings);
|
||||
@@ -150,11 +145,10 @@ public class CalendarCommand implements ICommand {
|
||||
moduleTimezone(args, event, calendarData, settings);
|
||||
break;
|
||||
case "edit":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleEdit(event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Args.Invalid", settings), event);
|
||||
@@ -179,11 +173,10 @@ public class CalendarCommand implements ICommand {
|
||||
if (args.length > 1) {
|
||||
String name = GeneralUtils.getContent(args, 1);
|
||||
PreCalendar calendar = CalendarCreator.getCreator().init(event, name, settings, true);
|
||||
if (calendar.getCreatorMessage() != null) {
|
||||
if (calendar.getCreatorMessage() != null)
|
||||
Message.deleteMessage(event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Create.Init", settings), event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Create.Name", settings), event);
|
||||
}
|
||||
@@ -209,22 +202,20 @@ public class CalendarCommand implements ICommand {
|
||||
CalendarCreator.getCreator().setCreatorMessage(Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Edit.Success", settings), event));
|
||||
}
|
||||
} else {
|
||||
if (!editing) {
|
||||
if (!editing)
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Success", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Edit.Success", settings), event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Cancel.Failure", settings), event);
|
||||
Message.deleteMessage(event);
|
||||
}
|
||||
} else {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary"))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NotInit", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,11 +231,10 @@ public class CalendarCommand implements ICommand {
|
||||
Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(preCalendar, settings), MessageManager.getMessage("Creator.Calendar.Review", settings), event);
|
||||
}
|
||||
} else {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary"))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,11 +280,10 @@ public class CalendarCommand implements ICommand {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary"))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,18 +299,16 @@ public class CalendarCommand implements ICommand {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!event.getMessage().getAuthor().getPermissionsForGuild(event.getMessage().getGuild()).contains(
|
||||
Permissions.MANAGE_SERVER)) {
|
||||
if (!event.getMessage().getAuthor().getPermissionsForGuild(event.getMessage().getGuild()).contains(Permissions.MANAGE_SERVER)) {
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.MANAGE_SERVER", settings), event);
|
||||
return;
|
||||
}
|
||||
if (!calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
//Delete calendar
|
||||
if (CalendarUtils.deleteCalendar(calendarData, settings)) {
|
||||
if (CalendarUtils.deleteCalendar(calendarData, settings))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Success", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Failure.Unknown", settings), event);
|
||||
}
|
||||
} else {
|
||||
//No calendar to delete
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Failure.NoCalendar", settings), event);
|
||||
@@ -342,11 +329,10 @@ public class CalendarCommand implements ICommand {
|
||||
Message.sendMessage(msg, event);
|
||||
}
|
||||
} else {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary"))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (CalendarCreator.getCreator().hasPreCalendar(guildId)) {
|
||||
@@ -376,11 +362,10 @@ public class CalendarCommand implements ICommand {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Description.O.Success", "%desc%", GeneralUtils.getContent(args, 1), settings) + TIME_ZONE_DB, event);
|
||||
}
|
||||
} else {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary"))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (CalendarCreator.getCreator().hasPreCalendar(guildId)) {
|
||||
@@ -422,11 +407,10 @@ public class CalendarCommand implements ICommand {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary")) {
|
||||
if (calendarData.getCalendarId().equalsIgnoreCase("primary"))
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.NoCalendar", settings), event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.HasCalendar", settings), event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (CalendarCreator.getCreator().hasPreCalendar(guildId)) {
|
||||
|
||||
@@ -24,9 +24,9 @@ public class CommandExecutor {
|
||||
* @return The instance of the CommandExecutor.
|
||||
*/
|
||||
public static CommandExecutor getExecutor() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new CommandExecutor();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -67,9 +67,8 @@ public class CommandExecutor {
|
||||
}
|
||||
|
||||
for (ICommand c : commands) {
|
||||
if (c.getCommand().equalsIgnoreCase(cmd) || c.getAliases().contains(cmd.toLowerCase())) {
|
||||
if (c.getCommand().equalsIgnoreCase(cmd) || c.getAliases().contains(cmd.toLowerCase()))
|
||||
c.issueCommand(args, event, settings);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -81,9 +80,8 @@ public class CommandExecutor {
|
||||
ArrayList<String> getAllCommands() {
|
||||
ArrayList<String> cmds = new ArrayList<>();
|
||||
for (ICommand c : commands) {
|
||||
if (!cmds.contains(c.getCommand())) {
|
||||
if (!cmds.contains(c.getCommand()))
|
||||
cmds.add(c.getCommand());
|
||||
}
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
@@ -94,9 +92,8 @@ public class CommandExecutor {
|
||||
|
||||
ICommand getCommand(String cmdNameOrAlias) {
|
||||
for (ICommand c : commands) {
|
||||
if (c.getCommand().equalsIgnoreCase(cmdNameOrAlias) || c.getAliases().contains(cmdNameOrAlias.toLowerCase())) {
|
||||
if (c.getCommand().equalsIgnoreCase(cmdNameOrAlias) || c.getAliases().contains(cmdNameOrAlias.toLowerCase()))
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class DevCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (event.getAuthor().getLongID() == DisCalAPI.getAPI().novaId || event.getAuthor().getLongID() == DisCalAPI.getAPI().xaanitId || event.getAuthor().getLongID() == DisCalAPI.getAPI().calId || event.getAuthor().getLongID() == DisCalAPI.getAPI().dreamId) {
|
||||
if (args.length < 1) {
|
||||
Message.sendMessage("Please specify the function you would like to execute. To view valid functions use `!help dev`", event);
|
||||
@@ -387,11 +387,10 @@ public class DevCommand implements ICommand {
|
||||
UserAPIAccount account = DatabaseManager.getManager().getAPIAccount(key);
|
||||
account.setBlocked(true);
|
||||
|
||||
if (DatabaseManager.getManager().updateAPIAccount(account)) {
|
||||
if (DatabaseManager.getManager().updateAPIAccount(account))
|
||||
Message.sendMessage("Successfully blocked API key!", event);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage("Error occurred! Could not block API key!", event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage("Please specify the API KEY!", event);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class DisCalCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length < 1) {
|
||||
moduleDisCalInfo(event, settings);
|
||||
} else {
|
||||
|
||||
@@ -111,7 +111,7 @@ public class EventCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
long guildId = event.getGuild().getLongID();
|
||||
//TODO: Add multiple calendar handling.
|
||||
CalendarData calendarData = DatabaseManager.getManager().getMainCalendar(guildId);
|
||||
@@ -120,46 +120,40 @@ public class EventCommand implements ICommand {
|
||||
} else {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCreate(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "copy":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCopy(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "edit":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleEdit(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "restart":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleRestart(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "cancel":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleCancel(event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "delete":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleDelete(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "view":
|
||||
moduleView(args, event, calendarData, settings);
|
||||
@@ -168,11 +162,10 @@ public class EventCommand implements ICommand {
|
||||
moduleView(args, event, calendarData, settings);
|
||||
break;
|
||||
case "confirm":
|
||||
if (PermissionChecker.hasSufficientRole(event)) {
|
||||
if (PermissionChecker.hasSufficientRole(event))
|
||||
moduleConfirm(event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
|
||||
}
|
||||
break;
|
||||
case "startdate":
|
||||
moduleStartDate(args, event, settings);
|
||||
@@ -253,14 +246,13 @@ public class EventCommand implements ICommand {
|
||||
} else {
|
||||
if (!calendarData.getCalendarAddress().equalsIgnoreCase("primary")) {
|
||||
PreEvent e;
|
||||
if (args.length == 1) {
|
||||
if (args.length == 1)
|
||||
e = EventCreator.getCreator().init(event, settings, true);
|
||||
} else {
|
||||
else
|
||||
e = EventCreator.getCreator().init(event, settings, GeneralUtils.getContent(args, 1), true);
|
||||
}
|
||||
if (e.getCreatorMessage() == null) {
|
||||
|
||||
if (e.getCreatorMessage() == null)
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Event.Create.Init", settings), event);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Event.NoCalendar", settings), event);
|
||||
}
|
||||
@@ -356,9 +348,9 @@ public class EventCommand implements ICommand {
|
||||
long guildId = event.getGuild().getLongID();
|
||||
IMessage msg = null;
|
||||
boolean editing = false;
|
||||
if (EventCreator.getCreator().hasPreEvent(guildId)) {
|
||||
if (EventCreator.getCreator().hasPreEvent(guildId))
|
||||
editing = EventCreator.getCreator().getPreEvent(guildId).isEditing();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (EventCreator.getCreator().hasCreatorMessage(guildId))
|
||||
@@ -369,11 +361,10 @@ public class EventCommand implements ICommand {
|
||||
Message.deleteMessage(msg);
|
||||
Message.deleteMessage(event);
|
||||
}
|
||||
if (!editing) {
|
||||
if (!editing)
|
||||
moduleCreate(args, event, calendarData, settings);
|
||||
} else {
|
||||
else
|
||||
moduleEdit(args, event, calendarData, settings);
|
||||
}
|
||||
} else {
|
||||
Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
|
||||
}
|
||||
|
||||
@@ -67,26 +67,23 @@ public class EventListCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
//Get events from calendar
|
||||
if (args.length < 1) {
|
||||
moduleSimpleList(args, event, settings);
|
||||
} else {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "search":
|
||||
if (settings.isDevGuild()) {
|
||||
//To search module.
|
||||
if (settings.isDevGuild())
|
||||
moduleSearch(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Disabled", settings), event);
|
||||
}
|
||||
break;
|
||||
case "today":
|
||||
if (settings.isDevGuild()) {
|
||||
if (settings.isDevGuild())
|
||||
moduleDay(args, event, settings);
|
||||
} else {
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Disabled", settings), event);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
moduleSimpleList(args, event, settings);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class HelpCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length < 1) {
|
||||
EmbedBuilder em = new EmbedBuilder();
|
||||
em.withAuthorIcon(DisCalAPI.getAPI().iconUrl);
|
||||
@@ -80,20 +80,18 @@ public class HelpCommand implements ICommand {
|
||||
} else if (args.length == 1) {
|
||||
String cmdFor = args[0];
|
||||
ICommand cmd = CommandExecutor.getExecutor().getCommand(cmdFor);
|
||||
if (cmd != null) {
|
||||
if (cmd != null)
|
||||
Message.sendMessage(getCommandInfoEmbed(cmd), event);
|
||||
}
|
||||
|
||||
} else if (args.length == 2) {
|
||||
//Display sub command info
|
||||
String cmdFor = args[0];
|
||||
ICommand cmd = CommandExecutor.getExecutor().getCommand(cmdFor);
|
||||
if (cmd != null) {
|
||||
if (cmd.getCommandInfo().getSubCommands().containsKey(args[1].toLowerCase())) {
|
||||
if (cmd.getCommandInfo().getSubCommands().containsKey(args[1].toLowerCase()))
|
||||
Message.sendMessage(getSubCommandEmbed(cmd, args[1].toLowerCase()), event);
|
||||
} else {
|
||||
//Sub command does not exist.
|
||||
else
|
||||
Message.sendMessage(MessageManager.getMessage("Notification.Args.InvalidSubCmd", settings), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,5 +38,5 @@ interface ICommand {
|
||||
* @param event The event received.
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings);
|
||||
boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class LinkCalendarCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
try {
|
||||
//TODO: Handle multiple calendars...
|
||||
CalendarData data = DatabaseManager.getManager().getMainCalendar(event.getGuild().getLongID());
|
||||
|
||||
@@ -75,7 +75,7 @@ public class RsvpCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
if (args.length > 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "ontime":
|
||||
@@ -257,26 +257,25 @@ public class RsvpCommand implements ICommand {
|
||||
notGoing.append(u.getName()).append(", ");
|
||||
}
|
||||
|
||||
if (onTime.toString().isEmpty()) {
|
||||
if (onTime.toString().isEmpty())
|
||||
em.appendField("On time", "N/a", true);
|
||||
} else {
|
||||
else
|
||||
em.appendField("On Time", onTime.toString(), true);
|
||||
}
|
||||
if (late.toString().isEmpty()) {
|
||||
|
||||
if (late.toString().isEmpty())
|
||||
em.appendField("Late", "N/a", true);
|
||||
} else {
|
||||
else
|
||||
em.appendField("Late", late.toString(), true);
|
||||
}
|
||||
if (unsure.toString().isEmpty()) {
|
||||
|
||||
if (unsure.toString().isEmpty())
|
||||
em.appendField("Unsure", "N/a", true);
|
||||
} else {
|
||||
else
|
||||
em.appendField("Unsure", unsure.toString(), true);
|
||||
}
|
||||
if (notGoing.toString().isEmpty()) {
|
||||
|
||||
if (notGoing.toString().isEmpty())
|
||||
em.appendField("Not Going", "N/a", true);
|
||||
} else {
|
||||
else
|
||||
em.appendField("Not Going", notGoing.toString(), true);
|
||||
}
|
||||
|
||||
em.withFooterText(MessageManager.getMessage("Embed.RSVP.List.Footer", settings));
|
||||
em.withColor(56, 138, 237);
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TimeCommand implements ICommand {
|
||||
* @return <code>true</code> if successful, else <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public Boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
public boolean issueCommand(String[] args, MessageReceivedEvent event, GuildSettings settings) {
|
||||
calendarTime(event, settings);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ public class StatusChanger extends TimerTask {
|
||||
statuses.add("%calCount% calendars!");
|
||||
statuses.add("%annCount% announcements!");
|
||||
statuses.add("%shards% shards!");
|
||||
if (BotSettings.RUN_API.get().equalsIgnoreCase("true")) {
|
||||
if (BotSettings.RUN_API.get().equalsIgnoreCase("true"))
|
||||
statuses.add("%users% using Dashboard!");
|
||||
}
|
||||
|
||||
statuses.add("Version " + Main.version);
|
||||
statuses.add("DisCal is on Patreon!");
|
||||
statuses.add("Share DisCal!!");
|
||||
@@ -53,10 +53,9 @@ public class StatusChanger extends TimerTask {
|
||||
DisCalAPI.getAPI().getClient().changePresence(StatusType.ONLINE, ActivityType.PLAYING, status);
|
||||
|
||||
//Set new index.
|
||||
if (index + 1 >= statuses.size()) {
|
||||
if (index + 1 >= statuses.size())
|
||||
index = 0;
|
||||
} else {
|
||||
else
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,14 +18,13 @@ public class ChannelUtils {
|
||||
* @param event The event received.
|
||||
* @return <code>true</code> if exists, else <code>false</code>.
|
||||
*/
|
||||
public static Boolean channelExists(String nameOrId, MessageReceivedEvent event) {
|
||||
if (nameOrId.contains("#")) {
|
||||
public static boolean channelExists(String nameOrId, MessageReceivedEvent event) {
|
||||
if (nameOrId.contains("#"))
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
}
|
||||
|
||||
for (IChannel c : event.getGuild().getChannels()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -38,13 +37,12 @@ public class ChannelUtils {
|
||||
* @return the IChannel if successful, else <code>null</code>.
|
||||
*/
|
||||
public static IChannel getChannelFromNameOrId(String nameOrId, MessageReceivedEvent event) {
|
||||
if (nameOrId.contains("#")) {
|
||||
if (nameOrId.contains("#"))
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
}
|
||||
|
||||
for (IChannel c : event.getGuild().getChannels()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId))
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -58,13 +56,12 @@ public class ChannelUtils {
|
||||
*/
|
||||
public static IChannel getChannelFromNameOrId(String nameOrId, long guildId) {
|
||||
IGuild guild = DisCalAPI.getAPI().getClient().getGuildByID(guildId);
|
||||
if (nameOrId.contains("#")) {
|
||||
if (nameOrId.contains("#"))
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
}
|
||||
|
||||
for (IChannel c : guild.getChannels()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId))
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -78,13 +75,12 @@ public class ChannelUtils {
|
||||
*/
|
||||
public static String getChannelNameFromNameOrId(String nameOrId, long guildId) {
|
||||
IGuild guild = DisCalAPI.getAPI().getClient().getGuildByID(guildId);
|
||||
if (nameOrId.contains("#")) {
|
||||
if (nameOrId.contains("#"))
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
}
|
||||
|
||||
for (IChannel c : guild.getChannels()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId))
|
||||
return c.getName();
|
||||
}
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
@@ -18,47 +18,42 @@ import java.util.stream.Collectors;
|
||||
public class RoleUtils {
|
||||
public static IRole getRoleFromMention(String mention, MessageReceivedEvent event) {
|
||||
for (IRole r : event.getMessage().getGuild().getRoles()) {
|
||||
if (mention.equalsIgnoreCase("<@&" + r.getStringID() + ">") || mention.equalsIgnoreCase("<@&!" + r.getStringID() + ">")) {
|
||||
if (mention.equalsIgnoreCase("<@&" + r.getStringID() + ">") || mention.equalsIgnoreCase("<@&!" + r.getStringID() + ">"))
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IRole getRoleFromID(String id, MessageReceivedEvent event) {
|
||||
for (IRole r : event.getMessage().getGuild().getRoles()) {
|
||||
if (id.equals(r.getStringID()) || id.equals(r.getName())) {
|
||||
if (id.equals(r.getStringID()) || id.equals(r.getName()))
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IRole getRoleFromID(String id, IGuild guild) {
|
||||
for (IRole r : guild.getRoles()) {
|
||||
if (id.equalsIgnoreCase(r.getStringID()) || id.equals(r.getName())) {
|
||||
if (id.equalsIgnoreCase(r.getStringID()) || id.equals(r.getName()))
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean roleExists(String id, MessageReceivedEvent event) {
|
||||
for (IRole r : event.getMessage().getGuild().getRoles()) {
|
||||
if (id.equals(r.getStringID())) {
|
||||
if (id.equals(r.getStringID()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getRoleNameFromID(String id, MessageReceivedEvent event) {
|
||||
IRole role = getRoleFromID(id, event);
|
||||
if (role != null) {
|
||||
if (role != null)
|
||||
return role.getName();
|
||||
} else {
|
||||
else
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +67,8 @@ public class RoleUtils {
|
||||
if (lower.matches("@&[0-9]+") || lower.matches("[0-9]+")) {
|
||||
final String parse = toLookFor.replaceAll("[<@&>]", "");
|
||||
IRole exists = guild.getRoleByID(Long.parseLong(toLookFor.replaceAll("[<@&>]", "")));
|
||||
if (exists != null) {
|
||||
if (exists != null)
|
||||
return exists.getLongID();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,9 +76,8 @@ public class RoleUtils {
|
||||
List<IRole> rs = guild.getRoles();
|
||||
roles.addAll(rs.stream().filter(r -> r.getName().equalsIgnoreCase(lower)).collect(Collectors.toList()));
|
||||
roles.addAll(rs.stream().filter(r -> r.getName().toLowerCase().contains(lower)).collect(Collectors.toList()));
|
||||
if (!roles.isEmpty()) {
|
||||
if (!roles.isEmpty())
|
||||
return roles.get(0).getLongID();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,8 @@ import java.util.stream.Collectors;
|
||||
public class UserUtils {
|
||||
public static IUser getUserFromMention(String mention, MessageReceivedEvent event) {
|
||||
for (IUser u : event.getGuild().getUsers()) {
|
||||
if (mention.equalsIgnoreCase("<@" + u.getStringID() + ">") || mention.equalsIgnoreCase("<@!" + u.getStringID() + ">")) {
|
||||
if (mention.equalsIgnoreCase("<@" + u.getStringID() + ">") || mention.equalsIgnoreCase("<@!" + u.getStringID() + ">"))
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -44,9 +43,8 @@ public class UserUtils {
|
||||
if (lower.matches("@!?[0-9]+") || lower.matches("[0-9]+")) {
|
||||
final String parse = toLookFor.replaceAll("[<@!>]", "");
|
||||
IUser exists = guild.getUserByID(Long.parseLong(toLookFor.replaceAll("[<@!>]", "")));
|
||||
if (exists != null) {
|
||||
if (exists != null)
|
||||
return exists.getLongID();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +58,8 @@ public class UserUtils {
|
||||
users.addAll(us.stream().filter(u -> u.getDisplayName(guild).toLowerCase().contains(lower)).collect(Collectors.toList()));
|
||||
|
||||
|
||||
if (!users.isEmpty()) {
|
||||
if (!users.isEmpty())
|
||||
return users.get(0).getLongID();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -78,9 +75,8 @@ public class UserUtils {
|
||||
|
||||
if (toLookFor.matches("<@!?[0-9]+>")) {
|
||||
IUser u = guild.getUserByID(Long.parseUnsignedLong(toLookFor.replaceAll("[^0-9]", "")));
|
||||
if (u != null) {
|
||||
if (u != null)
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
List<IUser> users = guild.getUsers().stream()
|
||||
@@ -108,9 +104,8 @@ public class UserUtils {
|
||||
ArrayList<IUser> users = new ArrayList<>();
|
||||
for (String u : userIds) {
|
||||
IUser user = getUserFromID(u, guild);
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
users.add(user);
|
||||
}
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
@@ -76,12 +76,12 @@ public class AnnouncementEndpoint {
|
||||
a.setAnnouncementChannelId(body.getString("channel"));
|
||||
a.setAnnouncementType(AnnouncementType.fromValue(body.getString("type")));
|
||||
|
||||
if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
|
||||
if (a.getAnnouncementType().equals(AnnouncementType.COLOR))
|
||||
a.setEventColor(EventColor.fromNameOrHexOrID(body.getString("event_color")));
|
||||
}
|
||||
if (a.getAnnouncementType().equals(AnnouncementType.RECUR) || a.getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
|
||||
|
||||
if (a.getAnnouncementType().equals(AnnouncementType.RECUR) || a.getAnnouncementType().equals(AnnouncementType.SPECIFIC))
|
||||
a.setEventId(body.getString("event_id"));
|
||||
}
|
||||
|
||||
|
||||
a.setHoursBefore(body.getInt("hours"));
|
||||
a.setMinutesBefore(body.getInt("minutes"));
|
||||
@@ -256,7 +256,6 @@ public class AnnouncementEndpoint {
|
||||
response.type("application/json");
|
||||
response.status(200);
|
||||
response.body(body.toString());
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
halt(400, "Bad Request");
|
||||
|
||||
@@ -131,11 +131,11 @@ public class EventEndpoint {
|
||||
jo.put("timezone", tz);
|
||||
jo.put("summary", e.getSummary());
|
||||
jo.put("description", e.getDescription());
|
||||
if (e.getLocked() != null) {
|
||||
if (e.getLocked() != null)
|
||||
jo.put("location", e.getLocation());
|
||||
} else {
|
||||
else
|
||||
jo.put("location", "N/a");
|
||||
}
|
||||
|
||||
jo.put("color", EventColor.fromNameOrHexOrID(e.getColorId()).name());
|
||||
jo.put("isParent", !(e.getId().contains("_")));
|
||||
|
||||
@@ -216,13 +216,11 @@ public class EventEndpoint {
|
||||
end.setDateTime(new DateTime(body.getLong("epochEnd")));
|
||||
event.setEnd(end.setTimeZone(cal.getTimeZone()));
|
||||
|
||||
if (!body.getString("color").equalsIgnoreCase("NONE")) {
|
||||
event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId().toString());
|
||||
}
|
||||
if (!body.getString("color").equalsIgnoreCase("NONE"))
|
||||
event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId() + "");
|
||||
|
||||
if (!body.getString("location").equalsIgnoreCase("") || !body.getString("location").equalsIgnoreCase("N/a")) {
|
||||
if (!body.getString("location").equalsIgnoreCase("") || !body.getString("location").equalsIgnoreCase("N/a"))
|
||||
event.setLocation(body.getString("location"));
|
||||
}
|
||||
|
||||
JSONObject recur = body.getJSONObject("recurrence");
|
||||
if (recur.getBoolean("recur")) {
|
||||
@@ -254,9 +252,8 @@ public class EventEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
if (ed.shouldBeSaved()) {
|
||||
if (ed.shouldBeSaved())
|
||||
DatabaseManager.getManager().updateEventData(ed);
|
||||
}
|
||||
|
||||
service.events().update(calendarData.getCalendarId(), eventId, event).execute();
|
||||
|
||||
@@ -312,13 +309,11 @@ public class EventEndpoint {
|
||||
end.setDateTime(new DateTime(body.getLong("epochEnd")));
|
||||
event.setEnd(end.setTimeZone(cal.getTimeZone()));
|
||||
|
||||
if (!body.getString("color").equalsIgnoreCase("NONE")) {
|
||||
event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId().toString());
|
||||
}
|
||||
if (!body.getString("color").equalsIgnoreCase("NONE"))
|
||||
event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId() + "");
|
||||
|
||||
if (!body.getString("location").equalsIgnoreCase("") || !body.getString("location").equalsIgnoreCase("N/a")) {
|
||||
if (!body.getString("location").equalsIgnoreCase("") || !body.getString("location").equalsIgnoreCase("N/a"))
|
||||
event.setLocation(body.getString("location"));
|
||||
}
|
||||
|
||||
JSONObject recur = body.getJSONObject("recurrence");
|
||||
if (recur.getBoolean("recur")) {
|
||||
@@ -350,9 +345,8 @@ public class EventEndpoint {
|
||||
}
|
||||
|
||||
|
||||
if (ed.shouldBeSaved()) {
|
||||
if (ed.shouldBeSaved())
|
||||
DatabaseManager.getManager().updateEventData(ed);
|
||||
}
|
||||
|
||||
Event confirmed = service.events().insert(calendarData.getCalendarId(), event).execute();
|
||||
|
||||
|
||||
@@ -104,9 +104,8 @@ public class GuildEndpoint {
|
||||
//Find all guilds user is in...
|
||||
ArrayList<IGuild> guilds = new ArrayList<>();
|
||||
for (IGuild g : DisCalAPI.getAPI().getClient().getGuilds()) {
|
||||
if (g.getUserByID(userId) != null) {
|
||||
if (g.getUserByID(userId) != null)
|
||||
guilds.add(g);
|
||||
}
|
||||
}
|
||||
|
||||
//Get needed data
|
||||
|
||||
@@ -87,17 +87,17 @@ public class DashboardHandler {
|
||||
|
||||
DiscordAccountHandler.getHandler().appendAccount(m, request.session().id());
|
||||
|
||||
if (settings.equalsIgnoreCase("calendar")) {
|
||||
if (settings.equalsIgnoreCase("calendar"))
|
||||
response.redirect("/dashboard/guild/calendar", 301);
|
||||
} else if (settings.equalsIgnoreCase("events")) {
|
||||
else if (settings.equalsIgnoreCase("events"))
|
||||
response.redirect("/dashboard/guild/events", 301);
|
||||
} else if (settings.equalsIgnoreCase("announcements")) {
|
||||
else if (settings.equalsIgnoreCase("announcements"))
|
||||
response.redirect("/dashboard/guild/announcements", 301);
|
||||
} else if (settings.equalsIgnoreCase("rsvp")) {
|
||||
else if (settings.equalsIgnoreCase("rsvp"))
|
||||
response.redirect("/dashboard/guild/rsvp", 301);
|
||||
} else {
|
||||
else
|
||||
response.redirect("/dashboard/guild", 301);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Logger.getLogger().exception(null, "[WEB] JSON || Settings Select failed!", e, DashboardHandler.class, true);
|
||||
response.redirect("/dashboard", 301);
|
||||
@@ -155,11 +155,10 @@ public class DashboardHandler {
|
||||
IGuild guild = DisCalAPI.getAPI().getClient().getGuildByID(Long.valueOf(g.getId()));
|
||||
IRole role = guild.getRoleByID(Long.valueOf(request.queryParams("con-role")));
|
||||
|
||||
if (role.isEveryoneRole()) {
|
||||
if (role.isEveryoneRole())
|
||||
g.getSettings().setControlRole("everyone");
|
||||
} else {
|
||||
else
|
||||
g.getSettings().setControlRole(role.getStringID());
|
||||
}
|
||||
|
||||
DatabaseManager.getManager().updateSettings(g.getSettings());
|
||||
|
||||
@@ -180,12 +179,10 @@ public class DashboardHandler {
|
||||
|
||||
IGuild guild = DisCalAPI.getAPI().getClient().getGuildByID(Long.valueOf(g.getId()));
|
||||
|
||||
if (request.queryParams("discal-channel").equalsIgnoreCase("0")) {
|
||||
//All channels
|
||||
g.getSettings().setDiscalChannel("all");
|
||||
} else {
|
||||
if (request.queryParams("discal-channel").equalsIgnoreCase("0"))
|
||||
g.getSettings().setDiscalChannel("all"); //All channels
|
||||
else
|
||||
g.getSettings().setDiscalChannel(request.queryParams("discal-channel"));
|
||||
}
|
||||
|
||||
DatabaseManager.getManager().updateSettings(g.getSettings());
|
||||
|
||||
@@ -210,11 +207,10 @@ public class DashboardHandler {
|
||||
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
|
||||
|
||||
if (g.getSettings().isPatronGuild()) {
|
||||
if (request.queryParams().contains("value")) {
|
||||
if (request.queryParams().contains("value"))
|
||||
g.getSettings().setBranded(true);
|
||||
} else {
|
||||
else
|
||||
g.getSettings().setBranded(false);
|
||||
}
|
||||
|
||||
DatabaseManager.getManager().updateSettings(g.getSettings());
|
||||
}
|
||||
@@ -228,11 +224,10 @@ public class DashboardHandler {
|
||||
|
||||
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
|
||||
|
||||
if (request.queryParams().contains("value")) {
|
||||
if (request.queryParams().contains("value"))
|
||||
g.getSettings().setSimpleAnnouncements(true);
|
||||
} else {
|
||||
else
|
||||
g.getSettings().setSimpleAnnouncements(false);
|
||||
}
|
||||
|
||||
DatabaseManager.getManager().updateSettings(g.getSettings());
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ public class DiscordAccountHandler {
|
||||
} //Prevent initialization
|
||||
|
||||
public static DiscordAccountHandler getHandler() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new DiscordAccountHandler();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,8 @@ public class DiscordAccountHandler {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
if (timer != null) {
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
//Boolean/checkers
|
||||
@@ -161,10 +160,8 @@ public class DiscordAccountHandler {
|
||||
for (String id : discordAccounts.keySet()) {
|
||||
Map m = discordAccounts.get(id);
|
||||
long lastUse = (long) m.get("lastUse");
|
||||
if (System.currentTimeMillis() - lastUse > limit) {
|
||||
//Timed out, remove account info and require sign in.
|
||||
toRemove.remove(id);
|
||||
}
|
||||
if (System.currentTimeMillis() - lastUse > limit)
|
||||
toRemove.remove(id); //Timed out, remove account info and require sign in.
|
||||
}
|
||||
|
||||
for (String id : toRemove) {
|
||||
|
||||
@@ -56,13 +56,9 @@ public class ThymeleafTemplateEngine extends TemplateEngine {
|
||||
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
|
||||
templateResolver.setTemplateMode(TemplateMode.HTML);
|
||||
|
||||
templateResolver.setPrefix(
|
||||
prefix != null ? prefix : DEFAULT_PREFIX
|
||||
);
|
||||
templateResolver.setPrefix(prefix != null ? prefix : DEFAULT_PREFIX);
|
||||
|
||||
templateResolver.setSuffix(
|
||||
suffix != null ? suffix : DEFAULT_SUFFIX
|
||||
);
|
||||
templateResolver.setSuffix(suffix != null ? suffix : DEFAULT_SUFFIX);
|
||||
|
||||
templateResolver.setCacheTTLMs(DEFAULT_CACHE_TTL_MS);
|
||||
return templateResolver;
|
||||
|
||||
Reference in New Issue
Block a user