901d74c92b70585c95e57007daa9b1f647059c8d
[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 string nickname;
13 private string decoratedNickname;
14
15 #endregion
16
17 #region Public properties
18
19 /// <summary>
20 /// Nickname of user.
21 /// </summary>
22 public string Nickname
23 {
24 get
25 {
26 return nickname;
27 }
28 }
29
30 /// <summary>
31 /// Decorated nickname of user.
32 /// </summary>
33 public string DecoratedNickname
34 {
35 get
36 {
37 return decoratedNickname;
38 }
39 }
40
41 /// <summary>
42 /// Wether user is channel operator.
43 /// </summary>
44 public bool Operator
45 {
46 get
47 {
48 return decoratedNickname.StartsWith("@");
49 }
50 }
51
52 /// <summary>
53 /// Wether user has voice.
54 /// </summary>
55 public bool Voice
56 {
57 get
58 {
59 return decoratedNickname.StartsWith("+");
60 }
61 }
62
63 #endregion
64
65 /// <summary>
66 /// Constructor.
67 /// </summary>
68 /// <param name="nickname">Nickname (possibly decorated) of user.</param>
69 public IrcUser(string nickname)
70 {
71 this.decoratedNickname = nickname.Trim();
72 this.nickname = StripDecoration(decoratedNickname);
73 }
74
75 /// <summary>
76 /// Strip docoration of nickname.
77 /// </summary>
78 /// <param name="nickname">Possible decorated nickname.</param>
79 /// <returns>Undecorated nickname.</returns>
80 public static string StripDecoration(string decoratedNickname)
81 {
82 if (decoratedNickname.StartsWith("@"))
83 {
84 return decoratedNickname.Substring(1);
85 }
86 else if (decoratedNickname.StartsWith("+"))
87 {
88 return decoratedNickname.Substring(1);
89 }
90 else
91 {
92 return decoratedNickname;
93 }
94 }
95 }
96 }