Skip to content

Commit

Permalink
some updates around file capture and member updating
Browse files Browse the repository at this point in the history
  • Loading branch information
FireBall1725 committed Mar 2, 2024
1 parent bc30cc4 commit 9038819
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ data class Member(
val country: String?,
val description: String?,
val show_on_website: Boolean,
val join_season: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class Database {
}

fun getMembers(): MutableList<Member> {
val query = connection!!.prepareStatement("SELECT * FROM members")
val query = connection!!.prepareStatement(
"SELECT member_id, display_username, discord_id, pronouns, country, description, show_on_website, join_season " +
"FROM members " +
"ORDER BY display_username"
)

val resultSet = query.executeQuery()
val members = mutableListOf<Member>()
Expand All @@ -51,14 +55,27 @@ class Database {
pronouns = resultSet.getString("pronouns"),
country = resultSet.getString("country"),
description = resultSet.getString("description"),
show_on_website = resultSet.getBoolean("show_on_website")
show_on_website = resultSet.getBoolean("show_on_website"),
join_season = resultSet.getInt("join_season"),
)
members.add(member)
}

return members
}

fun disableMember(memberId: UUID) {
val query = connection!!.prepareStatement(
"UPDATE members " +
"SET show_on_website = false " +
"WHERE member_id = ?"
)

query.setObject(1, memberId)

query.executeUpdate()
}

fun getMemberFromDiscordId(discordId: ULong): Member? {
val query = connection!!.prepareStatement("SELECT * FROM members where discord_id=${discordId}")

Expand All @@ -73,7 +90,8 @@ class Database {
pronouns = resultSet.getString("pronouns"),
country = resultSet.getString("country"),
description = resultSet.getString("description"),
show_on_website = resultSet.getBoolean("show_on_website")
show_on_website = resultSet.getBoolean("show_on_website"),
join_season = resultSet.getInt("join_season"),
)
members.add(member)
}
Expand Down Expand Up @@ -205,6 +223,25 @@ class Database {
query.executeUpdate()
}

fun deleteDiscordRoles(discordId: ULong) {
val query = connection!!.prepareStatement(
"DELETE FROM discord_roles " +
"WHERE discord_member_id='${discordId}'"
)
query.executeUpdate()
}

fun addDiscordRole(discordId: ULong, discordRoleId: ULong) {
val query = connection!!.prepareStatement(
"INSERT INTO discord_roles " +
"(discord_member_id, discord_role_id) " +
"VALUES (?, ?)"
)
query.setObject(1, discordId.toLong())
query.setObject(2, discordRoleId.toLong())
query.executeUpdate()
}

fun getServers(): MutableList<Server> {
val query = connection!!.prepareStatement(
"SELECT server_id, pterodactyl_id, server_name, description, gamemode, pack_url, live_map_url, server_live, server_started, server_finished, game_name, game_url, game_icon " +
Expand Down Expand Up @@ -236,4 +273,5 @@ class Database {

return servers
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ class JsonStatsProcessor {
processServerDirectory(it.server_id, "/${levelName}/playerdata", it.pterodactyl_id, isRoot = true)
processServerDirectory(it.server_id, "/${levelName}/stats", it.pterodactyl_id, isRoot = true)
processServerDirectory(it.server_id, "/${levelName}/data", it.pterodactyl_id, isRoot = true)
processServerDirectory(it.server_id, "/mods", it.pterodactyl_id, isRoot = true)
processServerDirectory(it.server_id, "${levelName}/datapacks", it.pterodactyl_id, isRoot = true)
if (it.gamemode == "VH") {
// this is specific to vault hunters servers
processServerDirectory(it.server_id, "/playerSnapshots", it.pterodactyl_id, isRoot = true)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,32 @@ class MembersProcessor {
if (! getGuilds().isNullOrEmpty()) {
val guild: Guild = getGuilds()!![0]
println("Processing members from ${guild.name}")
val guildMembers = mutableListOf<Long>()

// Add members to the database that don't exist
guild.members.toList().forEach {
var discordMemberId = it.id.value
if (RoleHelper().doesMemberHaveRole(it, 1143743030541680662U)) {
println("Processing Discord User: ${it.displayName} Id: ${it.id.value}")
getDatabase().updateMemberByDiscordId(it.id.value, it.displayName)
println("Processing Discord User: ${it.displayName} Id: ${discordMemberId}")
getDatabase().updateMemberByDiscordId(discordMemberId, it.displayName)
}
guildMembers.add(it.id.value.toLong())

// Add member roles to database
getDatabase().deleteDiscordRoles(discordMemberId)
it.roles.toList().forEach {
getDatabase().addDiscordRole(discordMemberId, it.id.value)
}
}

// Disable members that left the discord
val membersList = getDatabase().getMembers()
if (membersList != null && membersList.size > 0) {
membersList.forEach {
if (!guildMembers.contains(it.discord_id)) {
println("Disabling Discord User: ${it.display_username} Id: ${it.discord_id}")
getDatabase().disableMember(it.member_id)
}
}
}
}
Expand Down

0 comments on commit 9038819

Please sign in to comment.