2022-02-09 02:28:05 +01:00
|
|
|
const GameHelper = require('./helpers/cg-gh.js')
|
|
|
|
|
2022-02-07 17:19:38 +01:00
|
|
|
(function() {
|
2022-02-09 02:28:05 +01:00
|
|
|
var isOpen = $.getSetIniDbBoolean('cgstatus', 'isOpen', false),
|
|
|
|
seed = {},
|
|
|
|
guesses = {
|
|
|
|
'1':[
|
|
|
|
{user:'Alpha',location:'0,0',distance:5,score:2,streak:0},
|
|
|
|
{user:'Beta',location:'5,0',distance:100,score:3,streak:0},
|
|
|
|
{user:'Charlie',location:'6,6',distance:1000,score:0,streak:0},
|
|
|
|
{user:'Delta',location:'42,6',distance:1,score:5,streak:1}
|
|
|
|
],
|
|
|
|
'2':[
|
|
|
|
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
function dbSetSeed(id) {
|
|
|
|
$.inidb.SetBoolean("chatguessr", "isOpen", "", open);
|
|
|
|
isOpen = open;
|
|
|
|
}
|
2022-02-07 17:19:38 +01:00
|
|
|
|
2022-02-09 02:28:05 +01:00
|
|
|
function dbSetOpen(open) {
|
2022-02-07 17:19:38 +01:00
|
|
|
$.inidb.SetBoolean("chatguessr", "isOpen", "", open);
|
|
|
|
isOpen = open;
|
|
|
|
sendData('status',open);
|
|
|
|
}
|
2022-02-09 02:28:05 +01:00
|
|
|
function dbClearGuesses() {
|
2022-02-07 17:19:38 +01:00
|
|
|
guesses = {};
|
|
|
|
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
|
|
|
|
sendData('guesses',guesses);
|
|
|
|
}
|
|
|
|
|
2022-02-09 02:28:05 +01:00
|
|
|
function dbAddGuess(user,position) {
|
2022-02-07 17:19:38 +01:00
|
|
|
if(guesses[user] && guesses[user].length > 0){
|
2022-02-08 15:59:11 +01:00
|
|
|
}else if(isCoordinates(position)){
|
2022-02-07 17:19:38 +01:00
|
|
|
guesses[user] = position;
|
|
|
|
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
|
2022-02-09 02:28:05 +01:00
|
|
|
sendData('guesses',JSON.stringify(guesses));
|
2022-02-07 17:19:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendData(tpe, data) {
|
|
|
|
$.panelsocketserver.sendJSONToAll(JSON.stringify({
|
|
|
|
'eventFamily': 'chatguessr',
|
|
|
|
'eventType': tpe,
|
|
|
|
'data': data
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-02-08 15:59:11 +01:00
|
|
|
function isCoordinates(coordinates) {
|
|
|
|
const regex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g;
|
|
|
|
return regex.test(coordinates);
|
|
|
|
};
|
|
|
|
|
2022-02-07 17:19:38 +01:00
|
|
|
$.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')) {
|
2022-02-09 02:28:05 +01:00
|
|
|
//send url
|
|
|
|
//$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help', ' Use "!cg [open | close | ...]" to open/close the feature.'));
|
|
|
|
}else if(command.equalsIgnoreCase('cga')){
|
|
|
|
if(action.equalsIgnoreCase('open')){
|
|
|
|
isOpen = true;
|
|
|
|
$.getSetIniDbBoolean('cgstatus', 'isOpen', true);
|
|
|
|
}else if(action.equalsIgnoreCase('close')){
|
|
|
|
isOpen = false;
|
|
|
|
$.getSetIniDbBoolean('cgstatus', 'isOpen', false)
|
|
|
|
}else if(action.equalsIgnoreCase('start')){
|
|
|
|
seed = GameHelper.fetchSeed(args[1]);
|
|
|
|
}else if(action.equalsIgnoreCase('end')){
|
|
|
|
isOpen = false;
|
|
|
|
$.getSetIniDbBoolean('cgstatus', 'isOpen', false)
|
|
|
|
}else if(action.equalsIgnoreCase('refresh')){
|
|
|
|
let newseed = GameHelper.fetchSeed(args[1]);
|
|
|
|
}else if(action.equalsIgnoreCase('gg')){
|
|
|
|
sendData('guesses',JSON.stringify(guesses));
|
2022-02-07 17:19:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.bind('initReady', function() {
|
2022-02-09 02:28:05 +01:00
|
|
|
$.registerChatCommand('./custom/custom/chatguessr.js', 'cg',7);
|
2022-02-07 17:19:38 +01:00
|
|
|
$.registerChatCommand('./custom/custom/chatguessr.js', 'g',7);
|
2022-02-09 02:28:05 +01:00
|
|
|
$.registerChatCommand('./custom/custom/chatguessr.js', 'cga');
|
|
|
|
$.registerChatSubcommand('cga', 'open', 2);
|
|
|
|
$.registerChatSubcommand('cga', 'close', 2);
|
|
|
|
$.registerChatSubcommand('cga', 'start', 2);
|
|
|
|
$.registerChatSubcommand('cga', 'end', 2);
|
|
|
|
$.registerChatSubcommand('cga', 'refresh', 2);
|
2022-02-07 17:19:38 +01:00
|
|
|
});
|
|
|
|
|
2022-02-09 02:28:05 +01:00
|
|
|
})();
|