Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class LorittaHelper(val config: LorittaHelperConfig, val fanArtsConfig: FanArtsC
commandManager.register(LoriToolsCommand(this))
commandManager.register(TicketUtilsCommand(this))
commandManager.register(CloseTicketCommand(this))
commandManager.register(LockTicketCommand(this))
commandManager.register(DailyCheckCommand(this))
commandManager.register(TicketSenderCommand(this))
commandManager.register(ReportMessageSenderCommand(this))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.perfectdreams.loritta.helper.interactions.commands.vanilla

import net.dv8tion.jda.api.entities.channel.ChannelType
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel
import net.perfectdreams.i18nhelper.core.I18nContext
import net.perfectdreams.loritta.helper.LorittaHelper
import net.perfectdreams.loritta.helper.i18n.I18nKeysData
import net.perfectdreams.loritta.helper.utils.extensions.await
Expand All @@ -15,30 +15,38 @@ class CloseTicketCommand(val helper: LorittaHelper) : SlashCommandDeclarationWra
inner class CloseTicketExecutor : LorittaSlashCommandExecutor() {
override suspend fun execute(context: ApplicationCommandContext, args: SlashCommandArguments) {
val channel = context.event.guildChannel
if (channel.type != ChannelType.GUILD_PRIVATE_THREAD) {

if (channel !is ThreadChannel) {
context.reply(true) {
content = "You aren't in a ticket!"
content = "Você não está em um ticket!"
}

return
}
channel as ThreadChannel

val parentChannel = channel.parentChannel

val ticketSystemInformation = helper.ticketUtils.systems[parentChannel.idLong]!!
val i18nContext = ticketSystemInformation.getI18nContext(helper.languageManager)

context.reply(true) {
content = i18nContext.get(I18nKeysData.Tickets.ClosingYourTicket)
val i18nContext = if (helper.ticketUtils.systems[parentChannel.idLong] == null) {
helper.languageManager.getI18nContextById("pt")
} else {
helper.ticketUtils.systems[parentChannel.idLong]!!.getI18nContext(helper.languageManager)
}

context.reply(false) {
content = i18nContext.get(I18nKeysData.Tickets.TicketClosed(context.user.asMention))
}
closeTicket(context, channel, i18nContext)
}
}

private suspend fun closeTicket(context: ApplicationCommandContext, channel: ThreadChannel, i18nContext: I18nContext) {
context.reply(true) {
content = i18nContext.get(I18nKeysData.Tickets.ClosingYourTicket)
}

channel.manager.setArchived(true)
.reason("Archival request via command by ${context.user.name} (${context.user.idLong})")
.await()
context.reply(false) {
content = i18nContext.get(I18nKeysData.Tickets.TicketClosed(context.user.asMention))
}

channel.manager.setArchived(true)
.reason("Archival request via command by ${context.user.name} (${context.user.idLong})")
.await()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.perfectdreams.loritta.helper.interactions.commands.vanilla

import net.dv8tion.jda.api.Permission
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel
import net.perfectdreams.i18nhelper.core.I18nContext
import net.perfectdreams.loritta.helper.LorittaHelper
import net.perfectdreams.loritta.helper.i18n.I18nKeysData
import net.perfectdreams.loritta.helper.utils.extensions.await
import net.perfectdreams.loritta.morenitta.interactions.commands.*

class LockTicketCommand(val helper: LorittaHelper) : SlashCommandDeclarationWrapper {
override fun command() = slashCommand("lockticket", "Tranca uma thread caso esteja muita várzea") {
executor = LockTicketCommandExecutor()
}

inner class LockTicketCommandExecutor : LorittaSlashCommandExecutor() {
override suspend fun execute(context: ApplicationCommandContext, args: SlashCommandArguments) {
val channel = context.event.guildChannel

if (channel !is ThreadChannel) {
context.reply(true) {
content = "Você não está em um ticket!"
}

return
}

if (!context.member.hasPermission(Permission.MANAGE_THREADS)) {
context.reply(true) {
content = "Você não tem permissão para trancar tickets!"
}

return
}

val parentChannel = channel.parentChannel

val i18nContext = if (helper.ticketUtils.systems[parentChannel.idLong] == null) {
helper.languageManager.getI18nContextById("pt")
} else {
helper.ticketUtils.systems[parentChannel.idLong]!!.getI18nContext(helper.languageManager)
}

lockThread(context, channel, i18nContext)
}

private suspend fun lockThread(context: ApplicationCommandContext, channel: ThreadChannel, i18nContext: I18nContext) {
context.reply(true) {
content = i18nContext.get(I18nKeysData.Tickets.LockingYourTicket)
}

context.reply(false) {
content = i18nContext.get(I18nKeysData.Tickets.TicketLocked(context.user.asMention))
}

channel.manager.setLocked(true)
.reason("Lock request via command by ${context.user.name} (${context.user.idLong})")
.await()
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/languages/en/tickets.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tickets:
creatingATicket: "Creating a ticket for you... Hang tight!"
closingYourTicket: "Closing your ticket... I hope your question was solved!"
lockingYourTicket: "Locking your ticket... Let's control this mess!"
youAlreadyCreatedATicketRecently: "You created a ticket just recently! Did you know that creating new threads makes me tired? {loriSob} You will be able to create a new ticket in {time}..."
ticketWasCreated: "Your ticket was created! Please send your super amazing question there: {channel}"
autoResponseSolved: "If I solved your question, please, click on the button to close the ticket! Don't worry, if you have more questions in the future, you will be able to open another ticket then!"
Expand All @@ -16,6 +17,7 @@ tickets:
createATicketIfQuestionWasntFound: "Still didn't find your question? Then create a ticket by clicking the \"Open Ticket\" button, option which creates a private channel where you can direct your question to {lorittaSupport}!"
clickToFindYourQuestion: "Click to search for support to your question!"
ticketClosed: "Ticket closed by {user}, thank you and goodbye!"
ticketLocked: "Ticket locked by {user}, only staff members can reply!"
ticketAutoClosedUserLeftServer: "Ticket was automatically closed because the creator of the ticket left the support server... :("
threadCreated:
ready: "Done! I prepared a ticket for you, please ask your question and wait until our support staff comes here to answer your question."
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/pt/tickets.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tickets:
creatingATicket: "Criando um ticket para você... Segure firme!"
closingYourTicket: "Fechando o seu ticket... Eu espero que a sua dúvida foi resolvida!"
lockingYourTicket: "Trancando o seu ticket... Vamos controlar essa várzea!"
youAlreadyCreatedATicketRecently: "Você criou um ticket recentemente! Me deixe descansar um pouquinho pois ficar criando threads toda hora cansa, sabia? {loriSob} Você poderá abrir um novo ticket {time}..."
ticketWasCreated: "Seu ticket foi criado! Por favor mande a sua pergunta super incrível no ticket: {channel}"
autoResponseSolved: "Se a minha resposta resolveu a sua dúvida, por favor, clique no botão para encerrar o ticket! Não se preocupe, caso você tenha outra dúvida no futuro, você poderá abrir outro ticket!"
Expand All @@ -17,6 +18,7 @@ tickets:
createATicketIfQuestionWasntFound: "Mesmo assim não encontrou a sua pergunta? Então crie um ticket clicando no botão de \"Abrir Ticket\", isto irá criar um canal privado que irá permitir você perguntar a sua dúvida para o {lorittaSupport}! Eu espero que a gente possa te ajudar com a sua dúvida!!"
clickToFindYourQuestion: "Clique para encontrar a sua dúvida!"
ticketClosed: "Ticket encerrado por {user}, obrigada e até a próxima!"
ticketLocked: "Ticket trancado por {user}, somente membros da equipe podem responder!"
ticketAutoClosedUserLeftServer: "Ticket foi automaticamente fechado pois o criador do ticket saiu do servidor de suporte... :("
threadCreated:
ready: "Prontinho! Eu criei um ticket para você, faça sua pergunta e aguarde até que um membro da equipe venha tirar sua dúvida."
Expand Down
Loading