69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
(function() {
|
|
var isOpen = false,
|
|
guesses = {};
|
|
|
|
function DBsetOpen(open) {
|
|
$.inidb.SetBoolean("chatguessr", "isOpen", "", open);
|
|
isOpen = open;
|
|
sendData('status',open);
|
|
}
|
|
|
|
function DBClearG() {
|
|
guesses = {};
|
|
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
|
|
sendData('guesses',guesses);
|
|
}
|
|
|
|
function DBAddG(user,position) {
|
|
if(guesses[user] && guesses[user].length > 0){
|
|
}else{
|
|
guesses[user] = position;
|
|
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
|
|
sendData('guesses',guesses);
|
|
}
|
|
}
|
|
|
|
function sendData(tpe, data) {
|
|
$.panelsocketserver.sendJSONToAll(JSON.stringify({
|
|
'eventFamily': 'chatguessr',
|
|
'eventType': tpe,
|
|
'data': data
|
|
}));
|
|
}
|
|
|
|
$.bind('command', function(event) {
|
|
|
|
const sender = "" + event.getSender().toLowerCase(),
|
|
command = event.getCommand(),
|
|
args = event.getArgs(),
|
|
action = args[0];
|
|
|
|
if (command.equalsIgnoreCase('g')) {
|
|
if(isOpen) DBAddG(sender,args);
|
|
}else if (command.equalsIgnoreCase('cg')) {
|
|
if (!action) {
|
|
$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help', ' Use "!cg [open | close | ...]" to open/close the feature.'));
|
|
} else if (action.equalsIgnoreCase('open')) {
|
|
if(!isOpen) DBsetOpen(true);
|
|
} else if (action.equalsIgnoreCase('close')) {
|
|
if(isOpen) DBsetOpen(false);
|
|
} else if (action.equalsIgnoreCase('clear')) {
|
|
DBClearG();
|
|
} else if (action.equalsIgnoreCase('timer')) {
|
|
sendData(action, new Date(Date.now().getTime()+value*1000*60));
|
|
} else {
|
|
$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help'));
|
|
}
|
|
}
|
|
});
|
|
|
|
$.bind('initReady', function() {
|
|
$.registerChatCommand('./custom/custom/chatguessr.js', 'cg');
|
|
$.registerChatCommand('./custom/custom/chatguessr.js', 'g',7);
|
|
|
|
$.registerChatSubcommand('cg', 'open', 2);
|
|
$.registerChatSubcommand('cg', 'close', 2);
|
|
$.registerChatSubcommand('cg', 'clear', 2);
|
|
});
|
|
|
|
})(); |