OxfordAPI¶
OxfordAPI ¶
OxfordAPI(server_key=None, *, app_key=None, timeout=10, rate_limit='auto', max_retries=3, base_url=BASE_URL, session=None, global_key=None, server_id=None)
Bases: SyncSignatures, BaseClient
Client for the Oxford Response private server API (https://docs.oxfd.re).
For asyncio code (discord.py and the like) use :class:~oxrpy.AsyncOxfordAPI, which has
the same methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_key
|
Optional[str]
|
Your server's API key (Server Management > External > API Key). |
None
|
app_key
|
Optional[str]
|
Optional app key ( |
None
|
timeout
|
float
|
Seconds to wait for a response. Commands wait up to 8 seconds server side, so command requests always get at least 15. |
10
|
rate_limit
|
Union[str, float, None]
|
|
'auto'
|
max_retries
|
int
|
How many times to retry after a 429 (waiting |
3
|
base_url
|
str
|
Override the API base URL (for testing). |
BASE_URL
|
session
|
Optional[Session]
|
Use your own |
None
|
global_key
|
Optional[str]
|
Removed in 2.0; passing it warns and treats it as |
None
|
server_id
|
Optional[str]
|
No longer used; passing it warns. |
None
|
alert ¶
An alert to everyone, style "normal", "yellow" or "red".
ambulance_callout ¶
A patient callout for that paramedic, or the first one free (RoleplayKit).
ban ¶
Ban someone, in the server or not. duration is "30m", "12h", "7d",
"1d12h", a timedelta or seconds; leave it out for a permanent ban.
Reasons can be up to 200 characters.
clear_catalogue_cache ¶
Forget the stored Catalogue, so the next get_catalogue asks the API.
clear_placeables ¶
Pick up one person's cones, signs and other placed items, or everyone's.
create_incident ¶
Open a control-room incident at x, z (studs) for an emergency team, priority 1-3.
The new incident's ID is in the result's Message.
despawn_vehicle ¶
Put someone's vehicle away (the despawn command).
follow ¶
A :class:~oxrpy.LogFollower that yields only new log entries. See its docs.
save_to (a file path, or an object with load/save) remembers the position
across restarts. See :mod:oxrpy.state.
get_audit ¶
One page of the full audit log: { Entries, Next, Total }. Slower than the rest.
get_bans ¶
One page of bans: { Total, Offset, List: [...] }. See iter_bans.
get_catalogue ¶
Game data that only changes with an update: map, places, weapons, vehicles, offences, teams and ranks.
It's big and rarely changes, so the client keeps a copy for max_age seconds
(an hour by default) and returns that instead of asking again. Pass refresh=True
to fetch a fresh copy, or max_age=0 to never use the stored one.
get_command ¶
One command's result, for a command that was still Pending.
Keeps the API's old shape: lower-case Status (succeeded, failed,
pending, no_result). Results are kept for 7 days.
get_command_results ¶
Commands sent through the API and how they went. Last 200 kept.
get_commandlogs ¶
The newest audit log entries. Last 100 kept.
get_events ¶
About 100 kinds of game event, newest first. Last 1,000 kept.
get_joinlogs ¶
Joins and leaves, newest first. Last 500 kept.
get_modcalls ¶
Help requests, responders and resolutions, newest first. Last 300 kept.
get_radiocalls ¶
Radio calls, newest first. Last 500 kept.
get_server ¶
The always-returned fields: Online, LastHeartbeat, NextHeartbeat,
Cursor and Server (name, players, join code, packages…).
get_server_data ¶
get_server_data(*sections, since=None, limit=None, offset=None, audit_before=None, audit_category=None, audit_user=None, if_none_match=None)
Everything about the server in one request: GET /v1/server.
Name each section you want (case doesn't matter), e.g.
api.get_server_data("Players", "Vehicles", "Events", since=cursor).
The top-level fields (Online, LastHeartbeat, NextHeartbeat, Cursor,
Server) always come back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since
|
Optional[int]
|
A |
None
|
limit
|
Optional[int]
|
Most entries per log/ |
None
|
offset
|
Optional[int]
|
Bans to skip. |
None
|
audit_before
|
Optional[int]
|
Audit entries numbered below this (the last |
None
|
audit_category
|
Union[str, Iterable[str], None]
|
One or more of :data: |
None
|
audit_user
|
Union[str, int, None]
|
Only audit entries by this username or user ID. |
None
|
if_none_match
|
Optional[str]
|
A previous response's |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Optional[ServerData]
|
class: |
get_settings ¶
Every Server Management setting, keyed by name. Webhooks read "(set)".
get_status ¶
The API's own health (GET /status): status, uptime and response times.
Needs no key; don't ask more than every 30 seconds.
get_vehicles ¶
Every vehicle out, with emergency lights, siren, occupants… (None while offline).
give ¶
Give a RoleplayKit tool: megaphone, firestarter, lectern, flag or staffcuffs.
group_add ¶
Add someone to one of your groups (AdvancedServer).
group_remove ¶
Take someone out of one of your groups (AdvancedServer).
jail ¶
Jail someone as an arrest would, for 10 to 3,600 seconds (or the usual sentence).
kick ¶
Move someone out of your server, showing the reason. Staff can't be kicked.
list_callouts ¶
The callouts you can start, with their keys, in the result's Message.
lock_time ¶
Stop the clock (or start it again with locked=False).
lock_weather ¶
Stop the weather changing by itself (or let it again with locked=False).
new_join_code ¶
Replace the join code with a new random one. The new code is in Message.
on ¶
Register a handler for :meth:run_forever.
Keys can be an entry Type ("Kill", "Join", "ModCall", "SpeedCamera",
any event type), a log name ("KillLogs", "Events": every entry in it), "poll"
(called with the whole response after every request) or "error" (called with the
exception when a request fails and will be retried).
Use it as a decorator, @api.on("Kill"), or directly, api.on("Kill", handler).
plan_group_sync ¶
The group add/group remove commands needed to make group contain exactly
members (user IDs). Reads the groups; sends nothing.
plan_staff_sync ¶
The rank/unrank commands needed to make the staff match desired
(user ID -> rank name or Id, or None to remove). Reads the staff list; sends nothing.
See :func:oxrpy.sync.plan_staff_changes.
pm ¶
Send a private message, shown with your server's name and logo.
rank ¶
Put someone on the staff with a rank (its name or Id, e.g. "Admin"), or change it.
remove_vehicle ¶
Remove a vehicle by registration ("RJ75 FLK") or by its owner.
resolve_modcall ¶
Mark a mod call (help request) as handled. The CaseId is in ModCalls.
run_command ¶
Run one command (as you'd type it in game; the leading : is optional).
Waits up to 8 seconds for the result: { CommandId, Status, Code, Message }.
Status is Succeeded, Failed or Pending. A Failed command is still a
normal return unless check=True, which raises :class:CommandFailedError.
Raises:
| Type | Description |
|---|---|
ServerOfflineError
|
The server is offline (nothing was run). |
RateLimitError
|
Still rate limited after |
run_commands ¶
Run up to 10 commands in order, in one request. Returns one result per command.
run_forever ¶
Poll the server and call the handlers registered with :meth:on, until :meth:stop.
Entries from every log are passed to handlers oldest first. A handler that raises is
logged and skipped, and request errors are retried (see :class:LogFollower), so one
bad moment doesn't stop your bot. A wrong key still raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sections
|
Sequence[str]
|
Other sections to fetch every time (e.g. |
()
|
limit
|
Optional[int]
|
Most entries per log per request. |
None
|
cursor
|
Optional[int]
|
Resume from a saved cursor (then nothing is skipped). |
None
|
skip_existing
|
bool
|
Don't replay the entries that were already in the logs when you
started. Default |
True
|
save_to
|
Any
|
A file path ( |
None
|
run_many ¶
Run any number of commands, in order, as fast as the game allows.
Sends them in batches of up to 10 and waits when needed to stay under the game's
15 commands every 10 seconds. Returns one result per command, in the same order.
With check=True it stops at the first failed command and raises
:class:CommandFailedError.
set_invincible ¶
Make them unable to be hurt by weapons (or able to again), until they leave.
set_message ¶
Pin a message on everyone's screen until it's removed.
set_setting ¶
Change a Server Management setting. value is sent as JSON, so pass Python values:
api.set_setting("TeamLimits", {"Police": 8}). Lists and objects replace the whole value.
set_team ¶
Put someone on a team, ignoring team limits and locks.
spawn_vehicle ¶
Spawn one of your FleetKit custom vehicles in front of them.
speed_limit ¶
Limit every vehicle to 5-200 MPH (RoleplayKit). None or 0 lifts it.
start_callout ¶
Start a Fire or Highways callout by its key (RoleplayKit; list_callouts shows keys).
sync_group ¶
Make group (name or Id) contain exactly members (user IDs), sending only the
changes. Returns (command, result) pairs. remove_others=False only adds.
sync_staff ¶
Make the staff match desired (user ID -> rank, or None to remove), sending
only the changes. Returns (command, result) pairs; an empty list means nothing
needed changing. Use :meth:plan_staff_sync to see the commands without running them.
remove_others=True also unranks staff not in desired (never the owner).
teleport ¶
Teleport them next to another player (the tp command).
teleport_to_vehicle ¶
Teleport them next to another player's vehicle (the tocar command).
wait_for_command ¶
Poll :meth:get_command until it's no longer pending (gives up after timeout).
wanted ¶
Set a wanted level from 0 to 3. players can be a name, all, team:Civilian…