40 lines
1.7 KiB
Kotlin
40 lines
1.7 KiB
Kotlin
package nl.voidcorp.discord.commands.general
|
|
|
|
import nl.voidcorp.discord.command.Command
|
|
import nl.voidcorp.discord.command.CommandMessage
|
|
import nl.voidcorp.discord.command.CommandResult
|
|
import org.gitlab.api.GitlabAPI
|
|
import org.gitlab.api.TokenType
|
|
import org.springframework.context.annotation.Condition
|
|
import org.springframework.context.annotation.ConditionContext
|
|
import org.springframework.context.annotation.Conditional
|
|
import org.springframework.core.type.AnnotatedTypeMetadata
|
|
import org.springframework.stereotype.Service
|
|
|
|
@Conditional(ReportCommand.ReportAvailable::class)
|
|
@Service
|
|
class ReportCommand : Command(
|
|
"report",
|
|
helpMesage = "Report a bug or request a feature for the bot!",
|
|
usage = "report bug/feature \"name\" \"description\""
|
|
) {
|
|
val api =
|
|
GitlabAPI.connect("https://gitlab.voidcorp.nl/", System.getenv("GITLAB_API_TOKEN"), TokenType.PRIVATE_TOKEN)
|
|
|
|
override fun handle(event: CommandMessage): CommandResult {
|
|
if (event.params.size != 4) return CommandResult.PARAMETERS
|
|
val theProject = api.projects.first { it.name.contains("ottobotv2") }
|
|
val (type, title, descr) = event.params.drop(1)
|
|
if (type.toLowerCase() !in listOf("bug", "feature")) return CommandResult.PARAMETERS
|
|
|
|
|
|
val issue = api.createIssue(theProject.id, 0, null, type.toLowerCase().capitalize(), descr, title)
|
|
event.reply("Thanks for reporting, a new issue was created: ${theProject.webUrl}/issues/${issue.iid}")
|
|
return CommandResult.SUCCESS
|
|
}
|
|
|
|
class ReportAvailable : Condition {
|
|
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata) =
|
|
System.getenv("GITLAB_API_TOKEN") != null
|
|
}
|
|
} |