a822e4ca6e9c968b02a4734a4145e8308e03eac4
[reactos.git] / irc / TechBot / TechBot.Library / Commands / Base / Command.cs
1 using System;
2 using System.Text.RegularExpressions;
3
4 namespace TechBot.Library
5 {
6 public abstract class Command
7 {
8 protected TechBotService m_TechBotService = null;
9 protected MessageContext m_Context = null;
10 protected string m_Params = null;
11
12 public TechBotService TechBot
13 {
14 get { return m_TechBotService; }
15 set { m_TechBotService = value; }
16 }
17
18 public MessageContext Context
19 {
20 get { return m_Context; }
21 set { m_Context = value; }
22 }
23
24 public virtual bool AnswerInPublic
25 {
26 get { return false; }
27 }
28
29 public string Name
30 {
31 get
32 {
33 CommandAttribute commandAttribute = (CommandAttribute)
34 Attribute.GetCustomAttribute(GetType(), typeof(CommandAttribute));
35
36 return commandAttribute.Name;
37 }
38 }
39
40 public string Parameters
41 {
42 get { return m_Params; }
43 set { m_Params = value; }
44 }
45
46 protected virtual void Say()
47 {
48 TechBot.ServiceOutput.WriteLine(Context, string.Empty);
49 }
50
51 protected virtual void Say(string message)
52 {
53 TechBot.ServiceOutput.WriteLine(Context, message);
54 }
55
56 protected virtual void Say(string format , params object[] args)
57 {
58 TechBot.ServiceOutput.WriteLine(Context, String.Format(format, args));
59 }
60
61 public void Run()
62 {
63 if (Context is ChannelMessageContext)
64 {
65 if (AnswerInPublic)
66 {
67 ExecuteCommand();
68 }
69 else
70 {
71 Say("Sorry, I only respond '{0}' in private , PM me!", Name);
72 }
73 }
74 else
75 {
76 ExecuteCommand();
77 }
78 }
79
80 public abstract void ExecuteCommand();
81
82 public virtual void Initialize()
83 {
84 }
85
86 public virtual void DeInitialize()
87 {
88 }
89 }
90 }