-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathDNDCommand.cs
More file actions
54 lines (49 loc) · 2.04 KB
/
DNDCommand.cs
File metadata and controls
54 lines (49 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using DevChatter.Bot.Core.Commands;
using DevChatter.Bot.Core.Commands.Operations;
using DevChatter.Bot.Core.Data;
using DevChatter.Bot.Core.Data.Model;
using DevChatter.Bot.Core.Events.Args;
using DevChatter.Bot.Core.Systems.Chat;
using System.Collections.Generic;
using System.Linq;
namespace DevChatter.Bot.Core.Games.DealNoDeal
{
public class DNDCommand : BaseCommand, IGameCommand
{
private readonly DealNoDealGame _dealNoDealGame;
public IGame Game => _dealNoDealGame;
public DNDCommand(IRepository repository, DealNoDealGame dealNoDealGame, IChatClient chatClient) : base(repository, UserRole.Everyone)
{
_dealNoDealGame = dealNoDealGame;
_chatClient = chatClient;
HelpText =
"Use \"!dnd\" to start a game. Use \"!dnd pick x\" to pick/guess a box. Use \"!dnd accept\" or \"!dnd decline\" to accept or decline offers .";
}
private List<ICommandOperation> _operations;
private readonly IChatClient _chatClient;
public List<ICommandOperation> Operations => _operations ?? (_operations = new List<ICommandOperation>
{
new PickABoxOperation(_dealNoDealGame,_chatClient),
new MakeADealOperation(_dealNoDealGame,_chatClient)
});
protected override void HandleCommand(IChatClient chatClient, CommandReceivedEventArgs eventArgs)
{
string argumentOne = eventArgs?.Arguments?.FirstOrDefault();
ChatUser chatUser = eventArgs?.ChatUser;
//dnd start dnd pick
var operationToUse = Operations.SingleOrDefault(x => x.ShouldExecute(argumentOne));
if (operationToUse != null)
{
string resultMessage = operationToUse.TryToExecute(eventArgs);
}
else
{
if (string.IsNullOrWhiteSpace(argumentOne))
{
// attempting to start a game
_dealNoDealGame.AttemptToStartGame(chatUser);
}
}
}
}
}