This commit is contained in:
Szymon Uglis 2021-03-12 16:56:09 +01:00
parent 21a0aae017
commit de58a77979
No known key found for this signature in database
GPG key ID: 112376C5BEE91FE2
5 changed files with 21 additions and 14 deletions

View file

@ -57,6 +57,11 @@ class Commander with ICommandRegistrable {
AfterHandlerFunction? afterCommandHandler,
LoggerHandlerFunction? loggerHandlerFunction,
CommandExecutionError? commandExecutionError}) {
if (!PermissionsUtils.isApplied(client.intents, GatewayIntents.allUnprivileged)) {
_logger.shout("Commander cannot start without at least all unprivileged intents");
exit(1);
}
if (prefix == null && prefixHandler == null) {
_logger.shout("Commander cannot start without both prefix and prefixHandler");
exit(1);
@ -89,13 +94,14 @@ class Commander with ICommandRegistrable {
}
// Find matching command with given message content
final matchingCommand = _commandEntities._findMatchingCommand(event.message.content.replaceFirst(prefix, "").trim().split(" ")) as CommandHandler?;
final messageContentParts = event.message.content.replaceFirst(prefix, "").trim().split(" ");
final matchingCommand = _commandEntities._findMatchingCommand(messageContentParts) as CommandHandler?;
if(matchingCommand == null) {
return;
}
final fullCommandName = matchingCommand.getFullCommandName();
final fullCommandName = _getFullCommandFromMessage(matchingCommand, messageContentParts);
// construct commandcontext
final context = CommandContext._new(

View file

@ -1,5 +1,16 @@
part of nyxx_commander;
String _getFullCommandFromMessage(CommandHandler commandHandler, List<String> messageParts) {
var iterator = 1;
for(var e = commandHandler.parent; e != null; e = e.parent) {
iterator++;
}
messageParts.removeRange(iterator, messageParts.length);
return messageParts.join(" ");
}
// TODO: FIX. I think that is just awful but is does its job
extension _CommandMatcher on Iterable<CommandEntity> {
CommandEntity? _findMatchingCommand(Iterable<String> messageParts) {

View file

@ -28,15 +28,6 @@ class ClientOptions {
/// The number of messages to cache for each channel.
int messageCacheSize;
/// Whether or not to force fetch all of the members the client can see.
/// Can slow down ready times but is recommended if you rely on `Message.member`
/// or the member cache.
bool forceFetchMembers;
/// Allows to disable member caching on `GUILD_CREATE` event.
/// **It means client will collect members from other events**
bool cacheMembers;
/// Maximum size of guild for which offline member will be sent
int largeThreshold;
@ -71,8 +62,6 @@ class ClientOptions {
{this.allowedMentions,
this.shardCount,
this.messageCacheSize = 400,
this.forceFetchMembers = false,
this.cacheMembers = true,
this.largeThreshold = 50,
this.ignoredEvents = const [],
this.compressedGatewayPayloads = true,

View file

@ -240,6 +240,7 @@ class GuildMessage extends Message {
this.author = Webhook._new(raw["author"] as Map<String, dynamic>, client);
} else {
this.author = User._new(client, raw["author"] as Map<String, dynamic>);
this.client.users[this.author.id] = this.author as User;
}
if (raw["member"] != null) {

View file

@ -26,7 +26,7 @@ class MessageDeleteEvent {
this.channel = _ChannelCacheable(client, Snowflake(raw["d"]["channel_id"]));
this.messageId = Snowflake(raw["d"]["id"]);
final message = channel.getFromCache()?.messageCache[this.messageId];
this.message = channel.getFromCache()?.messageCache[this.messageId];
}
}