feat: add subscription and photo sending to bot handler
This commit is contained in:
parent
2bbbc32322
commit
c3fb8b9c6f
@ -59,6 +59,39 @@ public class BotHandler
|
||||
}
|
||||
}
|
||||
|
||||
public void Subscribe(long id)
|
||||
{
|
||||
if (_subscribers.Any(s => s.Identifier == id))
|
||||
{
|
||||
_logger.LogWarning("User {Id} is already subscribed", id);
|
||||
return;
|
||||
}
|
||||
|
||||
_subscribers.Add(new ChatId(id));
|
||||
_logger.LogInformation("User {Id} subscribed to receive messages", id);
|
||||
}
|
||||
|
||||
public async Task UpdatePhoto(string path)
|
||||
{
|
||||
if (_bot is null)
|
||||
{
|
||||
_logger.LogWarning("Bot is not initialized yet");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_subscribers.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("No subscribers to send message to");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var subscriber in _subscribers)
|
||||
{
|
||||
await using var stream = File.OpenRead(path);
|
||||
var inputFile = InputFile.FromStream(stream, Path.GetFileName(path));
|
||||
await _bot.SendPhoto(subscriber, inputFile, "Detected object");
|
||||
}
|
||||
}
|
||||
private async Task SendImageTest(long id)
|
||||
{
|
||||
if (_bot is null)
|
||||
|
Loading…
Reference in New Issue
Block a user