Compare commits

..

No commits in common. "67116539abdb34201cc007db06ac103ff89ad1ba" and "1a71c92a8e132f7b7a49aec2d0430fbd3101dd82" have entirely different histories.

7 changed files with 43 additions and 100 deletions

View File

@ -1,5 +0,0 @@
.vscode
target
.env
.gitignore
renovate.json

View File

@ -1,37 +0,0 @@
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

View File

@ -1,19 +0,0 @@
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
View File

@ -1,2 +1,2 @@
target /target
.env .env

View File

@ -1,12 +0,0 @@
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" ]

View File

@ -1,9 +0,0 @@
version: '3.8'
services:
bot:
container_name: Kon
image: 'git.toast-server.net/toast/kon:main'
build: .
env_file:
- .env
restart: unless-stopped

View File

@ -1,48 +1,73 @@
use crate::{Error, COLOR}; use crate::Error;
use reqwest::get; use reqwest::get;
use std::collections::HashMap; use std::collections::HashMap;
use serde_json::Value; use serde_json::Value;
use tokio::join;
lazy_static::lazy_static! { 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"); 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 statuses from Wargaming /// 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
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub async fn status(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> { pub async fn asia(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
let pms_asia = &PMS_BASE; let asia_pms = &PMS_BASE;
let pms_eu = PMS_BASE.replace("asia", "eu"); let servers = pms_serverstatus(&asia_pms).await?;
let (servers_asia, servers_eu) = join!(pms_serverstatus(&pms_asia), pms_serverstatus(&pms_eu)); let mut fields = Vec::new();
let mut embed_fields = Vec::new(); for server in servers {
for server in servers_eu.unwrap() {
let name = server["name"].as_str().unwrap().to_owned(); let name = server["name"].as_str().unwrap().to_owned();
let status = match server["availability"].as_str().unwrap() { let status = match server["availability"].as_str().unwrap() {
"1" => "Online", "1" => "Online",
"-1" => "Offline", "-1" => "Offline",
_ => "Unknown" _ => "Unknown"
}; };
embed_fields.push((name, status, true)); fields.push((name, status, true));
} }
for server in servers_asia.unwrap() { 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 {
let name = server["name"].as_str().unwrap().to_owned(); let name = server["name"].as_str().unwrap().to_owned();
let status = match server["availability"].as_str().unwrap() { let status = match server["availability"].as_str().unwrap() {
"1" => "Online", "1" => "Online",
"-1" => "Offline", "-1" => "Offline",
_ => "Unknown" _ => "Unknown"
}; };
embed_fields.push((name, status, true)); fields.push((name, status, true));
} }
ctx.send(|m| m.embed(|e| ctx.send(|m|
e.color(COLOR) m.embed(|e| {
.title("World of Tanks Server Status") e.color(crate::COLOR)
.fields(embed_fields) .title("World of Tanks Europe Status")
)).await?; .fields(fields)
})
).await?;
Ok(()) Ok(())
} }