mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-04-24 18:38:54 -05:00
Get bot responding again. Fix issue with snowflakes.
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ public class AnnouncementCreator {
|
||||
public Announcement init(MessageCreateEvent e, GuildSettings settings) {
|
||||
if (!hasAnnouncement(settings.getGuildID())) {
|
||||
Announcement a = new Announcement(settings.getGuildID());
|
||||
a.setAnnouncementChannelId(e.getMessage().getChannel().block().getId().toString());
|
||||
a.setAnnouncementChannelId(e.getMessage().getChannel().block().getId().asString());
|
||||
|
||||
if (PermissionChecker.botHasMessageManagePerms(e)) {
|
||||
Message msg = MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Announcement.Create.Init", settings), AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), e);
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ public class AnnouncementMessageFormatter {
|
||||
if (guild != null)
|
||||
channel = (TextChannel)guild.getChannelById(Snowflake.of(announcement.getAnnouncementChannelId())).block();
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger().exception(null, "An error occurred when looking for announcement channel! | Announcement: " + announcement.getAnnouncementId() + " | TYPE: " + announcement.getAnnouncementType() + " | Guild: " + announcement.getGuildId().toString(), e, AnnouncementMessageFormatter.class);
|
||||
Logger.getLogger().exception(null, "An error occurred when looking for announcement channel! | Announcement: " + announcement.getAnnouncementId() + " | TYPE: " + announcement.getAnnouncementType() + " | Guild: " + announcement.getGuildId().asString(), e, AnnouncementMessageFormatter.class);
|
||||
}
|
||||
|
||||
if (channel == null) {
|
||||
|
||||
+14
-23
@@ -15,59 +15,50 @@ import java.util.Arrays;
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal
|
||||
*/
|
||||
@SuppressWarnings({"unused", "ToArrayCallWithZeroLengthArrayArgument", "ConstantConditions", "OptionalGetWithoutIsPresent"})
|
||||
@SuppressWarnings({"unused", "ToArrayCallWithZeroLengthArrayArgument", "OptionalGetWithoutIsPresent"})
|
||||
class CommandListener {
|
||||
private static CommandExecutor cmd;
|
||||
|
||||
/**
|
||||
* Creates a new CommandListener listener.
|
||||
*
|
||||
* @param _cmd The CommandExecutor instance to use.
|
||||
*/
|
||||
CommandListener(CommandExecutor _cmd) {
|
||||
cmd = _cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for command validity and calls the command executor if valid.
|
||||
*
|
||||
* @param event The event received to check for a command.
|
||||
*/
|
||||
public static void onMessageEvent(MessageCreateEvent event) {
|
||||
static void onMessageEvent(MessageCreateEvent event) {
|
||||
try {
|
||||
if (event.getMessage().getContent().isPresent() && event.getMessage().getContent().get().isEmpty() && event.getMember().isPresent() && !event.getMember().get().isBot()) {
|
||||
if (event.getMessage().getContent().isPresent() && !event.getMessage().getContent().get().isEmpty() && event.getMember().isPresent() && !event.getMember().get().isBot()) {
|
||||
String content = event.getMessage().getContent().get();
|
||||
//Message is a valid guild message (not DM and not from a bot). Check if in correct channel.
|
||||
GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuild().block().getId());
|
||||
if (event.getMessage().getContent().get().startsWith(settings.getPrefix())) {
|
||||
GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuildId().get());
|
||||
if (content.startsWith(settings.getPrefix())) {
|
||||
if (PermissionChecker.isCorrectChannel(event)) {
|
||||
//Prefixed with ! which should mean it is a command, convert and confirm.
|
||||
String[] argsOr = event.getMessage().getContent().get().split("\\s+");
|
||||
String[] argsOr = content.split("\\s+");
|
||||
if (argsOr.length > 1) {
|
||||
ArrayList<String> argsOr2 = new ArrayList<>(Arrays.asList(argsOr).subList(1, argsOr.length));
|
||||
String[] args = argsOr2.toArray(new String[argsOr2.size()]);
|
||||
|
||||
String command = argsOr[0].replace(settings.getPrefix(), "");
|
||||
cmd.issueCommand(command, args, event, settings);
|
||||
CommandExecutor.getExecutor().issueCommand(command, args, event, settings);
|
||||
} else if (argsOr.length == 1) {
|
||||
//Only command... no args.
|
||||
cmd.issueCommand(argsOr[0].replace(settings.getPrefix(), ""), new String[0], event, settings);
|
||||
CommandExecutor.getExecutor().issueCommand(argsOr[0].replace(settings.getPrefix(), ""), new String[0], event, settings);
|
||||
}
|
||||
}
|
||||
} else if (!event.getMessage().mentionsEveryone() && !event.getMessage().getContent().get().contains("@here") && (event.getMessage().toString().startsWith("<@" + DisCalClient.getClient().getSelfId().get() + ">") || event.getMessage().toString().startsWith("<@!" + DisCalClient.getClient().getSelfId().get() + ">"))) {
|
||||
} else if (!event.getMessage().mentionsEveryone() && !content.contains("@here") && (content.startsWith("<@" + DisCalClient.getClient().getSelfId().get().asString() + ">") || content.startsWith("<@!" + DisCalClient.getClient().getSelfId().get().asString() + ">"))) {
|
||||
if (PermissionChecker.isCorrectChannel(event)) {
|
||||
String[] argsOr = event.getMessage().getContent().get().split("\\s+");
|
||||
String[] argsOr = content.split("\\s+");
|
||||
if (argsOr.length > 2) {
|
||||
ArrayList<String> argsOr2 = new ArrayList<>(Arrays.asList(argsOr).subList(2, argsOr.length));
|
||||
String[] args = argsOr2.toArray(new String[argsOr2.size()]);
|
||||
|
||||
String command = argsOr[1];
|
||||
cmd.issueCommand(command, args, event, settings);
|
||||
CommandExecutor.getExecutor().issueCommand(command, args, event, settings);
|
||||
} else if (argsOr.length == 2) {
|
||||
//No args...
|
||||
cmd.issueCommand(argsOr[1], new String[0], event, settings);
|
||||
CommandExecutor.getExecutor().issueCommand(argsOr[1], new String[0], event, settings);
|
||||
} else if (argsOr.length == 1) {
|
||||
//Only disCal mentioned...
|
||||
cmd.issueCommand("DisCal", new String[0], event, settings);
|
||||
CommandExecutor.getExecutor().issueCommand("DisCal", new String[0], event, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,7 @@ import org.dreamexposure.discal.core.object.event.RsvpData;
|
||||
import org.dreamexposure.discal.core.object.web.UserAPIAccount;
|
||||
import org.dreamexposure.novautils.database.MySQL;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -240,7 +236,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + dataTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, settings.getGuildID().toString());
|
||||
statement.setString(1, settings.getGuildID().asString());
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
boolean hasStuff = res.next();
|
||||
@@ -322,7 +318,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + calendarTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, calData.getGuildId().toString());
|
||||
statement.setString(1, calData.getGuildId().asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -614,7 +610,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + dataTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -661,7 +657,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + calendarTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -689,7 +685,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + calendarTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -717,7 +713,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + calendarTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -777,7 +773,7 @@ public class DatabaseManager {
|
||||
String query = "SELECT * FROM " + eventTableName + " WHERE GUILD_ID= ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
while (res.next()) {
|
||||
@@ -804,7 +800,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + rsvpTableName + " WHERE GUILD_ID= ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -885,7 +881,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "SELECT * FROM " + announcementTableName + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query);
|
||||
statement.setString(1, guildId.toString());
|
||||
statement.setString(1, guildId.asString());
|
||||
|
||||
ResultSet res = statement.executeQuery();
|
||||
|
||||
@@ -1078,7 +1074,7 @@ public class DatabaseManager {
|
||||
String announcementTableName = String.format("%sannouncements", databaseInfo.getPrefix());
|
||||
|
||||
PreparedStatement stmt = databaseInfo.getConnection().prepareStatement("SELECT * FROM " + announcementTableName + " WHERE ENABLED = 1 AND GUILD_ID = ?");
|
||||
stmt.setString(1, guildId.toString());
|
||||
stmt.setString(1, guildId.asString());
|
||||
ResultSet res = stmt.executeQuery();
|
||||
|
||||
while (res.next()) {
|
||||
@@ -1168,7 +1164,7 @@ public class DatabaseManager {
|
||||
String query = "DELETE FROM " + announcementTableName + " WHERE EVENT_ID = ? AND GUILD_ID = ? AND ANNOUNCEMENT_TYPE = ?";
|
||||
PreparedStatement preparedStmt = databaseInfo.getConnection().prepareStatement(query);
|
||||
preparedStmt.setString(1, eventId);
|
||||
preparedStmt.setString(2, guildId.toString());
|
||||
preparedStmt.setString(2, guildId.asString());
|
||||
preparedStmt.setString(3, AnnouncementType.SPECIFIC.name());
|
||||
|
||||
preparedStmt.execute();
|
||||
@@ -1212,7 +1208,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "DELETE FROM " + eventTable + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement preparedStmt = databaseInfo.getConnection().prepareStatement(query);
|
||||
preparedStmt.setString(1, guildId.toString());
|
||||
preparedStmt.setString(1, guildId.asString());
|
||||
|
||||
preparedStmt.execute();
|
||||
preparedStmt.close();
|
||||
@@ -1231,7 +1227,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "DELETE FROM " + announcementTable + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement preparedStmt = databaseInfo.getConnection().prepareStatement(query);
|
||||
preparedStmt.setString(1, guildId.toString());
|
||||
preparedStmt.setString(1, guildId.asString());
|
||||
|
||||
preparedStmt.execute();
|
||||
preparedStmt.close();
|
||||
@@ -1250,7 +1246,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "DELETE FROM " + rsvpTable + " WHERE GUILD_ID = ?";
|
||||
PreparedStatement preparedStmt = databaseInfo.getConnection().prepareStatement(query);
|
||||
preparedStmt.setString(1, guildId.toString());
|
||||
preparedStmt.setString(1, guildId.asString());
|
||||
|
||||
preparedStmt.execute();
|
||||
preparedStmt.close();
|
||||
@@ -1269,7 +1265,7 @@ public class DatabaseManager {
|
||||
|
||||
String query = "DELETE FROM " + calendarTable + " WHERE GUILD_ID = ? AND CALENDAR_ADDRESS = ?";
|
||||
PreparedStatement preparedStmt = databaseInfo.getConnection().prepareStatement(query);
|
||||
preparedStmt.setString(1, data.getGuildId().toString());
|
||||
preparedStmt.setString(1, data.getGuildId().asString());
|
||||
preparedStmt.setString(2, data.getCalendarAddress());
|
||||
|
||||
preparedStmt.execute();
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Collections;
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class RsvpData {
|
||||
private final Snowflake guildId;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ChannelUtils {
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
|
||||
for (GuildChannel c : event.getGuild().block().getChannels().toIterable()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().toString().equals(nameOrId))
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -34,7 +34,7 @@ public class ChannelUtils {
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
|
||||
for (GuildChannel c : guild.getChannels().toIterable()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().toString().equals(nameOrId))
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -52,7 +52,7 @@ public class ChannelUtils {
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
|
||||
for (GuildChannel c : event.getGuild().block().getChannels().toIterable()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().toString().equals(nameOrId))
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
@@ -69,7 +69,7 @@ public class ChannelUtils {
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
|
||||
for (GuildChannel c : guild.getChannels().toIterable()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().toString().equals(nameOrId))
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
@@ -86,7 +86,7 @@ public class ChannelUtils {
|
||||
nameOrId = nameOrId.replace("#", "");
|
||||
|
||||
for (GuildChannel c : guild.getChannels().toIterable()) {
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().toString().equals(nameOrId))
|
||||
if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId))
|
||||
return c.getName();
|
||||
}
|
||||
return "ERROR";
|
||||
|
||||
@@ -25,7 +25,7 @@ public class GuildUtils {
|
||||
|
||||
for (Guild g : client.getGuilds().toIterable()) {
|
||||
for (Member m : g.getMembers().toIterable()) {
|
||||
if (m.getId().toString().equals(userId)) {
|
||||
if (m.getId().asString().equals(userId)) {
|
||||
WebGuild wg = new WebGuild().fromGuild(g);
|
||||
wg.setManageServer(PermissionChecker.hasManageServerRole(m));
|
||||
wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, m));
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PermissionChecker {
|
||||
Role role = null;
|
||||
|
||||
for (Role r : event.getMessage().getGuild().block().getRoles().toIterable()) {
|
||||
if (r.getId().toString().equals(roleId)) {
|
||||
if (r.getId().asString().equals(roleId)) {
|
||||
role = r;
|
||||
break;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class PermissionChecker {
|
||||
|
||||
if (role != null) {
|
||||
for (Role r : event.getGuild().block().getMemberById(sender.getId()).block().getRoles().toIterable()) {
|
||||
if (r.getId().toString().equals(role.getId().toString()) || r.getPosition().block() > role.getPosition().block())
|
||||
if (r.getId().asString().equals(role.getId().asString()) || r.getPosition().block() > role.getPosition().block())
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class PermissionChecker {
|
||||
Role role = null;
|
||||
|
||||
for (Role r : guild.getRoles().toIterable()) {
|
||||
if (r.getId().toString().equals(roleId)) {
|
||||
if (r.getId().asString().equals(roleId)) {
|
||||
role = r;
|
||||
break;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class PermissionChecker {
|
||||
|
||||
GuildChannel channel = null;
|
||||
for (GuildChannel c : event.getMessage().getGuild().block().getChannels().toIterable()) {
|
||||
if (c.getId().toString().equals(settings.getDiscalChannel())) {
|
||||
if (c.getId().asString().equals(settings.getDiscalChannel())) {
|
||||
channel = c;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.stream.Collectors;
|
||||
public class RoleUtils {
|
||||
public static Role getRoleFromMention(String mention, MessageCreateEvent event) {
|
||||
for (Role r : event.getMessage().getGuild().block().getRoles().toIterable()) {
|
||||
if (mention.equalsIgnoreCase("<@&" + r.getId().toString() + ">") || mention.equalsIgnoreCase("<@&!" + r.getId().toString() + ">"))
|
||||
if (mention.equalsIgnoreCase("<@&" + r.getId().asString() + ">") || mention.equalsIgnoreCase("<@&!" + r.getId().asString() + ">"))
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
@@ -27,7 +27,7 @@ public class RoleUtils {
|
||||
|
||||
public static Role getRoleFromID(String id, MessageCreateEvent event) {
|
||||
for (Role r : event.getMessage().getGuild().block().getRoles().toIterable()) {
|
||||
if (id.equals(r.getId().toString()) || id.equals(r.getName()))
|
||||
if (id.equals(r.getId().asString()) || id.equals(r.getName()))
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
@@ -35,7 +35,7 @@ public class RoleUtils {
|
||||
|
||||
public static Role getRoleFromID(String id, Guild guild) {
|
||||
for (Role r : guild.getRoles().toIterable()) {
|
||||
if (id.equalsIgnoreCase(r.getId().toString()) || id.equals(r.getName()))
|
||||
if (id.equalsIgnoreCase(r.getId().asString()) || id.equals(r.getName()))
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
@@ -43,7 +43,7 @@ public class RoleUtils {
|
||||
|
||||
public static boolean roleExists(String id, MessageCreateEvent event) {
|
||||
for (Role r : event.getMessage().getGuild().block().getRoles().toIterable()) {
|
||||
if (id.equals(r.getId().toString()))
|
||||
if (id.equals(r.getId().asString()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -51,7 +51,7 @@ public class RoleUtils {
|
||||
|
||||
public static boolean roleExists(String id, Guild guild) {
|
||||
for (Role r : guild.getRoles().toIterable()) {
|
||||
if (id.equals(r.getId().toString()))
|
||||
if (id.equals(r.getId().asString()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.stream.Collectors;
|
||||
public class UserUtils {
|
||||
public static Member getUserFromMention(String mention, MessageCreateEvent event) {
|
||||
for (Member u : event.getGuild().block().getMembers().toIterable()) {
|
||||
if (mention.equalsIgnoreCase("<@" + u.getId().toString() + ">") || mention.equalsIgnoreCase("<@!" + u.getId().toString() + ">"))
|
||||
if (mention.equalsIgnoreCase("<@" + u.getId().asString() + ">") || mention.equalsIgnoreCase("<@!" + u.getId().asString() + ">"))
|
||||
return u;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class UserUtils {
|
||||
|
||||
List<Member> users = guild.getMembers().toStream()
|
||||
.filter(u -> u.getUsername().toLowerCase().contains(lower)
|
||||
|| u.getUsername().equalsIgnoreCase(lower) || u.getId().toString().equals(lower)
|
||||
|| u.getUsername().equalsIgnoreCase(lower) || u.getId().asString().equals(lower)
|
||||
|| u.getDisplayName().toLowerCase().contains(lower)
|
||||
|| u.getDisplayName().equalsIgnoreCase(lower))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Reference in New Issue
Block a user