-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLilyItem.cs
More file actions
371 lines (323 loc) · 9.23 KB
/
LilyItem.cs
File metadata and controls
371 lines (323 loc) · 9.23 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
using System;
using System.Collections;
using System.Windows.Forms;
namespace lilySharp
{
/// <summary>
/// The base class for IUser/IDiscussion classes
/// </summary>
public abstract class LilyObject : IComparable, ILilyObject
{
protected LilyWindow window;
protected string name, handle;
/// <summary>
/// Allows access to the IUser/IDiscussion name
/// </summary>
/// <value>Allows access to the IUser/IDiscussion name</value>
public string Name
{
get { return name;}
set { name = value;}
}
/// <summary>
/// Allows access to the IUser/IDiscussion object ID
/// </summary>
/// <value>Allows access to the IUser/IDiscussion object ID</value>
public string Handle
{
get { return handle; }
}
/// <summary>
/// Allows access to the IUser/IDiscussion window
/// </summary>
/// <value>Allows access to the IUser/IDiscussion window</value>
public LilyWindow Window
{
get { return window;}
set { window = value;}
}
/// <summary>
/// Returns the name of the IUser/IDiscussion
/// </summary>
/// <returns>The IUser/IDiscussion's name</returns>
public override string ToString()
{
return name;
}
/// <summary>
/// Compairs two IUser/IDiscussion's object IDs to determine if they are equal
/// </summary>
/// <param name="lhs">The left hand operand</param>
/// <param name="rhs">The right hand operand</param>
/// <returns>True if they are equal, false otherwise</returns>
/// <remarks>
/// Need to do some crazy tricks to compensate for null values =(
/// </remarks>
public static bool operator==(LilyObject lhs, LilyObject rhs)
{
try
{
return lhs.Equals(rhs);
}
catch(System.NullReferenceException) // happens if lhs is null
{
try
{
return rhs.Equals(lhs);
}
catch(System.NullReferenceException) // happens if both references are null
{
return true;
}
}
}
/// <summary>
/// Compairs two IUser/IDiscussion's object IDs to determine if they are not equal
/// </summary>
/// <param name="lhs">Left hand operand</param>
/// <param name="rhs">Right hand operand</param>
/// <returns>True of the oIDs are not equal, false otherwise</returns>
public static bool operator!=(LilyObject lhs, LilyObject rhs)
{
return !(lhs == rhs);
}
/// <summary>
/// Compairs this with another object to see if they are equal
/// </summary>
/// <param name="o">Object to compair this to</param>
/// <returns>True if the object is a ILilyObject and it's oID matches this one, false otherwise</returns>
public override bool Equals(object o)
{
if(o == null || o.GetType() != GetType())
return false;
return ((ILilyObject)o).Handle == this.handle;
}
/// <summary>
/// Returns this IUser/IDiscussion's object ID in numeric form as this item's hashcode
/// </summary>
/// <returns>The numerical representation of this IUser/IDiscussion's oID</returns>
public override int GetHashCode()
{
string str = handle.Substring(1,handle.Length - 1);
return int.Parse(str);
}
public int CompareTo(object obj)
{
if(obj == null) return -1;
if(!(obj.GetType() == this.GetType()))
throw new ArgumentException("Agument is not of type ILilyObject");
return string.Compare(this.ToString(), obj.ToString());
}
}
/// <summary>
/// Holds the data for a discussion
/// </summary>
public class Discussion : LilyObject, IDiscussion
{
private string title, game;
private bool priv,
connect,
inv,
moderated,
info,
memo;
private DateTime created,
lastInput;
public Discussion(Hashtable attributes)
{
handle = attributes["HANDLE"] as string;
name = attributes["NAME"] as string;
title = attributes["TITLE"] as string;
if(attributes["GAME"] != null) game = attributes["GAME"] as string;
created = Util.ConvertFromUnixTime(attributes["CREATION"] as string);
lastInput = Util.ConvertFromUnixTime(attributes["INPUT"] as string);
priv = ((string)attributes["ATTRIB"]).IndexOf("private") == -1 ? false : true;
connect = ((string)attributes["ATTRIB"]).IndexOf("connect") == -1 ? false : true;
inv = ((string)attributes["ATTRIB"]).IndexOf("inv") == -1 ? false : true;
moderated = ((string)attributes["ATTRIB"]).IndexOf("moderated") == -1 ? false : true;
info = ((string)attributes["ATTRIB"]).IndexOf("info") == -1 ? false : true;
memo = ((string)attributes["ATTRIB"]).IndexOf("memo") == -1 ? false : true;
}
#region Properties
/// <summary>
/// Allows access to this IDiscussion's private flag
/// </summary>
/// <value>Allows access to this IDiscussion's private flag</value>
public bool Private
{
get { return priv; }
set { priv = value;}
}
/// <summary>
/// Allows access to this IDiscussion's connect flag
/// </summary>
/// <value>Allows access to this IDiscussion's connect flag</value>
public bool Connect
{
get { return connect; }
}
/// <summary>
/// Allows access to this IDiscussion's invulnerable flag
/// </summary>
/// <value>Allows access to this IDiscussion's invulnerable flag</value>
public bool Invulnerable
{
get { return inv; }
set { inv = value;}
}
/// <summary>
/// Allows access to this IDiscussion's info flag
/// </summary>
/// <value>Allows access to this IDiscussion's info flag</value>
public bool Info
{
get { return info; }
set { info = value;}
}
/// <summary>
/// Allows access to this IDiscussion's memo flag
/// </summary>
/// <value>Allows access to this IDiscussion's memo flag</value>
public bool Memo
{
get { return memo;}
set { memo = value;}
}
public bool Moderated
{
get { return moderated;}
set { moderated = value;}
}
/// <summary>
/// Allows access to this IDiscussion's title
/// </summary>
/// <value>Allows access to this IDiscussion's title</value>
public string Title
{
get { return title; }
set { title = value;}
}
#endregion
}
/// <summary>
/// Holds the data for a user
/// </summary>
public class User : LilyObject, IUser
{
private string blurb,
pronoun;
private bool finger,
info,
memo;
private DateTime login,
lastInput;
private States state;
private Ignore ignore;
public User(Hashtable attributes)
{
handle = attributes["HANDLE"] as string;
name = attributes["NAME"] as string;
blurb = attributes["BLURB"] == null ? "" : attributes["BLURB"] as string;
pronoun = attributes["PRONOUN"] == null ? "" : attributes["PRONOUN"] as string;
login = attributes["LOGIN"] == null ? DateTime.Now : Util.ConvertFromUnixTime(attributes["LOGIN"] as string);
lastInput = attributes["INPUT"] == null ? DateTime.Now : Util.ConvertFromUnixTime(attributes["INPUT"] as string);
ignore = new Ignore(false,false);
// Determine state
switch(attributes["STATE"] as string)
{
case "here":
state = States.Here;
break;
case "away":
state = States.Away;
break;
case "detach":
state = States.Detached;
break;
default:
state = States.Disconnected;
break;
}
// Determine attributes
if(attributes["ATTRIB"] != null)
{
foreach(string attrib in ((string)attributes["ATTRIB"]).Split(new char[]{','}))
{
switch(attrib)
{
case "finger":
finger = true;
break;
case "info":
info = true;
break;
case "memo":
memo = true;
break;
} // end case
} // end foreach
} // end if
}
#region Properties
/// <summary>
/// Allows access to the IUser's blurb
/// </summary>
/// <value>Allows access to the IUser's blurb</value>
public string Blurb
{
get { return blurb;}
set { blurb = value;}
}
/// <summary>
/// Allows access to the IUser's pronoun
/// </summary>
/// <value>Allows access to the IUser's pronoun</value>
public string Pronoun
{
get { return pronoun; }
set { pronoun = value;}
}
/// <summary>
/// Allows access to the IUser's state
/// </summary>
/// <value>Allows access to the IUser's state</value>
public States State
{
get { return state; }
set { state = value;}
}
/// <summary>
/// Allows access to the IUser's finger flag
/// </summary>
/// <value>Allows access to the IUser's finger flag</value>
public bool Finger
{
get { return finger; }
set { finger = value; }
}
/// <summary>
/// Allows access to the IUser's info flag
/// </summary>
/// <value>Allows access to the IUser's info flag</value>
public bool Info
{
get { return info;}
set { info = value;}
}
/// <summary>
/// Allows access to the IUser's memo flag
/// </summary>
/// <value>Allows access to the IUser's memo flag</value>
public bool Memo
{
get { return memo;}
set { memo = value;}
}
public Ignore IgnoreSettings
{
get { return ignore;}
set { ignore = value;}
}
#endregion
}
}