Skip to content

Commit 89d013d

Browse files
committed
Add name field to bot events
1 parent f398662 commit 89d013d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

RealTimeWeatherMonitoringApp/Domain/Common/BotEventArgs.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ namespace RealTimeWeatherMonitoringApp.Domain.Common;
22

33
public class BotEventArgs : EventArgs
44
{
5+
public string BotName { get; }
56
public string Message { get; }
6-
public BotEventArgs(string message) => Message = message;
7+
8+
public BotEventArgs(string botName, string message)
9+
{
10+
BotName = botName;
11+
Message = message;
12+
}
713
}

RealTimeWeatherMonitoringApp/Domain/Models/Controller/BotController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BotController<TEvaluated> : IBotController<TEvaluated>
99
public BotController(Bot<TEvaluated> bot) => _bot = bot;
1010

1111
public BotEventArgs? React(DataChangeEventArgs<TEvaluated> args) =>
12-
args.NewData != null && IsTriggeredBy(args.NewData) ? new BotEventArgs(_bot.Message) : null;
12+
args.NewData != null && IsTriggeredBy(args.NewData) ? new BotEventArgs(_bot.Name, _bot.Message) : null;
1313

1414
private bool IsTriggeredBy(TEvaluated data) => _bot.Enabled && _bot.Evaluator.Evaluate(data);
1515
}

RealTimeWeatherMonitoringApp/Presentation/UserController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class UserController
1616

1717
public void Start()
1818
{
19-
BotNotificationService.OnBotNotification += (_, args) => Console.WriteLine(args.Message);
19+
BotNotificationService.OnBotNotification += (_, args) =>
20+
Console.WriteLine($"\n{args.BotName}: {args.Message}");
2021

2122
while (true)
2223
{

0 commit comments

Comments
 (0)