getObject method
Get the collected object by type and name.
{type} is the type of the object.
{name} is the name of the object.
{autoLoad} is a boolean value that indicates whether the object should be loaded from the server if it is not collected.
{botName} is the name of the bot that the object belongs to. If not specified, the bot that is currently collected will be used. {botName} should not be specified if the bot is already collected to avoid unnecessary loading.
Implementation
Future<BotObject?> getObject(BotObjectType type, String name,
{String? botName}) async {
if (botName == null && _bot == null) {
GetIt.I<BotnoiClient>().error.add(
"[collector.getObject] : A bot must be collected first or the botName must be specified");
return null;
}
String key =
"${botName ?? _bot?.botName}/${type.stringType}/${BotObjectNamer.byAction(name, type)}";
if (_objects.containsKey(key)) {
return _objects[key];
} else {
if (implicitCollecting) {
if (botName != null && botName != _bot?.botName) {
Bot? loadedBot =
await BotnoiChatbot.serverInstance.findBotWithName(botName);
if (loadedBot != null) {
BotObject? loadedObject =
await loadedBot.opt.findObjectWithName(type: type, name: name);
if (loadedObject != null) {
collectObject(loadedObject);
return loadedObject;
} else {
return null;
}
} else {
return null;
}
}
if (_bot != null) {
BotObject? loadedObject =
await _bot!.opt.findObjectWithName(type: type, name: name);
if (loadedObject != null) {
collectObject(loadedObject);
return loadedObject;
} else {
return null;
}
}
}
return null;
}
}