Skip to content

Commit

Permalink
add selfdeafen and fix polls
Browse files Browse the repository at this point in the history
  • Loading branch information
blahblahbloopster committed Dec 30, 2024
1 parent 0d25e77 commit fdb40ef
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bot/resources/motors.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,32 @@ object Administration {
}
}

@Command("selfdeafen", "Temporarily your message read permissions")
suspend inline fun CmdCtx.selfdeafen(@P("hours", "The number of hours to deafen for") hours: Double, @P("reason", "The reason for self-deafening") reason: String?) {
val member = event.member ?: throw CommandException("Must be run in a guild!")

if (!event.guild!!.selfMember.hasPermission(Permission.MODERATE_MEMBERS) /*|| !event.guild!!.selfMember.canInteract(member) */) throw CommandException("Insufficient bot permissions!")
val duration = hours.hours
if (duration !in kotlin.time.Duration.ZERO..28.days) throw CommandException("Invalid duration!")
val r = bot.database.trnsctn {
event.guild!!.m.deafenRole
} ?: throw CommandException("Deafens are not configured in this guild")

val role = event.guild!!.getRoleById(r) ?: throw CommandException("Deafen role does not exist!")

try {
event.guild!!.addRoleToMember(member, role).await()
} catch (_: Throwable) {
throw CommandException("Failed to add deafen role!")
}

bot.database.trnsctn {
ModerationDB.UserLogs.logDeafen(event.user, event.guild!!, event.user, duration, reason ?: "")
}

event.replyEmbeds(embed("Deafening", description = "Deafening you for ${duration.inWholeHours} hours", stripPings = false)).ephemeral().await()
}

@Command("deafen", "Deafens a user")
suspend inline fun CmdCtx.deafen(@P("user", "The user to deafen") victim: User, @P("reason", "The deafen reason") reason: String, @P("hours", "The number of hours to deafen for") hours: Double, @P("publish", "If true, logs to the mod log channel") log: Boolean) {
assertPermissions(Permission.MODERATE_MEMBERS, channel = null)
Expand Down Expand Up @@ -881,6 +907,21 @@ object Administration {
}
}

@Command("setdeafenrole", "Sets the guild's deafen role")
suspend inline fun CmdCtx.setDeafenRole(@P("role", "The role that deafened members are assigned") role: Role) {
assertAdmin()

if (!event.guild!!.selfMember.canInteract(role) || !event.guild!!.selfMember.hasPermission(Permission.MANAGE_ROLES)) {
throw CommandException("Missing permissions to assign role")
}

bot.database.trnsctn {
event.guild!!.m.deafenRole = role.idLong
}

event.replyEmbeds(Commands.embed("Set role", description = "Deafened members will be assigned the ${role.asMention} role. The role will not be automatically configured, manually disable the view messages permission for this role in each category", stripPings = false)).ephemeral().await()
}

@Command("modlog", "View the moderation log for a user")
suspend inline fun CmdCtx.modlog(@P("user", "The user to view the log for") victim: User) {
assertPermissions(Permission.MODERATE_MEMBERS, channel = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.corruptedinc.corruptedmainframe.core.db.ExposedDatabase
import com.github.corruptedinc.corruptedmainframe.core.db.ExposedDatabase.Companion.m
import com.github.corruptedinc.corruptedmainframe.core.db.ExposedDatabase.StarredMessage
import com.github.corruptedinc.corruptedmainframe.core.db.ExposedDatabase.StarredMessages
import com.github.corruptedinc.corruptedmainframe.utils.bar
import dev.minn.jda.ktx.coroutines.await
import dev.minn.jda.ktx.events.listener
import net.dv8tion.jda.api.entities.Message
Expand All @@ -18,7 +19,7 @@ import org.jetbrains.exposed.sql.and
class Starboard(private val bot: Bot) {
companion object {
private val url = "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]".toRegex()
private val mediaExtensions = setOf("png", "jpg", "jpeg", "gif"/*, "webm", "mp4"*/)
private val mediaExtensions = setOf("png", "jpg", "jpeg", "gif", "webp"/*, "webm", "mp4"*/)
}

init {
Expand All @@ -44,6 +45,7 @@ class Starboard(private val bot: Bot) {
// we have to retrieve the message to get the reaction counts
val msg = event.retrieveMessage().await()
if (msg.author.idLong == bot.jda.selfUser.idLong && msg.embeds.singleOrNull()?.title?.contains("Starboard") == true) return@listener
if (event.reaction.retrieveUsers().await().any { it.idLong == 336336224266485762 }) return@listener
val reaction = msg.reactions.find { event.reaction.emoji.asReactionCode == it.emoji.asReactionCode } ?: return@listener
if (board.second <= reaction.count) {
star(event.channel as GuildMessageChannel, u, event.messageIdLong, board.third)
Expand Down Expand Up @@ -102,9 +104,11 @@ class Starboard(private val bot: Bot) {
// would be nice if this could be put in the above transaction, but oh well
bot.leveling.addPoints(message.author, points, channel)

val poll = message.poll?.let { "Poll: ${it.question.text}\n${it.answers.joinToString("\n") { ans -> "|${bar(ans.votes.toDouble() / it.answers.sumOf { a -> a.votes.toDouble() }, 24)}| ${if (it.isFinalizedVotes && ans.votes >= it.answers.maxOf { a -> a.votes }) "" else ""}" }}\n${it.answers.sumOf { ans -> ans.votes }} votes" } ?: ""

val attachments = message.attachments.filter { it.isImage }.map { it.url } + url.findAll(message.contentRaw).filter { it.value.substringAfterLast('.') in mediaExtensions }.map { it.value }
val embed = Commands.embed(name, message.jumpUrl,
description = "${message.member?.asMention}:\n" + message.contentRaw.ifBlank { message.embeds.firstOrNull()?.description ?: "" },
description = "${message.member?.asMention}:\n" + message.contentRaw.ifBlank { message.embeds.firstOrNull()?.description ?: "" } + poll,
color = message.member?.color, thumbnail = message.member?.effectiveAvatarUrl,
imgUrl = attachments.randomOrNull(),
timestamp = message.timeCreated,
Expand Down

0 comments on commit fdb40ef

Please sign in to comment.