use of util.Connexion in project KaellyBot by Kaysoro.
the class ChannelLanguage method getChannelLanguages.
public static synchronized Map<Long, ChannelLanguage> getChannelLanguages() {
if (channelLanguages == null) {
channelLanguages = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT lang, id_chan FROM Channel_Language");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
long idChan = Long.parseLong(resultSet.getString("id_chan"));
Language lang = Language.valueOf(resultSet.getString("lang"));
IChannel chan = ClientConfig.DISCORD().getChannelByID(idChan);
if (chan != null && !chan.isDeleted())
channelLanguages.put(chan.getLongID(), new ChannelLanguage(lang, idChan));
else {
new ChannelLanguage(lang, idChan).removeToDatabase();
LOG.info("Chan deleted : " + idChan);
}
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("getChannlLanguages", e);
}
}
return channelLanguages;
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class ChannelLanguage method removeToDatabase.
public synchronized void removeToDatabase() {
getChannelLanguages().remove(getChannelId());
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement request = connection.prepareStatement("DELETE FROM Channel_Language WHERE id_chan = ?;");
request.setString(1, String.valueOf(getChannelId()));
request.executeUpdate();
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getChannelByID(getChannelId()).getGuild(), ClientConfig.DISCORD().getChannelByID(getChannelId()));
LOG.error("removeToDatabase", e);
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class CommandForbidden method addToDatabase.
public synchronized void addToDatabase() {
if (!isSaved) {
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO Command_Guild(id_guild, name_command) VALUES(?, ?);");
preparedStatement.setString(1, getGuild().getId());
preparedStatement.setString(2, getCommand().getName());
preparedStatement.executeUpdate();
getGuild().getForbiddenCommands().put(getCommand().getName(), this);
isSaved = true;
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getGuildByID(Long.parseLong(getGuild().getId())));
LOG.error("addToDatabase", e);
}
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class CommandForbidden method getForbiddenCommands.
public static synchronized Map<String, CommandForbidden> getForbiddenCommands(Guild g) {
Map<String, CommandForbidden> commands = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT name_command FROM Command_Guild WHERE id_guild = (?);");
query.setString(1, g.getId());
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
String commandName = resultSet.getString("name_command");
CommandForbidden tmp = new CommandForbidden(CommandManager.getCommand(commandName), g, true);
commands.put(tmp.getCommand().getName(), tmp);
}
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getGuildByID(Long.parseLong(g.getId())));
LOG.error("getForbiddenCommands", e);
}
return commands;
}
Aggregations