Skip to content

oxrpy.sync

Keep staff ranks and groups in step with somewhere else (Discord roles, a database…).

Oxford's advice is to compare what the server has with what you want and send only the differences. These functions work out those differences as commands. The clients' plan_staff_sync/sync_staff and plan_group_sync/sync_group fetch the current lists for you and run the commands within the game's limits.

Users are identified by user ID only: a username can match nobody, or someone else after a name change.

CommandWindow

CommandWindow(limit=GAME_COMMANDS_PER_WINDOW, window=GAME_WINDOW_SECONDS)

Tracks commands sent in the last 10 seconds, to stay under the game's 15.

wait_time

wait_time(count, now=None)

Seconds to wait before count more commands fit.

plan_staff_changes

plan_staff_changes(staff, desired, *, remove_others=False)

The rank/unrank commands that turn the current staff list into desired.

Parameters:

Name Type Description Default
staff Mapping[str, Any]

The Staff section ({ OwnerId, Staff, Ranks }).

required
desired Mapping[UserKey, Optional[str]]

User ID -> rank name or Id (None to take them off the staff).

required
remove_others bool

Also unrank staff who aren't in desired. Off by default, so staff you added by hand are left alone.

False

The owner is never touched. Ranks are matched by name or Id, ignoring case.

plan_group_changes

plan_group_changes(groups, group, members, *, remove_others=True)

The group add/group remove commands that make group contain members.

Parameters:

Name Type Description Default
groups Iterable[Mapping[str, Any]]

The Groups section.

required
group str

The group's name or Id (ignoring case).

required
members Iterable[UserKey]

User IDs who should be in it.

required
remove_others bool

Take out anyone not in members (default). Set False to only add.

True