use of ml.duncte123.skybot.objects.guild.GuildSettings in project SkyBot by duncte123.
the class BotListener method onGuildMemberJoin.
/**
* This will fire when a new member joins
*
* @param event The corresponding {@link GuildMemberJoinEvent}
*/
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
if (event.getMember().equals(event.getGuild().getSelfMember()))
return;
/*
{{USER_MENTION}} = mention user
{{USER_NAME}} = return username
{{GUILD_NAME}} = the name of the guild
{{GUILD_USER_COUNT}} = member count
{{GUILD_OWNER_MENTION}} = mention the guild owner
{{GUILD_OWNER_NAME}} = return the name form the owner
*/
GuildSettings settings = GuildSettingsUtils.getGuild(event.getGuild());
if (settings.isEnableJoinMessage()) {
String welcomeLeaveChannelId = (settings.getWelcomeLeaveChannel() == null || "".equals(settings.getWelcomeLeaveChannel()) ? GuildUtils.getPublicChannel(event.getGuild()).getId() : settings.getWelcomeLeaveChannel());
TextChannel welcomeLeaveChannel = event.getGuild().getTextChannelById(welcomeLeaveChannelId);
String msg = parseGuildVars(settings.getCustomJoinMessage(), event);
if (!msg.isEmpty() || "".equals(msg) || welcomeLeaveChannel != null)
MessageUtils.sendMsg(welcomeLeaveChannel, msg);
}
if (settings.getAutoroleRole() != null && !"".equals(settings.getAutoroleRole()) && event.getGuild().getSelfMember().hasPermission(Permission.MANAGE_ROLES)) {
Role r = event.getGuild().getRoleById(settings.getAutoroleRole());
if (r != null && !event.getGuild().getPublicRole().equals(r))
event.getGuild().getController().addSingleRoleToMember(event.getMember(), r).queue(null, it -> {
});
}
}
use of ml.duncte123.skybot.objects.guild.GuildSettings in project SkyBot by duncte123.
the class GuildSettingsUtils method registerNewGuild.
/**
* This will register a new guild with their settings on bot join
*
* @param g The guild that we are joining
* @return The new guild
*/
public static GuildSettings registerNewGuild(Guild g) {
if (AirUtils.guildSettings.containsKey(g.getId())) {
return AirUtils.guildSettings.get(g.getId());
}
GuildSettings newGuildSettings = new GuildSettings(g.getId());
String dbName = AirUtils.DB.getName();
Connection database = AirUtils.DB.getConnManager().getConnection();
try {
ResultSet resultSet = database.createStatement().executeQuery("SELECT id FROM " + dbName + ".guildSettings WHERE guildId='" + g.getId() + "'");
int rows = 0;
while (resultSet.next()) rows++;
if (rows == 0) {
PreparedStatement smt = database.prepareStatement("INSERT INTO " + dbName + ".guildSettings(guildId, guildName," + "customWelcomeMessage, prefix, customLeaveMessage) " + "VALUES('" + g.getId() + "', ? , ? , ? , ?)");
smt.setString(1, g.getName().replaceAll("\\P{Print}", ""));
smt.setString(2, newGuildSettings.getCustomJoinMessage());
smt.setString(3, Settings.PREFIX);
smt.setString(4, newGuildSettings.getCustomLeaveMessage().replaceAll("\\P{Print}", ""));
smt.execute();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (database != null) {
try {
database.close();
} catch (SQLException e2) {
e2.printStackTrace();
}
}
}
AirUtils.guildSettings.put(g.getId(), newGuildSettings);
return newGuildSettings;
}
Aggregations