Comments (5)
I thought about this aswell, however I designed this library to use as minimal sinusbot functions as possible for performance reasons.
You could emulate this behaviour:
createCommand("foo")
.addArgument(
createGroupedArgument("or")
.setName("client")
.argument(createArgument("client").setName("uid"))
.argument(createArgument("string").setName("name").min(1))
)
.exec((invoker, args) => {
let client = null
if (args.client.name) {
client = backend.getClientByName(args.client.name)
} else {
client = backend.getClientByUID(args.client.uid)
}
//no online client found
if (!client) return
})
However i did not test the above code
PS: I'm sorry if you don't take feature requests or this is the wrong place for it.
this is the right place for it ;)
from sinusbot-command.
Got some time for testing and it dosn't seem to work properly. If i set the client argument first it processes the uuid but gives me invalid usage with a string:
.addArgument(
commandlib.createGroupedArgument("or")
.setName("target")
.argument(commandlib.createArgument("client").setName("uid"))
.argument(commandlib.createArgument("string").setName("name").min(1))
)
The other way around it takes both but treats both as string, so the client argument is ignored:
.addArgument(
commandlib.createGroupedArgument("or")
.setName("target")
.argument(commandlib.createArgument("string").setName("name").min(1))
.argument(commandlib.createArgument("client").setName("uid"))
)
seems like i'll have to do it the manual way. Also wouldn't string give problems with names with a space? or is there some way to input (in chat) a string with spaces which will count as one argument?
For the moment i'll use this workaround which works pretty good (except for names with spaces):
.addArgument(commandlib.createArgument("string").setName("target"))
.exec((client, args, reply, raw) => {
let target = backend.getClientByUID(args.target);
if(!target) {
target = backend.getClientByName(args.target);
}
if(!target) return reply("Could not find Client: "+args.target);
});
from sinusbot-command.
I tried to reproduce your first example with following code:
const command = require("command")
command.createCommand("test")
.addArgument(
command.createGroupedArgument("or")
.setName("target")
.argument(command.createArgument("client").setName("uid"))
.argument(command.createArgument("string").setName("name").min(1))
)
.exec((invoker, args, reply) => {
console.log(args)
reply(JSON.stringify(args))
})
with command.js version 1.2.3
the Grouped "or" argument always priorizes the first added argument, if it fails it checks the next one
from sinusbot-command.
Ok i found the issue. The command.js i got with the sinusbot update was on version 1.2.1 which seems to have that bug. Updated to 1.2.3 and your example instantly worked
from sinusbot-command.
Alright, the feature with the nickname will not be implemented since its a bit problematic parsing the arguments when a client himself has spaces in his name
from sinusbot-command.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sinusbot-command.