Skip to content

Commit

Permalink
feat: Discord Integration (#9)
Browse files Browse the repository at this point in the history
* initial discord integration

* cleanup discord integration + config options

* fix interaction response

* fix: edge case with refresh button
  • Loading branch information
b1naryth1ef authored Jan 26, 2022
1 parent a38b9bd commit 7cb6afc
Show file tree
Hide file tree
Showing 9 changed files with 773 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ yarn-debug.log*
yarn-error.log*
/scratch.txt
/config.json
/sneaker-server
/sneaker-server
/state.json
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ A live example of Sneaker can be viewed [here](https://hoggit.brrt.me/).
2. Create a configuration file based off the [example](/example.config.json), replacing the required information (and optionally adding multiple servers to the array)
3. Run the executable with the configuration path: `sneaker-server.exe --config config.json`

### Discord Integration

Sneaker features a built-in Discord integration which provides basic server information and GCI duty tracking via Discord slash-commands.

1. Create a new [Discord Application](https://discord.com/developers/applications) and configure the `Interactions Endpoint URL` to point at your Sneaker installations `/api/discord/interactions` endpoint.
2. Add a Bot to the application (this is used to DM users about GCI duty timeouts)
3. Add the bot to your server by opening a link generated [here](https://discord.com/developers/applications/935306685692674078/oauth2/url-generator). You only need the `applications.commands` scope.
4. Add the following to your `config.json`:
```json
"discord": {
"application_id": "<discord application id, bunch of numbers>",
"application_key": "<discord public key, bunch of letters/numbers>",
"token": "<discord bot token>",
"state_path": "<optional path to a location to save GCI duty state between restarts>",
"timeout": "<number of minutes before gci is automatically logged off duty, default = 60>",
"reminder": "<number of minutes before timeout to warn gci via discord, default = 5>"
}
```

## Documentation

- [API](/docs/API.md) provides information on the internal Sneaker API.

## Web UI

The Sneaker web UI presents an emulated radar scope over top a [Open Street Map](https://openstreetmap.org) rendered via [maptalks](https://maptalks.org). The web UI is updated at a configurable simulated refresh rate (by default 5 seconds).
Expand Down
127 changes: 127 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# API

## Available Endpoints

### Server List

```
$ curl https://sneaker.example.com/api/servers
[
{
"name": "saw",
"ground_unit_modes": [
"enemy",
"friendly"
],
"players": [
{
"name": "[TFP] Ghost",
"type": "F-16C_50"
},
{
"name": "Legacy 1-1 | Zanax116",
"type": "F-16C_50"
},
{
"name": "Barack 1-1",
"type": "F-16C_50"
},
{
"name": "Hesgad",
"type": "Mi-24P"
}
],
"gcis": [
{
"id": "80351110224678912",
"notes": "asfd",
"expires_at": "2022-01-26T18:11:50.948081071Z"
}
]
}
]
```

### Server Information

```
$ curl https://sneaker.example.com/api/servers/saw
{
"name": "saw",
"ground_unit_modes": [
"enemy",
"friendly"
],
"players": [
{
"name": "[TFP] Ghost",
"type": "F-16C_50"
},
{
"name": "Legacy 1-1 | Zanax116",
"type": "F-16C_50"
},
{
"name": "Barack 1-1",
"type": "F-16C_50"
},
{
"name": "Hesgad",
"type": "Mi-24P"
}
],
"gcis": [
{
"id": "80351110224678912",
"notes": "asfd",
"expires_at": "2022-01-26T18:11:50.948081071Z"
}
]
}
```

### Server Events

This is a long-poll SSE HTTP connection.

```
$ curl https://sneaker.example.com/api/servers/saw/events
data: {
"d": {
"session_id": "2022-01-26T17:22:03.013Z",
"offset": 17975,
"objects": null
},
"e": "SESSION_STATE"
}\n\n
data: {
"d": {
"updated": [],
"deleted": [],
"created": [
{
"id": 62210,
"types": [
"Ground",
"Vehicle"
],
"properties": {
"Coalition": "Enemies",
"Color": "Blue",
"Country": "us",
"Group": "Ground-3",
"Name": "Patriot AMG",
"Pilot": "Ground-2-3-1"
},
"latitude": 34.5961321,
"longitude": 32.9832006,
"altitude": 13.04,
"heading": 90,
"updated_at": 17844,
"created_at": 17844
}
]
},
"e": "SESSION_RADAR_SNAPSHOT"
}\n\n
```
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ go 1.17
require (
github.com/alioygur/gores v1.2.2
github.com/b1naryth1ef/jambon v0.0.4-0.20220109012622-92223168294c
github.com/bwmarrin/discordgo v0.23.3-0.20211228023845-29269347e820
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/cors v1.2.0
github.com/urfave/cli/v2 v2.3.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/spkg/bom v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
14 changes: 12 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/alioygur/gores v1.2.2 h1:y5mzo3R5cNWz1LBTIwAEU6DmB8grIC7iJwfc91kmBVU=
github.com/alioygur/gores v1.2.2/go.mod h1:z9GuicgNf03HUIQ5aPbiQGshig430sMeaFFfqfRacl8=
github.com/b1naryth1ef/jambon v0.0.4-0.20220106204832-12ebbf739bfb h1:Gxufp0hqv/TQelY+zYlaoBmHPXraU3AoZmFeCD96d6k=
github.com/b1naryth1ef/jambon v0.0.4-0.20220106204832-12ebbf739bfb/go.mod h1:jVzH5viOXvJXHc1DgMKauvOfR96UY7Zu49jIdUM6GX8=
github.com/b1naryth1ef/jambon v0.0.4-0.20220109012622-92223168294c h1:mWNvev5C4sPVOWGrjoAQ8FHi+fJ0SmU6qeNak/UYHYI=
github.com/b1naryth1ef/jambon v0.0.4-0.20220109012622-92223168294c/go.mod h1:jVzH5viOXvJXHc1DgMKauvOfR96UY7Zu49jIdUM6GX8=
github.com/bwmarrin/discordgo v0.23.3-0.20211228023845-29269347e820 h1:MIW5DnBVJAgAy4LYBqWwIMBB0ezklvh8b7DsYvHZHb0=
github.com/bwmarrin/discordgo v0.23.3-0.20211228023845-29269347e820/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand All @@ -13,6 +13,8 @@ github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/cors v1.2.0 h1:tV1g1XENQ8ku4Bq3K9ub2AtgG+p16SmzeMSGTwrOKdE=
github.com/go-chi/cors v1.2.0/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
Expand All @@ -26,6 +28,14 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
16 changes: 13 additions & 3 deletions server/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package server

type Config struct {
Bind string `json:"bind"`
Servers []TacViewServerConfig `json:"servers"`
AssetsPath *string `json:"assets_path"`
Bind string `json:"bind"`
Servers []TacViewServerConfig `json:"servers"`
AssetsPath *string `json:"assets_path"`
Discord *DiscordIntegrationConfig `json:"discord"`
}

type DiscordIntegrationConfig struct {
Token string `json:"token"`
ApplicationKey string `json:"application_key"`
ApplicationID string `json:"application_id"`
StatePath *string `json:"state_path"`
Timeout *int `json:"timeout"`
Reminder *int `json:"reminder"`
}

type TacViewServerConfig struct {
Expand Down
Loading

0 comments on commit 7cb6afc

Please sign in to comment.