diff --git a/src/main/kotlin/at/hannibal2/skyhanni/discord/CommandListener.kt b/src/main/kotlin/at/hannibal2/skyhanni/discord/CommandListener.kt index 17d66a4..8460801 100644 --- a/src/main/kotlin/at/hannibal2/skyhanni/discord/CommandListener.kt +++ b/src/main/kotlin/at/hannibal2/skyhanni/discord/CommandListener.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.discord.Utils.reply import at.hannibal2.skyhanni.discord.command.BaseCommand import at.hannibal2.skyhanni.discord.command.HelpCommand import at.hannibal2.skyhanni.discord.command.PullRequestCommand +import at.hannibal2.skyhanni.discord.command.RepoPullRequestCommand import at.hannibal2.skyhanni.discord.command.ServerCommands import at.hannibal2.skyhanni.discord.command.TagCommands import at.hannibal2.skyhanni.discord.command.TagUndo @@ -17,6 +18,8 @@ import java.lang.reflect.Modifier object CommandListener { private const val BOT_ID = "1343351725381128193" + private val pullRequestCommand: PullRequestCommand = PullRequestCommand() + var commands = listOf() private set private var commandsMap = mapOf() @@ -48,9 +51,6 @@ object CommandListener { TagCommands.lastMessages.remove(this.author.id) } - if (ServerCommands.isKnownServerUrl(this, message)) return - if (PullRequestCommand.isPullRequest(this, message)) return - if (!isCommand(message)) return val split = message.substring(1).split(" ") @@ -62,6 +62,10 @@ object CommandListener { return } + if (ServerCommands.isKnownServerUrl(this, message)) return + if (command.name == "pr" && pullRequestCommand.isPullRequest(this, message)) return + if (command.name == "repopr" && RepoPullRequestCommand.isPullRequest(this, message)) return + if (!command.userCommand) { if (!hasAdminPermissions()) { reply("No permissions $PLEADING_FACE") diff --git a/src/main/kotlin/at/hannibal2/skyhanni/discord/DiscordBot.kt b/src/main/kotlin/at/hannibal2/skyhanni/discord/DiscordBot.kt index 78f1ac0..346f830 100644 --- a/src/main/kotlin/at/hannibal2/skyhanni/discord/DiscordBot.kt +++ b/src/main/kotlin/at/hannibal2/skyhanni/discord/DiscordBot.kt @@ -31,6 +31,8 @@ class DiscordBot(val jda: JDA, val config: BotConfig) { } const val PLEADING_FACE = "🥺" +const val BIG_X = "❌" +const val CHECK_MARK = "✅" const val PING_HANNIBAL = "<@239858538959077376>" fun main() { diff --git a/src/main/kotlin/at/hannibal2/skyhanni/discord/command/PullRequestCommand.kt b/src/main/kotlin/at/hannibal2/skyhanni/discord/command/PullRequestCommand.kt index 9534b36..c9ec283 100644 --- a/src/main/kotlin/at/hannibal2/skyhanni/discord/command/PullRequestCommand.kt +++ b/src/main/kotlin/at/hannibal2/skyhanni/discord/command/PullRequestCommand.kt @@ -1,11 +1,7 @@ package at.hannibal2.skyhanni.discord.command -import at.hannibal2.skyhanni.discord.BOT -import at.hannibal2.skyhanni.discord.Option -import at.hannibal2.skyhanni.discord.PLEADING_FACE -import at.hannibal2.skyhanni.discord.SimpleTimeMark +import at.hannibal2.skyhanni.discord.* import at.hannibal2.skyhanni.discord.SimpleTimeMark.Companion.asTimeMark -import at.hannibal2.skyhanni.discord.Utils import at.hannibal2.skyhanni.discord.Utils.createParentDirIfNotExist import at.hannibal2.skyhanni.discord.Utils.embed import at.hannibal2.skyhanni.discord.Utils.format @@ -30,26 +26,25 @@ import java.time.format.DateTimeFormatter import kotlin.time.Duration.Companion.days import kotlin.time.Duration.Companion.seconds -object PullRequestCommand : BaseCommand() { +open class PullRequestCommand : BaseCommand() { - override val name: String = "pr" + open val disableBuildInfo: Boolean = false + open val repo get() = "SkyHanni" + protected val user get() = "hannibal002" + private val base get() = "https://github.com/$user/$repo" + private val pullRequestPattern = "$base/pull/(?\\d+)".toPattern() + open val github by lazy { GitHubClient(user, repo, BOT.config.githubToken) } + private val runIdRegex = + Regex("https://github\\.com/[\\w.]+/[\\w.]+/actions/runs/(?\\d+)/job/(?\\d+)") + + override val name: String = "pr" override val description: String = "Displays useful information about a pull request on Github." override val options: List