-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatCommands.cs
More file actions
108 lines (97 loc) · 3.14 KB
/
ChatCommands.cs
File metadata and controls
108 lines (97 loc) · 3.14 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
namespace TheOneChatServer
{
static class ChatCommands
{
private static string prefix = "/";
public static void InitCommands()
{
ChatCommand helpCommand = new ChatCommand("/Help");
ChatCommand pingCommand = new ChatCommand("/Ping");
ChatCommand fickerCommand = new ChatCommand("/Ficker");
}
public static void PerformCommand(User sender, string command)
{
if (CommandManager.RunCommand(command))
{
sender.SendMessage(command);
if (command.ToLower().Equals("/help"))
{
foreach(ChatCommand chatCommand in CommandManager.GetCommands())
{
sender.SendMessage(chatCommand.GetCommandInput());
}
}
ChatCommand currentCommand = GetCommandByInputString(command);
currentCommand.CallCommand();
}
else
{
sender.SendMessage(String.Format("Couldn't find the command: " + command));
}
}
private static ChatCommand GetCommandByInputString(string cmdIn)
{
foreach(ChatCommand command in CommandManager.GetCommands())
{
if (command.GetCommandInput().Equals(cmdIn))
{
return command;
}
}
return null;
}
private static class CommandManager
{
private static List<ChatCommand> commands = new List<ChatCommand>();
public static void AddCommand(string commandIn, ChatCommand command)
{
commands.Add(command);
}
public static bool RunCommand(string cmdIn)
{
foreach (ChatCommand chatCommand in commands)
{
if (chatCommand.GetCommandInput().Equals(cmdIn, StringComparison.InvariantCultureIgnoreCase))
{
chatCommand.CallCommand();
return true;
}
}
return false;
}
public static List<ChatCommand> GetCommands()
{
return commands;
}
}
private class ChatCommand
{
private Receiver commandReceiver;
private string commandInput;
public ChatCommand(string commandInput)
{
this.commandInput = commandInput;
//commandReceiver = receiver;
CommandManager.AddCommand(commandInput, this);
}
public void CallCommand()
{
//commandReceiver.CallCommand();
}
public string GetCommandInput()
{
return commandInput;
}
//Receiver commandReceiver;
}
public interface Receiver
{
public abstract void CallCommand();
}
public static string GetPrefix()
{
return prefix;
}
}
}