Create guild in DB on guild join

This commit is contained in:
anthorob committed 2022-03-15 16:46:53 -04:00
1 parent c44ddd42be
commit f71cdb324b
2 files changed
+10 -9

No files matched your search

@@ -245,21 +245,16 @@ public class GuildManager {
session.save(entity);
session.getTransaction().commit();
handleJoinEvent();
guild.getTextChannels()
.stream()
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
.forEach(textChannel -> textChannel.sendMessage("Error logging enabled on channel " + textChannel.getAsMention()).queue());
}
session.close();
return entity;
}
public void handleJoinEvent() {
guild.getTextChannels()
.stream()
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
.forEach(textChannel -> textChannel.sendMessage("Error logging enabled on channel " + textChannel.getAsMention()).queue());
}
public void reloadEntity() {
this.guildEntity = loadGuildFromDb(guild.getId());
}
@@ -7,6 +7,7 @@ package netneutrality.handler.hooks.guilds;
* https://discord.gg/CdFcyQ
*/
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import netneutrality.core.GuildManager;
@@ -14,6 +15,11 @@ import org.jetbrains.annotations.NotNull;
public class ServerJoinHandler extends ListenerAdapter {
@Override
public void onGuildJoin(@NotNull GuildJoinEvent event) {
GuildManager.getManager(event.getGuild());
}
@Override
public void onGuildLeave(@NotNull GuildLeaveEvent event) {
GuildManager.getManager(event.getGuild()).removeFromDB();