1.2.0 • Published 9 months ago

rbxcloud v1.2.0

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
9 months ago

About

RbxCloud is an open cloud API for Roblox experiences.

  • Object oriented
  • Aims to be as close to the Roblox API as possible for the following services:
    • DataStoreService
    • MessagingService
  • Promise-based
  • Support for non-JSON responses and such
  • Support for nearly all open-cloud features
    • Place publishing will come in a later update.

Installation

npm install rbxcloud

Example Usage

You can find working examples in example/general-usage.js or just read below:

Publish a message using MessagingService:

const { OpenCloud, MessagingService } = require('rbxcloud');
OpenCloud.Configure({
    MessagingService: 'API-KEY', // This is an API key for MessagingService
    UniverseId: 0, // You can get the UniverseId from the Asset explorer
});

MessagingService.PublishAsync('MyTopic', 'Hello World!').then(() => {
    console.log('Publish was a success!');
}).catch(err => {
    console.log(err);
});

Read, set, and update DataStore entry:

const { OpenCloud, DataStoreService } = require('rbxcloud');
const { DataStoreSetOptions } = DataStoreService.Objects;

OpenCloud.Configure({
    DataStoreService: 'API-KEY', // This is an API key for MessagingService
    UniverseId: 0, // You can get the UniverseId from the Asset explorer
});

const GoldStore = DataStoreService.GetDataStore('Gold');

GoldStore.GetAsync(125196014).then(([data, keyInfo]) => {
    console.log(keyInfo.DataType === JSON); // true / false
    console.log(keyInfo.CreatedTime); // UNIX Timestamp
    console.log(keyInfo.UpdatedTime); // UNIX Timestamp
    console.log(keyInfo.Version); // DataStore key version
    console.log(`The player has ${data.amount} gold!`)
});

// SetAsync the player's gold
GoldStore.SetAsync(125196014, {
    currency: 'Gold',
    amount: 100,
}).then((result) => {
    console.log('Data saved: ', result);
}).catch((err) => {
    console.log('Error', err);
});

// Delete the player's gold
GoldStore.RemoveAsync(125196014).then()

// Increment a player's gold (incompatible with the current data setup though)
GoldStore.IncrementAsync(125196014, 5).then(([newAmount, keyInfo]) => {
    console.log(`The player now has ${newAmount} gold!`);
}).catch((err) => {
    console.log(err);
});

// Now use UpdateAsync; has nearly the exact same functionality as the native implementation. Do not yield this.
// Additionally, if you use this with the data being an array, you will lose your data unless you wrap the array inside another array.
GoldStore.UpdateAsync(125196014, function(data, keyInfo) {
    if (data.amount < 100) {
        data += 100;
    }
    //return data; <-- This is valid
    
    // Alternatively, you can return numerous values as specified by the Roblox API for UpdateAsync:
    const metadata = {
        IsOwnedByAPlayer: true,
        IsThisPlayerVeryCool: true
    };
    return [ data, [], metadata ]
});

// UpdateAsync with an array:
GoldStore.UpdateAsync(125196014, function(data, keyInfo) {
    data.push('Hello World!');
    return [ [ data ], [], metadata ]
})

Links

Contributing

Create an issue for any suggestions or bug reports that you find. Please ensure that you've read the documentation, and if you're creating an issue, verify that it isn't a duplicate.

1.2.0

9 months ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago