kordlib / kordx.commands Goto Github PK
View Code? Open in Web Editor NEWKotlin Command library for Kord and other APIs
License: MIT License
Kotlin Command library for Kord and other APIs
License: MIT License
Related to kordlib/kord#142
There should be a way of registering kordx.commands commands with Discord slash commands
This extension is hosted on Bintray according to README.md, though it is impossible to fetch because JFrog deprecated Bintray. Is it possible to upload this extension to the Maven Central Repository?
The regex of RoleArgument ('^<#&\d+>$') has an '#' instead of an '@', as roles look like this: <@&767105440315998218>
Trying to use the bot function breaks with latest kord version
Exception in thread "main" java.lang.NoSuchMethodError: 'int dev.kord.core.ClientResources.getShardCount()'
at today.howoldisjava8.discord_bot.LauncherKt.main(Launcher.kt:91)
The problem is this line
Since the called functions is inline when compiling kxc it inlined this code
but the implementation has been updated to
this causes problems as ClientResources.shardCount no longer exists
Instead of creating multiple instances of the Command and CommandData in CommandBuilder.build, we can create single Command and store the aliases as List<String>
and in BuildEnvironment.addCommand we can point primary name and each aliases to same instance of the Command.
Benefits:
If the bot function logs itself in, the user won't be able to use any functionality from the CommandsProcessor.
As such we can't get the list of commands, and the structure of the bot becomes inside-out (restricted to event handling).
One of the use-case of this (not automatically logging in) could be listen for MessageCreateEvent/MessageUpdateEvent and filter out the messages which does not contains the command in it. To filter this, one need reference to CommandsProcessor.commands and CommandsProcessor.prefix but it is impossible to do so with the bot function.
(creating bot with BotBuilder manually instead of bot() function is an option, but it will create noise in the code).
Change the bot function signature (not backward compatible):
/**
* Creates a bot with the given [kord] instance, applying [configure] to the bot's configuration.
*/
suspend inline fun bot(kord: Kord, configure: KordProcessorBuilder.() -> Unit): CommandProcessor =
BotBuilder(kord).apply { processorBuilder.configure() }.build()
Doing this we can't assure the backward compatibility with the older function, but as this library wasn't stable and used much as of now we shall change the method signature.
Deprecate the current function and define new which can optionally login:
@Deprecated(
message = "Use bot(kord, login, configure) instead.",
replaceWith = ReplaceWith("bot(kord, login = true, configure)"),
level = DeprecationLevel.WARNING
)
suspend inline fun bot(kord: Kord, configure: KordProcessorBuilder.() -> Unit) {
bot(kord, true, configure)
}
suspend inline fun bot(
kord: Kord,
login: Boolean,
configure: KordProcessorBuilder.() -> Unit
): CommandProcessor =
BotBuilder(kord)
.apply { processorBuilder.configure() }
.build()
.also { if (login) kord.login() }
Currently aliases are supplied when configuring commands:
command(name) {
alias(aliasOne, aliasTwo, aliasThree)
invoke {
//....
}
}
It would be rather simple and more concise to also allow these to be supplied after the name:
command(name, aliasOne, aliasTwo, aliasThree) {
invoke {
//....
}
}
I don't think we'll ever use the arguments after a command's name for anything else, so there's not much risk capitalising the space like this.
You should be able to add sub commands to a command like this
command("main") {
command("sub") {
command("subsub") {
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.