Merge 12735:15568 from xmlbuildsystem branch
[reactos.git] / irc / TechBot / TechBot.IRCLibrary / IrcUser.cs
1 using System;
2
3 namespace TechBot.IRCLibrary
4 {
5 /// <summary>
6 /// IRC user.
7 /// </summary>
8 public class IrcUser
9 {
10 #region Private fields
11
12 private IrcClient owner;
13 private string nickname;
14 private string decoratedNickname;
15
16 #endregion
17
18 #region Public properties
19
20 /// <summary>
21 /// Owner of this channel.
22 /// </summary>
23 public IrcClient Owner
24 {
25 get
26 {
27 return owner;
28 }
29 }
30
31 /// <summary>
32 /// Nickname of user.
33 /// </summary>
34 public string Nickname
35 {
36 get
37 {
38 return nickname;
39 }
40 }
41
42 /// <summary>
43 /// Decorated nickname of user.
44 /// </summary>
45 public string DecoratedNickname
46 {
47 get
48 {
49 return decoratedNickname;
50 }
51 }
52
53 /// <summary>
54 /// Wether user is channel operator.
55 /// </summary>
56 public bool Operator
57 {
58 get
59 {
60 return decoratedNickname.StartsWith("@");
61 }
62 }
63
64 /// <summary>
65 /// Wether user has voice.
66 /// </summary>
67 public bool Voice
68 {
69 get
70 {
71 return decoratedNickname.StartsWith("+");
72 }
73 }
74
75 #endregion
76
77 /// <summary>
78 /// Constructor.
79 /// </summary>
80 /// <param name="owner">Owner of this channel.</param>
81 /// <param name="nickname">Nickname (possibly decorated) of user.</param>
82 public IrcUser(IrcClient owner,
83 string nickname)
84 {
85 if (owner == null)
86 {
87 throw new ArgumentNullException("owner", "Owner cannot be null.");
88 }
89 this.owner = owner;
90 this.decoratedNickname = nickname.Trim();
91 this.nickname = StripDecoration(decoratedNickname);
92 }
93
94 /// <summary>
95 /// Talk to the user.
96 /// </summary>
97 /// <param name="text">Text to send to the user.</param>
98 public void Talk(string text)
99 {
100 if (text == null)
101 {
102 throw new ArgumentNullException("text", "Text cannot be null.");
103 }
104
105 owner.SendMessage(new IrcMessage(IRC.PRIVMSG,
106 String.Format("{0} :{1}",
107 nickname,
108 text)));
109 }
110
111 /// <summary>
112 /// Strip docoration of nickname.
113 /// </summary>
114 /// <param name="nickname">Possible decorated nickname.</param>
115 /// <returns>Undecorated nickname.</returns>
116 public static string StripDecoration(string decoratedNickname)
117 {
118 if (decoratedNickname.StartsWith("@"))
119 {
120 return decoratedNickname.Substring(1);
121 }
122 else if (decoratedNickname.StartsWith("+"))
123 {
124 return decoratedNickname.Substring(1);
125 }
126 else
127 {
128 return decoratedNickname;
129 }
130 }
131 }
132 }