Fix wrong source when creating new task or event

This commit is contained in:
Vyn 2024-11-05 16:55:13 +01:00
parent 893fcc11e3
commit ab2200ecc1
3 changed files with 18 additions and 1 deletions

View file

@ -149,6 +149,18 @@ Source *Mirai::getSourceById(int id)
return source->get();
}
Source *Mirai::getSourceByName(const std::string &name)
{
auto source = std::ranges::find_if(sources_, [&](const std::unique_ptr<Source> &source) {
return source->name() == name;
});
assert(source != sources_.end()); // This should not happen
if (source == sources_.end()) {
return nullptr;
}
return source->get();
}
void Mirai::onSourceAdded(std::function<void(Source *)> f)
{
sourceAdded.registerCallback(f);