use of sx.blah.discord.handle.obj.IChannel in project KaellyBot by Kaysoro.
the class AlmanaxCalendar method start.
public static void start() {
if (!isStarted) {
isStarted = true;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
long firstDelay = LocalDateTime.now().until(LocalDate.now().plusDays(1).atStartOfDay().plusMinutes(1), ChronoUnit.MINUTES);
long period = TimeUnit.DAYS.toMinutes(1);
scheduler.scheduleAtFixedRate(() -> {
boolean success = false;
Map<Language, Almanax> almanax = new HashMap<>();
while (!success) try {
almanax.clear();
for (Language lg : Language.values()) almanax.put(lg, Almanax.get(lg, new Date()));
success = true;
} catch (IOException e) {
ExceptionManager.manageSilentlyIOException(e);
try {
// 5min
Thread.sleep(300000);
} catch (InterruptedException e1) {
LOG.error("start", e1);
}
}
for (AlmanaxCalendar calendar : getAlmanaxCalendars().values()) try {
IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(calendar.getChan()));
Language lg = Translator.getLanguageFrom(chan);
if (chan != null && !chan.isDeleted())
Message.sendEmbed(chan, almanax.get(lg).getMoreEmbedObject(lg));
} catch (Exception e) {
LOG.error("AlmanaxCalendar", e);
}
}, firstDelay, period, TimeUnit.MINUTES);
}
}
use of sx.blah.discord.handle.obj.IChannel in project KaellyBot by Kaysoro.
the class RSSFinder method getRSSFinders.
public static synchronized Map<String, RSSFinder> getRSSFinders() {
if (rssFinders == null) {
rssFinders = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan, last_update FROM RSS_Finder");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
String idChan = resultSet.getString("id_chan");
String idGuild = resultSet.getString("id_guild");
long lastUpdate = resultSet.getLong("last_update");
IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(idChan));
if (chan != null && !chan.isDeleted())
rssFinders.put(chan.getStringID(), new RSSFinder(chan.getGuild().getStringID(), chan.getStringID(), lastUpdate));
else {
new RSSFinder(idGuild, idChan).removeToDatabase();
LOG.info("Chan deleted : " + idChan);
}
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("getRSSFinders", e);
}
}
return rssFinders;
}
use of sx.blah.discord.handle.obj.IChannel in project KaellyBot by Kaysoro.
the class TwitterFinder method getTwitterChannels.
public static synchronized Map<Long, TwitterFinder> getTwitterChannels() {
if (twitterChannels == null) {
twitterChannels = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan FROM Twitter");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
long idChan = Long.parseLong(resultSet.getString("id_chan"));
long idGuild = Long.parseLong(resultSet.getString("id_guild"));
IChannel chan = ClientConfig.DISCORD().getChannelByID(idChan);
if (chan != null && !chan.isDeleted())
twitterChannels.put(chan.getLongID(), new TwitterFinder(idGuild, idChan));
else {
new TwitterFinder(idGuild, idChan).removeToDatabase();
LOG.info("Chan deleted : " + idChan);
}
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("getTwitterChannels", e);
}
}
return twitterChannels;
}
use of sx.blah.discord.handle.obj.IChannel in project KaellyBot by Kaysoro.
the class GuildLeaveListener method onReady.
@EventSubscriber
public void onReady(GuildLeaveEvent event) {
try {
Guild guild = Guild.getGuild(event.getGuild(), false);
if (guild != null) {
guild.removeToDatabase();
LOG.info("La guilde " + event.getGuild().getStringID() + " - " + event.getGuild().getName() + " a supprimé " + Constants.name);
for (RSSFinder finder : RSSFinder.getRSSFinders().values()) {
IChannel chan = event.getGuild().getChannelByID(Long.parseLong(finder.getChan()));
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("RSS Chan \"" + chan.getName() + "\"");
}
}
for (TwitterFinder finder : TwitterFinder.getTwitterChannels().values()) {
IChannel chan = event.getGuild().getChannelByID(finder.getChannelId());
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("Twitter Chan \"" + chan.getName() + "\"");
}
}
for (AlmanaxCalendar finder : AlmanaxCalendar.getAlmanaxCalendars().values()) {
IChannel chan = event.getGuild().getChannelByID(Long.parseLong(finder.getChan()));
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("Almanax Chan \"" + chan.getName() + "\"");
}
}
}
Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[LOSE] **" + event.getGuild().getName() + "**, -" + event.getGuild().getUsers().size() + " utilisateurs");
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
}
use of sx.blah.discord.handle.obj.IChannel in project DisCal-Discord-Bot by NovaFox161.
the class DevCommand method moduleEval.
@SuppressWarnings("all")
private void moduleEval(MessageReceivedEvent event) {
IGuild guild = event.getGuild();
IUser user = event.getAuthor();
IMessage message = event.getMessage();
IDiscordClient client = event.getClient();
IChannel channel = event.getChannel();
String input = message.getContent().substring(message.getContent().indexOf("eval") + 5).replaceAll("`", "");
Object o = null;
factory.put("guild", guild);
factory.put("channel", channel);
factory.put("user", user);
factory.put("message", message);
factory.put("command", this);
factory.put("client", client);
factory.put("builder", new EmbedBuilder());
factory.put("cUser", client.getOurUser());
try {
o = factory.eval(input);
} catch (Exception ex) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(guild.getIconURL());
em.withAuthorName("Error");
em.withDesc(ex.getMessage());
em.withFooterText("Eval failed");
em.withColor(56, 138, 237);
Message.sendMessage(em.build(), channel);
return;
}
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(guild.getIconURL());
em.withAuthorName("Success!");
em.withColor(56, 138, 237);
em.withTitle("Evaluation output.");
em.withDesc(o == null ? "No output, object is null" : o.toString());
em.appendField("Input", "```java\n" + input + "\n```", false);
em.withFooterText("Eval successful!");
Message.sendMessage(em.build(), channel);
}
Aggregations