-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarpMessage.js
More file actions
104 lines (91 loc) · 2.93 KB
/
warpMessage.js
File metadata and controls
104 lines (91 loc) · 2.93 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
/* ************************************************************************
License: MIT
Authors: Lukas Michalski, Benjamin Zeller, Thorsten Schwalb
************************************************************************ */
qx.Class.define("pms.warpMessage",
{
extend : qx.core.Object,
/******************************************************************************
* CONSTRUCTOR
******************************************************************************/
construct : function()
{
this.regCommands = new qx.type.BaseArray();
this.invalidCommands = new qx.type.BaseArray();
},
/******************************************************************************
* MEMBERS
******************************************************************************/
members :
{
'regCommands' : null,
'invalidCommands' : null,
/******************************************************************************
* FUNCTION: registerCommand
******************************************************************************/
registerCommand : function (name)
{
this.regCommands.push(name);
},
/******************************************************************************
* FUNCTION: setInvalidCommand
******************************************************************************/
setInvalidCommand : function (name)
{
this.invalidCommands.push(name);
},
/******************************************************************************
* FUNCTION: isInvalidCommand
******************************************************************************/
isInvalidCommand : function (name)
{
if(qx.lang.Array.contains(this.invalidCommands,name))
return true;
else
return false;
},
/******************************************************************************
* FUNCTION: warpMessage
******************************************************************************/
warpMessage : function (Message,ChannelName)
{
var returnMessage = null;
if(Message.substr(0,1) != "/")
{
if(ChannelName != "default")
{
return "/send \""+ChannelName+"\" \""+Message+"\"";
}
else
{
return -1;
}
}
else
{
var command = pms.Parser.parseMessage(Message,true);
if(this.isInvalidCommand(command.name) == false)
{
if(qx.lang.Array.contains(this.regCommands,command.name))
{
if(ChannelName != "default")
{
returnMessage = "/"+command.name+" "+ChannelName;
if(command.arguments[0] != undefined)
returnMessage += " "+command.arguments[0];
}
}
else
{
returnMessage = Message;
}
}
else
{
returnMessage = undefined;
}
return returnMessage;
}
}
}
});