This commit is contained in:
choelzl 2022-02-09 02:28:05 +01:00
parent 2a5eadc8cf
commit 8f6690be36
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
3 changed files with 179 additions and 25 deletions

View File

@ -1,25 +1,42 @@
const GameHelper = require('./helpers/cg-gh.js')
(function() { (function() {
var isOpen = false, var isOpen = $.getSetIniDbBoolean('cgstatus', 'isOpen', false),
guesses = {}; 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;
}
function DBsetOpen(open) { function dbSetOpen(open) {
$.inidb.SetBoolean("chatguessr", "isOpen", "", open); $.inidb.SetBoolean("chatguessr", "isOpen", "", open);
isOpen = open; isOpen = open;
sendData('status',open); sendData('status',open);
} }
function dbClearGuesses() {
function DBClearG() {
guesses = {}; guesses = {};
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses)); $.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
sendData('guesses',guesses); sendData('guesses',guesses);
} }
function DBAddG(user,position) { function dbAddGuess(user,position) {
if(guesses[user] && guesses[user].length > 0){ if(guesses[user] && guesses[user].length > 0){
}else if(isCoordinates(position)){ }else if(isCoordinates(position)){
guesses[user] = position; guesses[user] = position;
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses)); $.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
sendData('guesses',guesses); sendData('guesses',JSON.stringify(guesses));
} }
} }
@ -46,29 +63,37 @@
if (command.equalsIgnoreCase('g')) { if (command.equalsIgnoreCase('g')) {
if(isOpen) DBAddG(sender,args); if(isOpen) DBAddG(sender,args);
}else if (command.equalsIgnoreCase('cg')) { }else if (command.equalsIgnoreCase('cg')) {
if (!action) { //send url
$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help', ' Use "!cg [open | close | ...]" to open/close the feature.')); //$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help', ' Use "!cg [open | close | ...]" to open/close the feature.'));
} else if (action.equalsIgnoreCase('open')) { }else if(command.equalsIgnoreCase('cga')){
if(!isOpen) DBsetOpen(true); if(action.equalsIgnoreCase('open')){
} else if (action.equalsIgnoreCase('close')) { isOpen = true;
if(isOpen) DBsetOpen(false); $.getSetIniDbBoolean('cgstatus', 'isOpen', true);
} else if (action.equalsIgnoreCase('clear')) { }else if(action.equalsIgnoreCase('close')){
DBClearG(); isOpen = false;
} else if (action.equalsIgnoreCase('timer')) { $.getSetIniDbBoolean('cgstatus', 'isOpen', false)
sendData(action, new Date(Date.now().getTime()+value*1000*60)); }else if(action.equalsIgnoreCase('start')){
} else { seed = GameHelper.fetchSeed(args[1]);
$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help')); }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));
} }
} }
}); });
$.bind('initReady', function() { $.bind('initReady', function() {
$.registerChatCommand('./custom/custom/chatguessr.js', 'cg'); $.registerChatCommand('./custom/custom/chatguessr.js', 'cg',7);
$.registerChatCommand('./custom/custom/chatguessr.js', 'g',7); $.registerChatCommand('./custom/custom/chatguessr.js', 'g',7);
$.registerChatCommand('./custom/custom/chatguessr.js', 'cga');
$.registerChatSubcommand('cg', 'open', 2); $.registerChatSubcommand('cga', 'open', 2);
$.registerChatSubcommand('cg', 'close', 2); $.registerChatSubcommand('cga', 'close', 2);
$.registerChatSubcommand('cg', 'clear', 2); $.registerChatSubcommand('cga', 'start', 2);
$.registerChatSubcommand('cga', 'end', 2);
$.registerChatSubcommand('cga', 'refresh', 2);
}); });
})(); })();

129
twitch/helpers/cg-gh.js Normal file

File diff suppressed because one or more lines are too long

BIN
web/chatguessr/SRC_ORIG.js Normal file

Binary file not shown.