Skip to content

Commit

Permalink
Make default scene URL configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mqp committed Jul 23, 2019
1 parent 79e958c commit 5c11606
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ STATSD_PREFIX=discordbot.

# True if verbose (e.g. per-message) logging should be enabled.
VERBOSE=false

# If set, Hubs rooms created by the bot with no scene specified will use this scene/GLTF/GLB/bundle URL as the scene.
DEFAULT_SCENE_URL=https://asset-bundles-prod.reticulum.io/rooms/atrium/Atrium.bundle.json
1 change: 1 addition & 0 deletions habitat/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ shard_count = "0"
verbose = "false"
locale = "en-US"
timezone = "America/Los_Angeles"
default_scene_url = "https://asset-bundles-prod.reticulum.io/rooms/atrium/Atrium.bundle.json"
1 change: 1 addition & 0 deletions habitat/hooks/run
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export LOCALE="{{ cfg.general.locale }}"
export TIMEZONE="{{ cfg.general.timezone }}"
export STATSD_HOST="{{ cfg.general.statsd_host }}"
export STATSD_PREFIX="{{ cfg.general.statsd_prefix }}"
export DEFAULT_SCENE_URL="{{ cfg.general.default_scene_url }}"

cd {{pkg.svc_path}}

Expand Down
18 changes: 5 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,26 +676,18 @@ async function start() {
return discordCh.send("A Hubs room is already bridged in the topic, so I am cowardly refusing to replace it.");
}

if (args.length === 2) { // !hubs create
const { url: hubUrl, hub_id: hubId } = await reticulumClient.createHubFromUrl(discordCh.name);
const updatedTopic = topicManager.addHub(discordCh.topic, hubUrl);
if (await trySetTopic(discordCh, updatedTopic) != null) {
return reticulumClient.bindHub(hubId, discordCh.guild.id, discordCh.id);
}
return;
}

const { sceneUrl, sceneId, sceneSlug } = topicManager.matchScene(args[2]) || {};
const name = args.length === 4 ? args[3] : (sceneSlug || discordCh.name);
const url = args.length > 2 ? args[2] : process.env.DEFAULT_SCENE_URL;
const { sceneUrl, sceneId, sceneSlug } = topicManager.matchScene(url) || {};
const name = args.length > 3 ? args[3] : discordCh.name;
const guildId = discordCh.guild.id;
if (sceneUrl) { // !hubs create [scene URL] [name]
if (sceneId) { // !hubs create [scene URL] [name]
const { url: hubUrl, hub_id: hubId } = await reticulumClient.createHubFromScene(name, sceneId);
const updatedTopic = topicManager.addHub(discordCh.topic, hubUrl);
if (await trySetTopic(discordCh, updatedTopic) != null) {
return reticulumClient.bindHub(hubId, guildId, discordCh.id);
}
} else { // !hubs create [environment URL] [name]
const { url: hubUrl, hub_id: hubId } = await reticulumClient.createHubFromUrl(name, args[2]);
const { url: hubUrl, hub_id: hubId } = await reticulumClient.createHubFromUrl(name, url);
const updatedTopic = topicManager.addHub(discordCh.topic, hubUrl);
if (await trySetTopic(discordCh, updatedTopic) != null) {
return reticulumClient.bindHub(hubId, guildId, discordCh.id);
Expand Down
7 changes: 2 additions & 5 deletions src/reticulum.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ dotenv.config({ path: ".env.defaults" });
// All of the session IDs ever assigned to the bot.
const BOT_SESSION_IDS = new Set();

// The URL for the scene used if users create a new room but don't specify a scene.
const DEFAULT_BUNDLE_URL = "https://asset-bundles-prod.reticulum.io/rooms/atrium/Atrium.bundle.json";

// Converts a Phoenix message push object into a promise that resolves when the push
// is acknowledged by Reticulum or rejects when it times out or Reticulum produces an error.
function promisifyPush(push) {
Expand Down Expand Up @@ -216,9 +213,9 @@ class ReticulumClient {
return this._request("POST", "hubs", payload);
}

// Creates a new hub with the given name and GLTF/GLB/bundle URL, or the default if not specified.
// Creates a new hub with the given name and GLTF/GLB/bundle URL.
async createHubFromUrl(name, url) {
const payload = { hub: { name, default_environment_gltf_bundle_url: url || DEFAULT_BUNDLE_URL } };
const payload = { hub: { name, default_environment_gltf_bundle_url: url } };
return this._request("POST", "hubs", payload);
}

Expand Down

0 comments on commit 5c11606

Please sign in to comment.