Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ To run that discord bot in a test environment, your `op_discord.env` should look
LOG_LEVEL = "INFO"

DF_API_HOST = "http://localhost:1337"
DF_API_KEY = "DUMMY"

DF_MAP_RENDERER = "http://localhost:9100"

Expand Down
1 change: 1 addition & 0 deletions compose.df_discord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
environment:
LOG_LEVEL: ${LOG_LEVEL}
DF_API_HOST: ${DF_API_HOST}
DF_API_KEY: ${DF_API_KEY}
DF_MAP_RENDERER: http://df_map:9100
DISCORD_TOKEN: ${DISCORD_TOKEN}
DF_GUILD_ID: ${DF_GUILD_ID}
Expand Down
27 changes: 27 additions & 0 deletions discord_app/api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
from df_lib.map_struct import serialize_map, deserialize_map

DF_API_HOST = os.environ['DF_API_HOST']
DF_API_KEY = os.environ['DF_API_KEY']
DF_MAP_RENDERER = os.environ['DF_MAP_RENDERER']
API_SUCCESS_CODE = 200
API_UNPROCESSABLE_ENTITY_CODE = 422
API_INTERNAL_SERVER_ERROR = 500

DF_API_HEADERS = {'Authorization': f'Bearer {DF_API_KEY}'}


def _check_code(response: httpx.Response):
if response.status_code == API_INTERNAL_SERVER_ERROR:
Expand Down Expand Up @@ -72,6 +75,7 @@ async def get_map(
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/map/get',
headers=DF_API_HEADERS,
params=params,
timeout=10
)
Expand All @@ -84,6 +88,7 @@ async def get_tile(x: int, y: int) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/map/tile/get',
headers=DF_API_HEADERS,
params={
'x': x,
'y': y
Expand All @@ -98,6 +103,7 @@ async def new_user(username: str, discord_id: int) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(
url=f'{DF_API_HOST}/user/new',
headers=DF_API_HEADERS,
params={
'username': username,
'discord_id': discord_id
Expand All @@ -112,6 +118,7 @@ async def get_user_by_discord(discord_id: int) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/user/get_by_discord_id',
headers=DF_API_HEADERS,
params={'discord_id': discord_id}
)

Expand All @@ -123,6 +130,7 @@ async def update_user_metadata(user_id: UUID, new_metadata: dict) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/user/update_metadata',
headers=DF_API_HEADERS,
params={'user_id': user_id},
json=new_metadata
)
Expand All @@ -135,6 +143,7 @@ async def new_convoy(user_id: UUID, new_convoy_name: str) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(
url=f'{DF_API_HOST}/convoy/new',
headers=DF_API_HEADERS,
params={
'user_id': user_id,
'convoy_name': new_convoy_name
Expand All @@ -149,6 +158,7 @@ async def get_convoy(convoy_id: UUID) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/convoy/get',
headers=DF_API_HEADERS,
params={'convoy_id': convoy_id,}
)

Expand All @@ -160,6 +170,7 @@ async def move_cargo(convoy_id: UUID, cargo_id: UUID, dest_vehicle_id: UUID) ->
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/convoy/cargo/move',
headers=DF_API_HEADERS,
params={
'convoy_id': convoy_id,
'cargo_id': cargo_id,
Expand All @@ -175,6 +186,7 @@ async def find_route(convoy_id: UUID, dest_x: int, dest_y: int) -> list[dict]:
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(
url=f'{DF_API_HOST}/convoy/find_route',
headers=DF_API_HEADERS,
params={
'convoy_id': convoy_id,
'dest_x': dest_x,
Expand All @@ -191,6 +203,7 @@ async def send_convoy(convoy_id: UUID, journey_id: UUID) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/convoy/send',
headers=DF_API_HEADERS,
params={
'convoy_id': convoy_id,
'journey_id': journey_id
Expand All @@ -205,6 +218,7 @@ async def get_vendor(vendor_id: UUID) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/vendor/get',
headers=DF_API_HEADERS,
params={'vendor_id': vendor_id}
)

Expand All @@ -216,6 +230,7 @@ async def buy_vehicle(vendor_id: UUID, convoy_id: UUID, vehicle_id: UUID) -> dic
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/vehicle/buy',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -231,6 +246,7 @@ async def sell_vehicle(vendor_id: UUID, convoy_id: UUID, vehicle_id: UUID) -> di
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/vehicle/sell',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -246,6 +262,7 @@ async def buy_cargo(vendor_id: UUID, convoy_id: UUID, cargo_id: UUID, quantity:
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/cargo/buy',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -262,6 +279,7 @@ async def sell_cargo(vendor_id: UUID, convoy_id: UUID, cargo_id: UUID, quantity:
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/cargo/sell',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -278,6 +296,7 @@ async def buy_resource(vendor_id: UUID, convoy_id: UUID, resource_type: str, qua
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/resource/buy',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -294,6 +313,7 @@ async def sell_resource(vendor_id: UUID, convoy_id: UUID, resource_type: str, qu
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/resource/sell',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -310,6 +330,7 @@ async def add_part(vendor_id: UUID, convoy_id: UUID, vehicle_id: UUID, part_carg
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/vendor/vehicle/part/add',
headers=DF_API_HEADERS,
params={
'vendor_id': vendor_id,
'convoy_id': convoy_id,
Expand All @@ -326,6 +347,7 @@ async def get_vehicle(vehicle_id: UUID) -> dict:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/vehicle/get',
headers=DF_API_HEADERS,
params={'vehicle_id': vehicle_id}
)

Expand All @@ -337,6 +359,7 @@ async def check_part_compatibility(vehicle_id: UUID, part_cargo_id: UUID) -> dic
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/vehicle/part_compatibility',
headers=DF_API_HEADERS,
params={
'vehicle_id': vehicle_id,
'part_cargo_id': part_cargo_id
Expand All @@ -351,6 +374,7 @@ async def send_message(sender_id: UUID, recipient_id: UUID, message: str) -> dic
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(
url=f'{DF_API_HOST}/dialogue/send',
headers=DF_API_HEADERS,
params={ # Use JSON body for POST requests
'sender_id': sender_id,
'recipient_id': recipient_id,
Expand All @@ -366,6 +390,7 @@ async def get_dialogue_by_char_ids(char_a_id: UUID, char_b_id: UUID) -> list[dic
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/dialogue/get_by_char_ids',
headers=DF_API_HEADERS,
params={
'char_a_id': char_a_id,
'char_b_id': char_b_id,
Expand All @@ -380,6 +405,7 @@ async def get_unseen_dialogue_for_user(user_id: UUID) -> list[dict]:
async with httpx.AsyncClient(verify=False) as client:
response = await client.get(
url=f'{DF_API_HOST}/dialogue/get_user_unseen_messages',
headers=DF_API_HEADERS,
params={'user_id': user_id}
)

Expand All @@ -391,6 +417,7 @@ async def mark_dialogue_as_seen(user_id: UUID) -> list[dict]:
async with httpx.AsyncClient(verify=False) as client:
response = await client.patch(
url=f'{DF_API_HOST}/dialogue/mark_user_dialogues_as_seen',
headers=DF_API_HEADERS,
params={'user_id': user_id}
)

Expand Down
1 change: 1 addition & 0 deletions wiki/containerization.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ In order to run that, you need an `op_discord_prod.env` should look something li
LOG_LEVEL = "INFO"

DF_API_HOST = "http://70.90.116.204:8001" # Official DF API
DF_API_KEY = "op://Oori DevOps/Oori - Desolate Frontiers - Discord Bot/Bearer Token"

DISCORD_TOKEN = "op://Oori DevOps/Oori - Desolate Frontiers - Discord Bot/credential" # Official DF bot/app

Expand Down