Compare commits
2 Commits
1a71c92a8e
...
67116539ab
Author | SHA1 | Date | |
---|---|---|---|
67116539ab | |||
f0db44f672 |
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@ -0,0 +1,5 @@
|
||||
.vscode
|
||||
target
|
||||
.env
|
||||
.gitignore
|
||||
renovate.json
|
37
.gitea/workflows/build.yml
Normal file
37
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,37 @@
|
||||
name: Build and push container image
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04-node
|
||||
steps:
|
||||
- name: Install and setup Docker
|
||||
run: |
|
||||
apt update
|
||||
apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
|
||||
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
||||
echo \
|
||||
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
|
||||
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
apt update
|
||||
apt install -y docker-ce docker-ce-cli containerd.io
|
||||
- name: Checkout branch
|
||||
uses: actions/checkout@v4.1.1
|
||||
- name: Login to Gitea
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.toast-server.net
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_TOKEN }}
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v5.1.0
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: git.toast-server.net/toast/kon:main
|
||||
cache-from: type=registry,ref=git.toast-server.net/toast/kon:main
|
||||
cache-to: type=inline
|
19
.gitea/workflows/deploy.yml
Normal file
19
.gitea/workflows/deploy.yml
Normal file
@ -0,0 +1,19 @@
|
||||
name: Deploy to host
|
||||
on:
|
||||
registry_package:
|
||||
types: [published]
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-22.04-node
|
||||
steps:
|
||||
- name: SSH into Docker Host
|
||||
uses: appleboy/ssh-action@55dabf81b49d4120609345970c91507e2d734799
|
||||
with:
|
||||
host: ${{ secrets.SSH_HOST }}
|
||||
username: ${{ secrets.SSH_USERNAME }}
|
||||
passphrase: ${{ secrets.SSH_PASSPHRASE }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
port: ${{ secrets.SSH_PORT }}
|
||||
script: |
|
||||
cd kon && docker compose pull && \
|
||||
docker compose up -d --remove-orphans && docker image prune -f
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
/target
|
||||
target
|
||||
.env
|
||||
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM rust:1.74-alpine3.18 AS compiler
|
||||
ENV RUSTFLAGS="-C target-feature=-crt-static"
|
||||
RUN apk add --no-cache openssl-dev musl-dev
|
||||
WORKDIR /usr/src/kon
|
||||
COPY . .
|
||||
RUN cargo fetch && cargo build -r
|
||||
|
||||
FROM alpine:3.19
|
||||
RUN apk add --no-cache openssl-dev libgcc
|
||||
WORKDIR /kon
|
||||
COPY --from=compiler /usr/src/kon/target/release/kon .
|
||||
CMD [ "./kon" ]
|
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
||||
version: '3.8'
|
||||
services:
|
||||
bot:
|
||||
container_name: Kon
|
||||
image: 'git.toast-server.net/toast/kon:main'
|
||||
build: .
|
||||
env_file:
|
||||
- .env
|
||||
restart: unless-stopped
|
@ -1,73 +1,48 @@
|
||||
use crate::Error;
|
||||
use crate::{Error, COLOR};
|
||||
|
||||
use reqwest::get;
|
||||
use std::collections::HashMap;
|
||||
use serde_json::Value;
|
||||
use tokio::join;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref PMS_BASE: String = std::env::var("WG_PMS").expect("Expected a \"WG_PMS\" in the envvar but none was found");
|
||||
}
|
||||
|
||||
/// Retrieve the server data from Wargaming
|
||||
#[poise::command(slash_command, subcommands("asia", "europe"))]
|
||||
pub async fn status(_ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check the server status for Asia server
|
||||
/// Retrieve the server statuses from Wargaming
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn asia(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||
let asia_pms = &PMS_BASE;
|
||||
let servers = pms_serverstatus(&asia_pms).await?;
|
||||
pub async fn status(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||
let pms_asia = &PMS_BASE;
|
||||
let pms_eu = PMS_BASE.replace("asia", "eu");
|
||||
|
||||
let mut fields = Vec::new();
|
||||
let (servers_asia, servers_eu) = join!(pms_serverstatus(&pms_asia), pms_serverstatus(&pms_eu));
|
||||
|
||||
for server in servers {
|
||||
let mut embed_fields = Vec::new();
|
||||
for server in servers_eu.unwrap() {
|
||||
let name = server["name"].as_str().unwrap().to_owned();
|
||||
let status = match server["availability"].as_str().unwrap() {
|
||||
"1" => "Online",
|
||||
"-1" => "Offline",
|
||||
_ => "Unknown"
|
||||
};
|
||||
fields.push((name, status, true));
|
||||
embed_fields.push((name, status, true));
|
||||
}
|
||||
|
||||
ctx.send(|m|
|
||||
m.embed(|e| {
|
||||
e.color(crate::COLOR)
|
||||
.title("World of Tanks Asia Status")
|
||||
.fields(fields)
|
||||
})
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check the server status for EU servers
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn europe(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||
let eu_pms = PMS_BASE.replace("asia", "eu");
|
||||
let servers = pms_serverstatus(&eu_pms).await?;
|
||||
|
||||
let mut fields = Vec::new();
|
||||
|
||||
for server in servers {
|
||||
for server in servers_asia.unwrap() {
|
||||
let name = server["name"].as_str().unwrap().to_owned();
|
||||
let status = match server["availability"].as_str().unwrap() {
|
||||
"1" => "Online",
|
||||
"-1" => "Offline",
|
||||
_ => "Unknown"
|
||||
};
|
||||
fields.push((name, status, true));
|
||||
embed_fields.push((name, status, true));
|
||||
}
|
||||
|
||||
ctx.send(|m|
|
||||
m.embed(|e| {
|
||||
e.color(crate::COLOR)
|
||||
.title("World of Tanks Europe Status")
|
||||
.fields(fields)
|
||||
})
|
||||
).await?;
|
||||
ctx.send(|m| m.embed(|e|
|
||||
e.color(COLOR)
|
||||
.title("World of Tanks Server Status")
|
||||
.fields(embed_fields)
|
||||
)).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user