-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatform.cs
429 lines (371 loc) · 13.9 KB
/
chatform.cs
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#region Namespaces
using System;
using System.Media;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
//XMPP Namespace
using agsXMPP;
//AIML Namespace
using AIMLbot;
#endregion
namespace XIMA_Beta
{
public partial class chatform1 : Form
{
#region Declaration
public String m_Jid;
private String m_path;
private String halfid;
private bool drag = false;
private Point start_point = new Point(0, 0);
private bool draggable = true;
private string exclude_list = "";
private User myUser;
private System.Windows.Forms.ToolStripItem pinx;
#endregion
#region Construction
public chatform1(String jid)
{
try
{
int halfindex;
InitializeComponent();
m_Jid = jid;
halfindex = m_Jid.IndexOf('@');
halfid = m_Jid.Remove(halfindex);
m_path = "userdata/" + m_Jid + ".xml";
//mouse events
this.MouseDown += new MouseEventHandler(Form_MouseDown);
this.MouseUp += new MouseEventHandler(Form_MouseUp);
this.MouseMove += new MouseEventHandler(Form_MouseMove);
label1.Text = m_Jid;
myUser = new User(m_Jid, chatload.myBot);
if (File.Exists(m_path))
{
myUser.Predicates.loadSettings(m_path);
}
//background image
switch (XIMA.backno)
{
case 2:
this.BackgroundImage = global::XIMA_Beta.Properties.Resources._2;
break;
case 3:
this.BackgroundImage = global::XIMA_Beta.Properties.Resources._3;
break;
case 4:
this.BackgroundImage = global::XIMA_Beta.Properties.Resources._4;
break;
case 5:
this.BackgroundImage = global::XIMA_Beta.Properties.Resources._5;
break;
case 6:
this.BackgroundImage = global::XIMA_Beta.Properties.Resources._6;
break;
default:
this.BackgroundImage = global::XIMA_Beta.Properties.Resources._1;
break;
}
pinx = XIMA.Tray_menu.Items.Add(m_Jid);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion
#region playsound
private void playSimpleSound()
{
SoundPlayer simpleSound = new SoundPlayer(global::XIMA_Beta.Properties.Resources.message);
simpleSound.Play();
}
#endregion
#region User Message Sending
private void sendtext_KeyPress_1(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == 13)
{
agsXMPP.protocol.client.Message msgs = new agsXMPP.protocol.client.Message();
msgs.Type = agsXMPP.protocol.client.MessageType.chat;
msgs.To = new Jid(m_Jid);
msgs.Body = sendtext.Text;
XIMA.xmppCon.Send(msgs);
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
chattext.AppendText("Me: ");
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Regular);
chattext.AppendText(sendtext.Text);
chattext.AppendText("\r\n");
chattext.AppendText("\r\n");
sendtext.Text = "";
chattext.SelectionStart = chattext.Text.Length;
chattext.ScrollToCaret();
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion
#region Incoming
public void incmoing(agsXMPP.protocol.client.Message msg)
{
try
{
if (msg.From.Bare == m_Jid)
{
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
chattext.AppendText(halfid + ": ");
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Regular);
chattext.AppendText(msg.Body);
chattext.AppendText("\r\n");
chattext.AppendText("\r\n");
chattext.SelectionStart = chattext.Text.Length;
chattext.ScrollToCaret();
playSimpleSound();
//Bot Interaction
if (checkBox1.Checked == true)
{
Request r = new Request(msg.Body, myUser, chatload.myBot);
Result res = chatload.myBot.Chat(r);
String respond;
respond = res.Output;
agsXMPP.protocol.client.Message msgs = new agsXMPP.protocol.client.Message();
msgs.Type = agsXMPP.protocol.client.MessageType.chat;
msgs.To = new Jid(m_Jid);
msgs.Body = respond;
XIMA.xmppCon.Send(msgs);
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
chattext.AppendText("AIIMA: ");
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Regular);
chattext.AppendText(respond);
chattext.AppendText("\r\n");
chattext.AppendText("\r\n");
chattext.SelectionStart = chattext.Text.Length;
chattext.ScrollToCaret();
}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion
#region Type Focus, No-title-bar
private void chattext_Enter(object sender, EventArgs e)
{
sendtext.Focus();
}
private void chatform_Enter(object sender, EventArgs e)
{
sendtext.Focus();
}
//removing title bar
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
System.Windows.Forms.CreateParams cp = base.CreateParams;
cp.Style &= ~0x00C00000; // WS_CAPTION
return cp;
}
}
#endregion
#region Overriden Functions for Drag
protected override void OnControlAdded(ControlEventArgs e)
{
try
{
//
//Add Mouse Event Handlers for each control added into the form,
//if Draggable property of the form is set to true and the control
//name is not in the ExcludeList.Exclude list is the comma separated
//list of the Controls for which you do not require the mouse handler
//to be added. For Example a button.
//
if (this.Draggable && (this.ExcludeList.IndexOf(e.Control.Name) == -1))
{
e.Control.MouseDown += new MouseEventHandler(Form_MouseDown);
e.Control.MouseUp += new MouseEventHandler(Form_MouseUp);
e.Control.MouseMove += new MouseEventHandler(Form_MouseMove);
}
base.OnControlAdded(e);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion
#region Control box
private void button2_Click(object sender, EventArgs e)
{
//minimize
this.Visible = false;
}
private void button1_Click_1(object sender, EventArgs e)
{
try
{
//remove from home list
for (int t = 0; t < chatload.chatwincount; t++)
{
if (chatload.chatwinbase[t] == m_Jid)
{
chatload.chatwinbase[t] = ""; ;
}
}
//close
myUser.Predicates.DictionaryAsXML.Save(m_path);
XIMA.Tray_menu.Items.Remove(pinx);
playSimpleSound1();
this.Close();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion
#region Drag Event Handlers
void Form_MouseDown(object sender, MouseEventArgs e)
{
//
//On Mouse Down set the flag drag=true and
//Store the clicked point to the start_point variable
//
this.drag = true;
this.start_point = new Point(e.X, e.Y);
}
void Form_MouseUp(object sender, MouseEventArgs e)
{
//
//Set the drag flag = false;
//
this.drag = false;
}
void Form_MouseMove(object sender, MouseEventArgs e)
{
//
//If drag = true, drag the form
//
if (this.drag)
{
Point p1 = new Point(e.X, e.Y);
Point p2 = this.PointToScreen(p1);
Point p3 = new Point(p2.X - this.start_point.X,
p2.Y - this.start_point.Y);
this.Location = p3;
}
}
#endregion
#region Drag Properties
public string ExcludeList
{
set
{
this.exclude_list = value;
}
get
{
return this.exclude_list.Trim();
}
}
public bool Draggable
{
set
{
this.draggable = value;
}
get
{
return this.draggable;
}
}
#endregion
#region playsound1
private void playSimpleSound1()
{
SoundPlayer simpleSound = new SoundPlayer(global::XIMA_Beta.Properties.Resources.online);
simpleSound.Play();
}
#endregion
#region XIMA Loader
private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{
try
{
String respond;
if (checkBox1.Checked == true)
{
sendtext.Enabled = false;
respond = "AIIMA ON";
agsXMPP.protocol.client.Message msgs = new agsXMPP.protocol.client.Message();
msgs.Type = agsXMPP.protocol.client.MessageType.chat;
msgs.To = new Jid(m_Jid);
msgs.Body = respond;
XIMA.xmppCon.Send(msgs);
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
chattext.AppendText("AIIMA: ");
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Regular);
chattext.AppendText(respond);
chattext.AppendText("\r\n");
chattext.AppendText("\r\n");
chattext.SelectionStart = chattext.Text.Length;
chattext.ScrollToCaret();
}
else
{
sendtext.Enabled = true;
respond = "AIIMA Signing Off...";
agsXMPP.protocol.client.Message msgs = new agsXMPP.protocol.client.Message();
msgs.Type = agsXMPP.protocol.client.MessageType.chat;
msgs.To = new Jid(m_Jid);
msgs.Body = respond;
XIMA.xmppCon.Send(msgs);
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Bold);
chattext.AppendText("AIIMA: ");
chattext.SelectionFont = new Font("Microsoft Sans Serif", 9, FontStyle.Regular);
chattext.AppendText(respond);
chattext.AppendText("\r\n");
chattext.AppendText("\r\n");
chattext.SelectionStart = chattext.Text.Length;
chattext.ScrollToCaret();
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion
#region Load
private void chatform_Load(object sender, EventArgs e)
{
if (chatload.uniai == true)
{
checkBox1.Checked = true;
}
}
private void chatform_VisibleChanged(object sender, EventArgs e)
{
}
#endregion
#region clear chat
private void label2_Click_1(object sender, EventArgs e)
{
chattext.Text = null;
}
#endregion
}
}