Reformat database class and queries using text blocks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
546637c188
commit
009fec3be3
@ -12,26 +12,22 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DatabaseSource
|
public class DatabaseSource {
|
||||||
{
|
|
||||||
|
|
||||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseSource.class);
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseSource.class);
|
||||||
private static final String JDBC_URL = "jdbc:sqlite:%path%";
|
private static final String JDBC_URL = "jdbc:sqlite:%path%";
|
||||||
private Connection dbConnection = null;
|
private Connection dbConnection = null;
|
||||||
private final String dbPath;
|
private final String dbPath;
|
||||||
|
|
||||||
public DatabaseSource(String dbPath)
|
public DatabaseSource(String dbPath) {
|
||||||
{
|
|
||||||
this.dbPath = dbPath;
|
this.dbPath = dbPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logException(SQLException e)
|
private void logException(SQLException e) {
|
||||||
{
|
|
||||||
LOGGER.error("Database Exception", e);
|
LOGGER.error("Database Exception", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect()
|
public boolean connect() {
|
||||||
{
|
|
||||||
String url = JDBC_URL.replace("%path%", dbPath);
|
String url = JDBC_URL.replace("%path%", dbPath);
|
||||||
|
|
||||||
if (!close()) return false;
|
if (!close()) return false;
|
||||||
@ -48,13 +44,10 @@ public class DatabaseSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean close()
|
public boolean close() {
|
||||||
{
|
if (dbConnection != null) {
|
||||||
if (dbConnection != null)
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
if(!dbConnection.isClosed())
|
if (!dbConnection.isClosed()) {
|
||||||
{
|
|
||||||
dbConnection.close();
|
dbConnection.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -94,38 +87,39 @@ public class DatabaseSource
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//todo: javadocs
|
//todo: javadocs
|
||||||
|
public boolean initDb() {
|
||||||
public boolean initDb()
|
|
||||||
{
|
|
||||||
List<String> newTables = new ArrayList<>();
|
List<String> newTables = new ArrayList<>();
|
||||||
|
|
||||||
newTables.add("CREATE TABLE IF NOT EXISTS pending_disabled_messages (" +
|
newTables.add("""
|
||||||
"guild_id TEXT NOT NULL, " +
|
CREATE TABLE IF NOT EXISTS pending_disabled_messages (
|
||||||
"channel_id TEXT NOT NULL," +
|
guild_id TEXT NOT NULL,
|
||||||
"message_id TEXT NOT NULL," +
|
channel_id TEXT NOT NULL,
|
||||||
"expiry_timestamp TEXT NOT NULL " +
|
message_id TEXT NOT NULL,
|
||||||
");");
|
expiry_timestamp TEXT NOT NULL);
|
||||||
|
""");
|
||||||
|
|
||||||
newTables.add("CREATE TABLE IF NOT EXISTS command_runners (" +
|
newTables.add("""
|
||||||
"guild_id TEXT NOT NULL, " +
|
CREATE TABLE IF NOT EXISTS command_runners (
|
||||||
"channel_id TEXT NOT NULL," + // channel the command was run in
|
guild_id TEXT NOT NULL,
|
||||||
"message_id TEXT NOT NULL," + // message id of the bot's response
|
channel_id TEXT NOT NULL,
|
||||||
"user_id TEXT NOT NULL, " + // user who ran the command
|
message_id TEXT NOT NULL,
|
||||||
"channel_type TEXT NOT NULL" + // channel type (PRIVATE, FORUM, ...)
|
user_id TEXT NOT NULL,
|
||||||
");");
|
channel_type TEXT NOT NULL);
|
||||||
|
""");
|
||||||
|
|
||||||
newTables.add("CREATE TABLE IF NOT EXISTS urban_dictionary (" +
|
newTables.add("""
|
||||||
"message_id TEXT NOT NULL, " + // message id of the bot's response
|
CREATE TABLE IF NOT EXISTS urban_dictionary (
|
||||||
"page INTEGER NOT NULL," + // page that we are currently on
|
message_id TEXT NOT NULL,
|
||||||
"meanings TEXT NOT NULL," + // list of all meanings, serialized and encoded
|
page INTEGER NOT NULL,
|
||||||
"examples TEXT NOT NULL, " + // list of all examples, serialized and encoded
|
meanings TEXT NOT NULL,
|
||||||
"contributors TEXT NOT NULL, " + // list of all contributors, serialized and encoded
|
examples TEXT NOT NULL,
|
||||||
"dates TEXT NOT NULL, " + // list of all submission dates, serialized and encoded
|
contributors TEXT NOT NULL,
|
||||||
"term TEXT NOT NULL" + // the term that was searched
|
dates TEXT NOT NULL,
|
||||||
");");
|
term TEXT NOT NULL
|
||||||
|
);
|
||||||
|
""");
|
||||||
|
|
||||||
for(String sql : newTables)
|
for (String sql : newTables) {
|
||||||
{
|
|
||||||
try (Statement stmt = dbConnection.createStatement()) {
|
try (Statement stmt = dbConnection.createStatement()) {
|
||||||
// execute the statement
|
// execute the statement
|
||||||
stmt.execute(sql);
|
stmt.execute(sql);
|
||||||
@ -138,14 +132,12 @@ public class DatabaseSource
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean trackRanCommandReply(Message message, User user)
|
public boolean trackRanCommandReply(Message message, User user) {
|
||||||
{
|
|
||||||
String userId = user.getId();
|
String userId = user.getId();
|
||||||
String guildId;
|
String guildId;
|
||||||
|
|
||||||
ChannelType channelType = message.getChannelType();
|
ChannelType channelType = message.getChannelType();
|
||||||
if(!(channelType.isGuild()))
|
if (!(channelType.isGuild())) {
|
||||||
{
|
|
||||||
guildId = userId;
|
guildId = userId;
|
||||||
} else {
|
} else {
|
||||||
guildId = message.getGuild().getId();
|
guildId = message.getGuild().getId();
|
||||||
@ -155,12 +147,13 @@ public class DatabaseSource
|
|||||||
String messageId = message.getId();
|
String messageId = message.getId();
|
||||||
|
|
||||||
|
|
||||||
String query = "INSERT INTO command_runners " +
|
String query = """
|
||||||
"(guild_id, channel_id, message_id, user_id, channel_type) VALUES " +
|
INSERT INTO command_runners
|
||||||
" (?, ?, ?, ?, ?);";
|
(guild_id, channel_id, message_id, user_id, channel_type) VALUES
|
||||||
|
(?, ?, ?, ?, ?);
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, guildId);
|
preparedStatement.setString(1, guildId);
|
||||||
preparedStatement.setString(2, channelId);
|
preparedStatement.setString(2, channelId);
|
||||||
preparedStatement.setString(3, messageId);
|
preparedStatement.setString(3, messageId);
|
||||||
@ -170,34 +163,31 @@ public class DatabaseSource
|
|||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e)
|
} catch (SQLException e) {
|
||||||
{
|
|
||||||
logException(e);
|
logException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUserTrackedFor(String userId, String messageId)
|
public boolean isUserTrackedFor(String userId, String messageId) {
|
||||||
{
|
|
||||||
String trackedUserId = getTrackedReplyUserId(messageId);
|
String trackedUserId = getTrackedReplyUserId(messageId);
|
||||||
if (trackedUserId == null) return false;
|
if (trackedUserId == null) return false;
|
||||||
return userId.equals(trackedUserId);
|
return userId.equals(trackedUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelType getTrackedMessageChannelType(String messageId)
|
public ChannelType getTrackedMessageChannelType(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT channel_type " +
|
""SELECT channel_type
|
||||||
"FROM command_runners " +
|
FROM command_runners
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
String channelTypeName = resultSet.getString("channel_type");
|
String channelTypeName = resultSet.getString("channel_type");
|
||||||
return ChannelType.valueOf(channelTypeName);
|
return ChannelType.valueOf(channelTypeName);
|
||||||
}
|
}
|
||||||
@ -210,19 +200,18 @@ public class DatabaseSource
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrackedReplyUserId(String messageId)
|
public String getTrackedReplyUserId(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT user_id " +
|
""SELECT user_id
|
||||||
"FROM command_runners " +
|
FROM command_runners
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("user_id");
|
return resultSet.getString("user_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,15 +222,13 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean queueDisabling(Message message)
|
public boolean queueDisabling(Message message) {
|
||||||
{
|
|
||||||
String messageId = message.getId();
|
String messageId = message.getId();
|
||||||
String channelId = message.getChannel().getId();
|
String channelId = message.getChannel().getId();
|
||||||
String guildId;
|
String guildId;
|
||||||
|
|
||||||
ChannelType channelType = message.getChannelType();
|
ChannelType channelType = message.getChannelType();
|
||||||
if(!(channelType.isGuild()))
|
if (!(channelType.isGuild())) {
|
||||||
{
|
|
||||||
guildId = "PRIVATE";
|
guildId = "PRIVATE";
|
||||||
} else {
|
} else {
|
||||||
guildId = message.getGuild().getId();
|
guildId = message.getGuild().getId();
|
||||||
@ -252,12 +239,13 @@ public class DatabaseSource
|
|||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Cache.getExpiryTimestampFormat());
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Cache.getExpiryTimestampFormat());
|
||||||
String expiryTimeFormatted = dateTimeFormatter.format(expiryTime);
|
String expiryTimeFormatted = dateTimeFormatter.format(expiryTime);
|
||||||
|
|
||||||
String query = "INSERT INTO pending_disabled_messages " +
|
String query = """
|
||||||
"(guild_id, channel_id, message_id, expiry_timestamp) VALUES " +
|
INSERT INTO pending_disabled_messages
|
||||||
" (?, ?, ?, ?);";
|
(guild_id, channel_id, message_id, expiry_timestamp) VALUES
|
||||||
|
(?, ?, ?, ?);
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, guildId);
|
preparedStatement.setString(1, guildId);
|
||||||
preparedStatement.setString(2, channelId);
|
preparedStatement.setString(2, channelId);
|
||||||
preparedStatement.setString(3, messageId);
|
preparedStatement.setString(3, messageId);
|
||||||
@ -266,27 +254,25 @@ public class DatabaseSource
|
|||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e)
|
} catch (SQLException e) {
|
||||||
{
|
|
||||||
logException(e);
|
logException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getQueuedExpiringMessages()
|
public List<String> getQueuedExpiringMessages() {
|
||||||
{
|
|
||||||
List<String> messages = new ArrayList<>();
|
List<String> messages = new ArrayList<>();
|
||||||
|
|
||||||
String query = "SELECT message_id " +
|
String query = """
|
||||||
"FROM pending_disabled_messages ";
|
SELECT message_id
|
||||||
|
FROM pending_disabled_messages;
|
||||||
|
""";
|
||||||
|
|
||||||
try (Statement statement = dbConnection.createStatement())
|
try (Statement statement = dbConnection.createStatement()) {
|
||||||
{
|
|
||||||
ResultSet resultSet = statement.executeQuery(query);
|
ResultSet resultSet = statement.executeQuery(query);
|
||||||
if (resultSet.isClosed()) return messages;
|
if (resultSet.isClosed()) return messages;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
messages.add(resultSet.getString("message_id"));
|
messages.add(resultSet.getString("message_id"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -296,38 +282,31 @@ public class DatabaseSource
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean untrackExpiredMessage(String messageId)
|
public boolean untrackExpiredMessage(String messageId) {
|
||||||
{
|
|
||||||
String query = "DELETE FROM pending_disabled_messages WHERE message_id = ?;";
|
String query = "DELETE FROM pending_disabled_messages WHERE message_id = ?;";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
} catch (SQLException e)
|
} catch (SQLException e) {
|
||||||
{
|
|
||||||
logException(e);
|
logException(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = "DELETE FROM command_runners WHERE message_id = ?;";
|
query = "DELETE FROM command_runners WHERE message_id = ?;";
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
} catch (SQLException e)
|
} catch (SQLException e) {
|
||||||
{
|
|
||||||
logException(e);
|
logException(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = "DELETE FROM urban_dictionary WHERE message_id = ?;";
|
query = "DELETE FROM urban_dictionary WHERE message_id = ?;";
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
} catch (SQLException e)
|
} catch (SQLException e) {
|
||||||
{
|
|
||||||
logException(e);
|
logException(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -335,19 +314,18 @@ public class DatabaseSource
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQueuedExpiringMessageExpiryDate(String messageId)
|
public String getQueuedExpiringMessageExpiryDate(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT expiry_timestamp " +
|
SELECT expiry_timestamp
|
||||||
"FROM pending_disabled_messages " +
|
FROM pending_disabled_messages
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("expiry_timestamp");
|
return resultSet.getString("expiry_timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,19 +336,18 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQueuedExpiringMessageChannel(String messageId)
|
public String getQueuedExpiringMessageChannel(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT channel_id " +
|
SELECT channel_id
|
||||||
"FROM pending_disabled_messages " +
|
FROM pending_disabled_messages
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("channel_id");
|
return resultSet.getString("channel_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,19 +358,18 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQueuedExpiringMessageGuild(String messageId)
|
public String getQueuedExpiringMessageGuild(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT guild_id " +
|
SELECT guild_id
|
||||||
"FROM pending_disabled_messages " +
|
FROM pending_disabled_messages
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("guild_id");
|
return resultSet.getString("guild_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,15 +382,15 @@ public class DatabaseSource
|
|||||||
|
|
||||||
public boolean trackUrban(String meanings, String examples,
|
public boolean trackUrban(String meanings, String examples,
|
||||||
String contributors, String dates,
|
String contributors, String dates,
|
||||||
Message message, String term)
|
Message message, String term) {
|
||||||
{
|
|
||||||
|
|
||||||
String query = "INSERT INTO urban_dictionary " +
|
String query = """
|
||||||
"(message_id, page, meanings, examples, contributors, dates, term) VALUES " +
|
INSERT INTO urban_dictionary
|
||||||
" (?, ?, ?, ?, ?, ?, ?);";
|
(message_id, page, meanings, examples, contributors, dates, term) VALUES
|
||||||
|
(?, ?, ?, ?, ?, ?, ?);
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, message.getId());
|
preparedStatement.setString(1, message.getId());
|
||||||
preparedStatement.setInt(2, 0);
|
preparedStatement.setInt(2, 0);
|
||||||
preparedStatement.setString(3, meanings);
|
preparedStatement.setString(3, meanings);
|
||||||
@ -426,27 +402,25 @@ public class DatabaseSource
|
|||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e)
|
} catch (SQLException e) {
|
||||||
{
|
|
||||||
logException(e);
|
logException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUrbanPage(String messageId)
|
public int getUrbanPage(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT page " +
|
SELECT page
|
||||||
"FROM urban_dictionary " +
|
FROM urban_dictionary
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return 0;
|
if (resultSet.isClosed()) return 0;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getInt("page");
|
return resultSet.getInt("page");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,19 +431,18 @@ public class DatabaseSource
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrbanMeanings(String messageId)
|
public String getUrbanMeanings(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT meanings " +
|
SELECT meanings
|
||||||
"FROM urban_dictionary " +
|
FROM urban_dictionary
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("meanings");
|
return resultSet.getString("meanings");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,19 +453,18 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrbanExamples(String messageId)
|
public String getUrbanExamples(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT examples " +
|
SELECT examples
|
||||||
"FROM urban_dictionary " +
|
FROM urban_dictionary
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("examples");
|
return resultSet.getString("examples");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,19 +475,18 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrbanContributors(String messageId)
|
public String getUrbanContributors(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT contributors " +
|
SELECT contributors
|
||||||
"FROM urban_dictionary " +
|
FROM urban_dictionary
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("contributors");
|
return resultSet.getString("contributors");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,19 +497,18 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrbanDates(String messageId)
|
public String getUrbanDates(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT dates " +
|
SELECT dates
|
||||||
"FROM urban_dictionary " +
|
FROM urban_dictionary
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("dates");
|
return resultSet.getString("dates");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,19 +519,18 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrbanTerm(String messageId)
|
public String getUrbanTerm(String messageId) {
|
||||||
{
|
String query = """
|
||||||
String query = "SELECT term " +
|
SELECT term
|
||||||
"FROM urban_dictionary " +
|
FROM urban_dictionary
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, messageId);
|
preparedStatement.setString(1, messageId);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
if (resultSet.isClosed()) return null;
|
if (resultSet.isClosed()) return null;
|
||||||
while(resultSet.next())
|
while (resultSet.next()) {
|
||||||
{
|
|
||||||
return resultSet.getString("term");
|
return resultSet.getString("term");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,14 +541,14 @@ public class DatabaseSource
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setUrbanPage(String messageId, int page)
|
public boolean setUrbanPage(String messageId, int page) {
|
||||||
{
|
String query = """
|
||||||
String query = "UPDATE urban_dictionary " +
|
UPDATE urban_dictionary
|
||||||
"SET page = ? " +
|
SET page = ?
|
||||||
"WHERE message_id = ?;";
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setInt(1, page);
|
preparedStatement.setInt(1, page);
|
||||||
preparedStatement.setString(2, messageId);
|
preparedStatement.setString(2, messageId);
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
@ -593,19 +562,19 @@ public class DatabaseSource
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean resetExpiryTimestamp(String messageId)
|
public boolean resetExpiryTimestamp(String messageId) {
|
||||||
{
|
|
||||||
LocalDateTime expiryTime = LocalDateTime.now().plusSeconds(Cache.getExpiryTimeSeconds());
|
LocalDateTime expiryTime = LocalDateTime.now().plusSeconds(Cache.getExpiryTimeSeconds());
|
||||||
|
|
||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Cache.getExpiryTimestampFormat());
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Cache.getExpiryTimestampFormat());
|
||||||
String expiryTimeFormatted = dateTimeFormatter.format(expiryTime);
|
String expiryTimeFormatted = dateTimeFormatter.format(expiryTime);
|
||||||
|
|
||||||
String query = "UPDATE pending_disabled_messages " +
|
String query = """
|
||||||
"SET expiry_timestamp = ? " +
|
UPDATE pending_disabled_messages
|
||||||
"WHERE message_id = ?;";
|
SET expiry_timestamp = ?
|
||||||
|
WHERE message_id = ?;
|
||||||
|
""";
|
||||||
|
|
||||||
try(PreparedStatement preparedStatement = dbConnection.prepareStatement(query))
|
try (PreparedStatement preparedStatement = dbConnection.prepareStatement(query)) {
|
||||||
{
|
|
||||||
preparedStatement.setString(1, expiryTimeFormatted);
|
preparedStatement.setString(1, expiryTimeFormatted);
|
||||||
preparedStatement.setString(2, messageId);
|
preparedStatement.setString(2, messageId);
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
|
Loading…
Reference in New Issue
Block a user