Skip to content

Instantly share code, notes, and snippets.

@douglasg
Created May 26, 2022 14:18
Show Gist options
  • Save douglasg/aea1ba0de5a70a9b6086139a04ee1da3 to your computer and use it in GitHub Desktop.
Save douglasg/aea1ba0de5a70a9b6086139a04ee1da3 to your computer and use it in GitHub Desktop.
Imports Raid-Helper Group Assignments into the current active google sheet
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Raid-Helper')
.addItem('Import', 'showPrompt')
.addItem('Update', 'update')
.addToUi();
}
function showPrompt() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var result = ui.prompt(
'Import Raid-Helper Group Assignments',
'Raid-Helper ID (leave empty for last id):',
ui.ButtonSet.OK_CANCEL);
var button = result.getSelectedButton();
var id = result.getResponseText();
if (button == ui.Button.OK) {
ImportRaidHelper(id);
}
}
function update() {
ImportRaidHelper('')
}
function ImportRaidHelper(id) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange("B1");
if(id == '') id = cell.getValue();
if(id == '') {
SpreadsheetApp.getUi().alert("Raid-Helper Id missing!");
return;
}
cell.setValue(id);
var url ="https://raid-helper.dev/api/raidplan/" + id;
var jsondata = UrlFetchApp.fetch(url);
var parsedData = JSON.parse(jsondata.getContentText());
setHeaders(sheet, parsedData.partyPerRaid);
parseData(parsedData,sheet);
}
function parseData(data, sheet) {
data.raidDrop.forEach(function(item) {
var raidslot = sheet.getRange(item.slotId+2,item.partyId+1);
var name = getPlayerName(item);
raidslot.setValue(name);
var bgColor = getClassColor(item);
raidslot.setBackground(bgColor);
});
}
function getPlayerName(item) {
switch(item.spec_emote) {
case '637564379847458846':
case '637564323530539019':
case '637564297622454272':
case '637564172007112723':
case '637564323442720768':
return "(H) " + item.name;
default:
break;
}
switch(item.class) {
case 'Tank':
return "(T) " + item.name;
default:
return item.name;
}
}
function getClassColor(item) {
switch(item.spec_emote) {
// Pala
case '637564297647489034':
case '637564297953673216':
case '637564297622454272':
return "#f48cba";
// Shaman
case '637564379772223489':
case '637564379847458846':
case '637564379595931649':
return "#0070dd";
// Hunter
case '637564202021814277':
case '637564202130866186':
case '637564202084466708':
return "#aad372";
// Warlock
case '637564406682877964':
case '637564406984867861':
case '637564407001513984':
return "#8788ee";
// Druid
case '637564171696734209':
case '637564171994529798':
case '637564172007112723':
case '637564172061900820':
return "#ff7c0a";
// Mage
case '637564231545389056':
case '637564231239073802':
case '637564231469891594':
return "#3fc7eb";
// Warrior
case '637564445215948810':
case '637564445031399474':
case '637564444834136065':
return "#c69b6d";
// Priest
case '637564323530539019':
case '637564323291725825':
case '637564323442720768':
return "#ffffff";
// Rogue
case '637564352169508892':
case '637564352333086720':
case '637564351707873324':
return "#fff468";
default:
return "#cccccc";
}
}
function setHeaders(sheet,partyPerRaid,){
for(var i=0; i < partyPerRaid; i++){
var group = sheet.getRange(2,i+2);
group.setFontWeight("bold");
group.setBackground("#b7b7b7");
if(i<5) {
group.setValue("Gruppe " + (i+1));
} else {
group.setValue("Bench");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment