v3.0.0 #15
ShindouMihou
announced in
Announcements
v3.0.0
#15
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
🐉 The Largest Update of Velen
Velen has gone through a lot of changes since its last official version to the
master
branch, after a long wait for Javacord 3.4.0, I decided to let this version be out for official use to all the users. Here are all the BREAKING and AMAZING changes that the framework has gone through over the past three weeks.Feel free to read from the Pull Request
🌟 Velen Mirror
Velen Mirror is the new command constructor system of Velen that aims to separate the nature of your code and
the command constructors which tends to be a mess especially for bots with tons of commands. Mirror is far cleaner
and verbose to read than ordinary Java builders, written under the
.velen
syntax.To fully understand the outline of Mirror, let us take a glance at a simple ping-pong command that can be found written
similarly on both Message and Slash folders but adapted to their own use-case. Our example here will showcase how they can
be written in Hybrid Command.
🎂 Ping-Pong with Velen Mirror
Now that we know of all the currently possible options of Velen Mirror, let us start to minimize
the file to view the actual parts of the command, shall we?
To see a full explanation of everything, please scroll even more below.
😲 ping.min.velen
Doesn't that look quite clean and readable, compare that to the original Java builder method?
Press here to read more about Velen Mirror
🥳 True Hybrid Command Support
Velen now supports TRUE hybrid command support which means you can now use a single handler for both slash commands and message commands. It supports both subcommand, subcommand groups, options and practically most of slash commands to message commands.
Press here for examples.
💘 Automated Slash Command Updater/Registerer
Velen now offers a new integrated module which allows you to automatically update slash commands in a more automated way, this module checks for any differences between slash commands (global ones) to the tiniest bit like options, names or descriptions then updates them accordingly.
There are two different modes to this:
NORMAL
andSOFT
VelenCommand
that isn't registered on Discord's side already while also updating the ones that have differing values (likeSoft
).VelenCommadn
that isn't registered on Discord's side but will update any that have differing values (like for example, if aVelenCommand
finds an equivalent command on Discord's side but with a different description, or a different option. It will send an update to update that command).📦 How to use?
To use this module, all you have to do is create a new
SlashCommandChecker
instance which takes in aDiscordApi
andVelen
instance (theDiscordApi
can be any shard, if you are wondering since it shouldn't matter for Discord):The method
run(Velen)
returns back aCompletableFuture<Integer>
with the integer showing many commands were updated (and registered).💭 Is this blocking?
Despite being a
CompletableFuture
, the initial collection of all slash commands from Discord will be a blocking statement and shouldn't take long (usually 1-2 seconds depending on your latency towards Discord's REST). In the first place, this method IS SUPPOSED TO BE USED AT STARTUP to keep everything up-to-date each restart.Other than that, after the initial
GET
request towards Discord, everything will start to run asynchronously through a different threadpool (VelenThreadPool
) to prevent any blockage with Javacord's side.📝 Interaction Support for Paginate
This version of Velen now supports interactions for Pagination Helper, please note that this change has introduced a major breaking change for any code that uses
PaginateEvent
, here is an example of the previousPaginateEvent
:And here is how it looks in this new version:
Your IDE should assist you into fixing this breaking change, don't worry.
💭 Why the sudden breaking change?
The sudden breaking change was to introduce this new interaction support while also reducing code duplication as much as possible, otherwise, you would be expecting at least a very fat package for this framework. You can find all the changes here.
😭 Another Breaking Change
There is another breaking change to Velen which involves the slash event but don't worry, you can quickly fix this through
CTRL + F
andCTRL + R
, the change addedSlashCommandCreateEvent
to theonEvent
forVelenSlashEvent
which is needed to support Pagination with Interactions.Old:
New:
🌃 Named Options is now supported!
Velen now supports named options, or otherwise named as routed options, which as the name implies works similar to a web framework's router which allows message commands and hybrid commands to be named and be conditioned from the get-go. This is by far one of the better changes of Velen but it is also breaking for message commands which can be fixed easily.
📦 Syntax and Formats
To first understand how this all works, we have to look in depth of the syntax for the formats:
:[optionName]
is how a placeholder for an option looks.:[optionName::(choose,only,among,us)]
is how a placeholder with limited options (ignore casing) looks, the user has to only pick among the options inside the::(...)
. PLEASE NOTE THAT VELEN DOES NOT SUPPORT PLACING SPACES BETWEEN OPTIONS:[optionName:(choose,only,among,us)]
is similar to the one above this but with strict casing.:[optionName:{^[0-9]}]
is a regex pattern option, this first checks if the option in that index matches the regex.You can only place one regex pattern checker and option limiter inside a option (you can have both though), with a full example of a format utilizing all looking like this:
The format above tells Velen that the command should have 4 arguments, the first argument will be named as
name
and the second argument will bedifficulty
and should match eitherhard, medium or easy
(case insensitive) with the third argument being namedtopic
and should match eitheranime, politics
(case insensitive) and lastly, the last argument should be namedamount
and should match the regex pattern:^[0-9]
which means it should be a digit.The beauty of this entire thing is, you can have multiple formats and Velen will still accurately grab the correct option name but ensure that the name of the options are unique in each format otherwise Velen will pick up only the first case. An instance with multiple formats is:
If your command has all those formats, Velen will still be able to fetch the correct option name, so don't worry. 😄
💯 Adding formats to your commands and syntax
This is the required method to have this entire thing working, you have to add a format to your command during building using the
VelenCommandBuilder#addFormats(...)
method, for instance:The example above will reply with
Hello <name>
if there is a name present, otherwise replies withHello Unknown Person
and ifcondition
is present and also is eithermorning or night
then it will reply withGoodmorning <name>
orGoodnight <name>
.Hybrid commands also work the same but with extra steps on getting the value of the option since Slash Commands supports several types like
integer
and others which Velen will automatically convert for you for Hybrid Commands, example of option grabbing with name on Velen would be:args.withName("name").get().asString().get()
.😱 Breaking Change
The breaking change this time is that
VelenEvent
andVelenServerEvent
now has an extra parameter from:🏢 Of(type) syntax for arguments.
The of-type syntax for message options or arguments is another key-feature of Velen which allows bots using both hybrid and message commands to be able to fetch the right type of argument or option for their commands. For example, if you want to fetch a user, all you have to do is add
:of(user)
and Velen will automatically check it for you.You can only add one
:of(type)
for each option as per common sense.:[optionName:of(numeric))]
which will mean this option must be of numerical (alias of:[optionName:{^[0-9]}]
):[$optionName:of(boolean)]
which will mean this option must be of boolean (alias of:[optionName:{true|false}
):[optionName:of(user))]
which will mean this option must be of user mention.:[$optionName:of(channel)]
which will mean this option must be of channel mention.:[optionName:of(role))]
which will mean this option must be of role mention.:[$optionName:of(message)]
which will mean this option must be of message link.:[optionName:of(snowflake))]
which will mean this option must be of Discord ID.:[$optionName:of(emoji)]
which will mean this option must be of emoji.:[$optionName:of(webhook)]
which will mean this option must be of webhook.🪙 hasMany and getWithMany
Velen's new argument system now supports fetching of multiple values with the same name for message commands, take for instance, the
say
command with the formatsay :[text]
, normally that would only be able to fetch all the arguments ofHello World
if it is quoted but now, by addinghas_many: true
on the option on your.velen
file or simply appending:hasMany()
on the format (say :[text:hasMany()]
), Velen will be able to join all the multiple values with the same name into one.You can see this in the newer examples of hybrid commands on the new system.
This discussion was created from the release v3.0.0.
Beta Was this translation helpful? Give feedback.
All reactions