Skip to content

Commit

Permalink
log on entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkLightTuna committed Jan 21, 2024
1 parent 2f49d97 commit 8f06917
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ Hooks.once("ready", async () => {
Logger.log('Ready')
})

function open_socket_with_oronder() {
if (oronder_socket !== undefined) return
export function open_socket_with_oronder(update = false) {
if (oronder_socket !== undefined) {
if (update)
oronder_socket.disconnect();
else
return
}

const guild_id = game.settings.get(MODULE_ID, GUILD_ID)
const authorization = game.settings.get(MODULE_ID, AUTH)

if (!guild_id || !authorization) return

oronder_socket = io(ORONDER_WS_URL, {
transports: ["websocket"],
auth: {'Guild-Id': guild_id, 'Authorization': authorization}
})
oronder_socket.on('connect', () => Logger.info('Oronder Websocket connection established.'));

oronder_socket.on('xp', data => {
for (const [id, xp] of Object.entries(data)) {
Expand All @@ -39,7 +48,6 @@ function open_socket_with_oronder() {
}
}
})
Logger.log('Oronder Websocket connection established.')
}

Hooks.on("updateActor", async (actor, data, options, userId) => {
Expand Down
16 changes: 13 additions & 3 deletions src/settings-form-application.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Logger} from "./util.mjs";
import {AUTH, GUILD_ID, ID_MAP, MODULE_ID, ORONDER_BASE_URL, VALID_CONFIG} from "./constants.mjs";
import {full_sync} from "./sync.mjs";
import {open_socket_with_oronder} from "./module.mjs";

export class OronderSettingsFormApplication extends FormApplication {

Expand Down Expand Up @@ -95,7 +96,7 @@ export class OronderSettingsFormApplication extends FormApplication {
const invalid_player_names = invalid_discord_ids.map(invalid_discord_id => {
return this.object.players.find(p => p.discord_id === invalid_discord_id).foundry_name
})
if (invalid_player_names.length===1) {
if (invalid_player_names.length === 1) {
Logger.error(
`${invalid_player_names[0]} ${game.i18n.localize("oronder.Could-Not-Be-Found")}`
)
Expand All @@ -105,12 +106,21 @@ export class OronderSettingsFormApplication extends FormApplication {
})
.catch(Logger.error)

let updated = false

if (game.settings.get(MODULE_ID, GUILD_ID) !== this.object.guild_id) {
game.settings.set(MODULE_ID, GUILD_ID, this.object.guild_id)
updated = true
}
if (game.settings.get(MODULE_ID, AUTH) !== this.object.auth) {
game.settings.set(MODULE_ID, AUTH, this.object.auth)
updated = true
}
game.settings.set(MODULE_ID, VALID_CONFIG, valid_config)
game.settings.set(MODULE_ID, GUILD_ID, this.object.guild_id)
game.settings.set(MODULE_ID, AUTH, this.object.auth)
game.settings.set(MODULE_ID, ID_MAP, id_map)

this.render()
open_socket_with_oronder(updated)
}

async _full_sync() {
Expand Down
2 changes: 1 addition & 1 deletion src/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export const registerSettings = async () => {
default: false
})

Logger.log('Registered Settings')
Logger.info('Registered Settings')
}

0 comments on commit 8f06917

Please sign in to comment.