Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
[feature] Title support for ;say
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT2 committed Dec 1, 2020
1 parent 8d75f70 commit e56aab4
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions src/main/kotlin/commands/SayCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ object SayCommand : Command("say") {
init {
channel("channel") {
bool("embed") {
greedyString("content") {
doesLaterIfHas(PermissionTypes.SAY) { context ->
val embed: Boolean = context arg "embed"
val content: String = context arg "content"
string("title") {
greedyString("content") {
doesLaterIfHas(PermissionTypes.SAY) { context ->
val embed: Boolean = context arg "embed"
val content: String = context arg "content"

val channel: TextChannel = (context.channelArg("channel", server) ?: run {
message.error("Error sending message! The text channel does not exist.")
return@doesLaterIfHas
}) as TextChannel
val channel: TextChannel = (context.channelArg("channel", server) ?: run {
message.error("Error sending message! The text channel does not exist.")
return@doesLaterIfHas
}) as TextChannel

if (embed) {
channel.send {
embed {
description = content
color = Colors.PRIMARY.color
if (embed) {
channel.send {
embed {
title = context arg "title"
description = content
color = Colors.PRIMARY.color
}
}
} else {
channel.send(content)
}
} else {
channel.send(content)
}
}
}
Expand All @@ -39,26 +42,29 @@ object SayCommand : Command("say") {
literal("edit") {
channel("channel") {
long("message") {
greedyString("content") {
doesLaterIfHas(PermissionTypes.SAY) { context ->
val channel: TextChannel = (context.channelArg("channel", server) ?: run {
message.error("Error sending message! The text channel does not exist.")
return@doesLaterIfHas
}) as TextChannel
string("title") {
greedyString("content") {
doesLaterIfHas(PermissionTypes.SAY) { context ->
val channel: TextChannel = (context.channelArg("channel", server) ?: run {
message.error("Error sending message! The text channel does not exist.")
return@doesLaterIfHas
}) as TextChannel

val message: Message = channel.getMessage(context arg "message") ?: run {
message.error("Error editing message! The message does not exist.")
return@doesLaterIfHas
}
val message: Message = channel.getMessage(context arg "message") ?: run {
message.error("Error editing message! The message does not exist.")
return@doesLaterIfHas
}

val content: String = context arg "content"
val content: String = context arg "content"

if (message.embeds.isNullOrEmpty()) {
message.edit(content)
} else {
message.edit {
description = content
color = Colors.PRIMARY.color
if (message.embeds.isNullOrEmpty()) {
message.edit(content)
} else {
message.edit {
title = context arg "title"
description = content
color = Colors.PRIMARY.color
}
}
}
}
Expand All @@ -70,7 +76,7 @@ object SayCommand : Command("say") {

override fun getHelpUsage(): String {
return "Say or edit messages via the bot.\n\n" +
"`$fullName <channel> <embed (true or false)> <content>`\n" +
"`$fullName edit <channel> <message id> <new content>`"
"`$fullName <channel> <embed (true or false)> <title or empty> <content>`\n" +
"`$fullName edit <channel> <message id> <title or empty> <new content>`"
}
}

0 comments on commit e56aab4

Please sign in to comment.