Dockerified
This commit is contained in:
parent
b46f0bac46
commit
e668f4f0dd
13 changed files with 114 additions and 63 deletions
4
.dockerignore
Normal file
4
.dockerignore
Normal file
|
@ -0,0 +1,4 @@
|
|||
.idea/
|
||||
.github/
|
||||
**/.env
|
||||
target/
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
|||
FROM rust:1.65.0
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
|
||||
RUN cargo install --path .
|
||||
|
||||
#ENV DISCORD_TOKEN=token
|
||||
#ENV MONGO_HOST=host
|
||||
#ENV MONGO_PORT=port
|
||||
#ENV API_HOST=host
|
||||
#ENV API_PORT=port
|
||||
|
||||
ENTRYPOINT ["drunk-venti-rust"]
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serenity::builder::CreateEmbed;
|
||||
|
@ -28,21 +28,27 @@ pub struct Artifact {
|
|||
impl Artifact{
|
||||
#[allow(dead_code)]
|
||||
pub async fn get(artifact: &str) -> Artifact {
|
||||
let url = format!("http://localhost:3000/api/artifacts/{}", artifact);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/artifacts/{}", host, port, artifact);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Artifact>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/artifacts");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/artifacts", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn search(artifact: &str) -> Vec<Artifact> {
|
||||
let url = format!("http://localhost:3000/api/artifacts/search/{}", artifact);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/artifacts/search/{}", host, port, artifact);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Artifact>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -86,6 +92,6 @@ impl Artifact{
|
|||
|
||||
#[test]
|
||||
fn test_artifact() {
|
||||
let data = fs::read_to_string("test/artifact.json").expect("No Artifact test file");
|
||||
let data = std::fs::read_to_string("test/artifact.json").expect("No Artifact test file");
|
||||
serde_json::from_str::<Artifact>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -40,14 +40,18 @@ pub struct Builds {
|
|||
impl Builds {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn get(build: &str) -> Builds {
|
||||
let url = format!("http://localhost:3000/api/builds/{}", build);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/builds/{}", host, port, build);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Builds>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/builds");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/builds", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -55,6 +59,6 @@ impl Builds {
|
|||
|
||||
#[test]
|
||||
fn test_build() {
|
||||
let data = fs::read_to_string("test/build.json").expect("No build test file");
|
||||
let data = std::fs::read_to_string("test/build.json").expect("No build test file");
|
||||
serde_json::from_str::<Builds>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use crate::data::builds::{Role};
|
||||
|
@ -47,23 +47,28 @@ impl Clone for Character {
|
|||
impl Character {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn get(character: &str) -> Character {
|
||||
let url = format!("http://localhost:3000/api/characters/{}", character);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/characters/{}", host, port, character);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
let a = reqwest::get(url.clone()).await.expect("Can't access Url");
|
||||
println!("{}",&a.text().await.expect(""));
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Character>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/characters");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/characters", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn search(character: &str) -> Vec<Character> {
|
||||
let url = format!("http://localhost:3000/api/characters/search/{}", character);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/characters/search/{}", host, port, character);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Character>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -71,6 +76,6 @@ impl Character {
|
|||
|
||||
#[test]
|
||||
fn test_character() {
|
||||
let data = fs::read_to_string("test/character.json").expect("No character test file");
|
||||
let data = std::fs::read_to_string("test/character.json").expect("No character test file");
|
||||
serde_json::from_str::<Character>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -42,14 +42,18 @@ pub struct Domain {
|
|||
impl Domain {
|
||||
#[allow(dead_code)]
|
||||
pub async fn get(domain: &str) -> Domain {
|
||||
let url = format!("http://localhost:3000/api/domains/{}", domain);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/domains/{}", host, port, domain);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Domain>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/domains");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/domains", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -63,6 +67,6 @@ impl Domain {
|
|||
|
||||
#[test]
|
||||
fn test_items() {
|
||||
let data = fs::read_to_string("test/domain.json").expect("No Domain test file");
|
||||
let data = std::fs::read_to_string("test/domain.json").expect("No Domain test file");
|
||||
serde_json::from_str::<Domain>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -8,20 +8,24 @@ pub struct Element {
|
|||
pub id: Box<str>,
|
||||
pub name: Box<str>,
|
||||
pub simple_name: Box<str>,
|
||||
pub color: u64
|
||||
pub color: u64,
|
||||
}
|
||||
|
||||
impl Element{
|
||||
impl Element {
|
||||
#[allow(dead_code)]
|
||||
async fn get(element: &str) -> Element {
|
||||
let url = format!("http://localhost:3000/api/elements/{}", element);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/elements/{}", host, port, element);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Element>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/elements");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/elements", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -29,6 +33,6 @@ impl Element{
|
|||
|
||||
#[test]
|
||||
fn test_element() {
|
||||
let data = fs::read_to_string("test/element.json").expect("No Element test file");
|
||||
let data = std::fs::read_to_string("test/element.json").expect("No Element test file");
|
||||
serde_json::from_str::<Element>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -27,21 +27,27 @@ impl Clone for Event {
|
|||
impl Event {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn get_current() -> Vec<Event> {
|
||||
let url = format!("http://localhost:3000/api/events/current");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/events/current", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Event>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn get_upcoming() -> Vec<Event> {
|
||||
let url = format!("http://localhost:3000/api/events/upcoming");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/events/upcoming", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Event>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Event> {
|
||||
let url = format!("http://localhost:3000/api/events");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/events", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Event>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -49,6 +55,6 @@ impl Event {
|
|||
|
||||
#[test]
|
||||
fn test_events() {
|
||||
let data = fs::read_to_string("test/events.json").expect("No events test file");
|
||||
let data = std::fs::read_to_string("test/events.json").expect("No events test file");
|
||||
serde_json::from_str::<Vec<Event>>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -15,20 +15,26 @@ pub struct Item {
|
|||
impl Item{
|
||||
#[allow(dead_code)]
|
||||
async fn get(item: &str) -> Item {
|
||||
let url = format!("http://localhost:3000/api/items/{}", item);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/items/{}", host, port, item);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Item>().await.expect("Wrong json format");
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/items");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/items", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn search(item: &str) -> Vec<Item> {
|
||||
let url = format!("http://localhost:3000/api/items/search/{}", item);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/items/search/{}", host, port, item);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Item>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -36,6 +42,6 @@ impl Item{
|
|||
|
||||
#[test]
|
||||
fn test_item() {
|
||||
let data = fs::read_to_string("test/item.json").expect("No item test file");
|
||||
let data = std::fs::read_to_string("test/item.json").expect("No item test file");
|
||||
serde_json::from_str::<Item>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serenity::builder::CreateEmbed;
|
||||
|
@ -53,21 +53,27 @@ pub struct Weapon {
|
|||
impl Weapon {
|
||||
#[allow(dead_code)]
|
||||
pub async fn get(weapon: &str) -> Weapon {
|
||||
let url = format!("http://localhost:3000/api/weapons/{}", weapon);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/weapons/{}", host, port, weapon);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Weapon>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/weapons");
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/weapons", host, port);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Box<str>>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn search(weapon: &str) -> Vec<Weapon> {
|
||||
let url = format!("http://localhost:3000/api/weapons/search/{}", weapon);
|
||||
let host = env::var("API_HOST").unwrap();
|
||||
let port = env::var("API_PORT").unwrap();
|
||||
let url = format!("http://{}:{}/api/weapons/search/{}", host, port, weapon);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Vec<Weapon>>().await.expect("Wrong json format");
|
||||
}
|
||||
|
@ -116,6 +122,6 @@ impl Weapon {
|
|||
|
||||
#[test]
|
||||
fn test_weapon() {
|
||||
let data = fs::read_to_string("test/weapon.json").expect("No Weapon test file");
|
||||
let data = std::fs::read_to_string("test/weapon.json").expect("No Weapon test file");
|
||||
serde_json::from_str::<Weapon>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
use std::borrow::Borrow;
|
||||
use std::ops::Add;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use rand::Rng;
|
||||
use serenity::{
|
||||
|
@ -10,7 +8,6 @@ use serenity::{
|
|||
};
|
||||
use serenity::builder::CreateEmbed;
|
||||
use serenity::model::id::{ChannelId, MessageId};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use serenity::model::interactions::application_command::ApplicationCommandInteraction;
|
||||
use serenity::model::interactions::InteractionApplicationCommandCallbackDataFlags;
|
||||
|
@ -20,18 +17,9 @@ use crate::interactions::data::events::Event;
|
|||
use crate::utils::mongo::{add_discord_status_message, get_all_status_messages, get_discord_status_message, StatusMessage};
|
||||
|
||||
|
||||
pub fn copy_embed(from: &Vec<CreateEmbed>) -> Vec<CreateEmbed> {
|
||||
let mut cln: Vec<CreateEmbed> = vec![];
|
||||
for x in from {
|
||||
cln.push(x.clone());
|
||||
}
|
||||
cln
|
||||
}
|
||||
|
||||
pub async fn update_status_message(ctx: Context) {
|
||||
let forever = tokio::task::spawn(async move {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(60*60));
|
||||
let mut counter = Arc::new(Mutex::new(0));
|
||||
loop {
|
||||
let mut x = get_all_status_messages().await;
|
||||
x.reverse();
|
||||
|
@ -47,8 +35,7 @@ pub async fn update_status_message(ctx: Context) {
|
|||
match m.edit(&ctx.http, |f| {
|
||||
f.set_embeds((*embeds).to_owned())
|
||||
}).await {
|
||||
Ok(_) => {
|
||||
},
|
||||
Ok(_) => {},
|
||||
Err(e) => println!("Error while editing message {}", e)
|
||||
}
|
||||
}
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -129,18 +129,19 @@ impl EventHandler for Handler {
|
|||
}
|
||||
}
|
||||
|
||||
fn test_environment() {
|
||||
env::var("DISCORD_TOKEN").expect("DISCORD_TOKEN needed");
|
||||
env::var("MONGO_HOST").expect("MONGO_HOST needed");
|
||||
env::var("MONGO_PORT").expect("MONGO_PORT needed");
|
||||
env::var("API_HOST").expect("API_HOST needed");
|
||||
env::var("API_PORT").expect("API_PORT needed");
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
let mut token= "".to_string();
|
||||
for (k, v) in env::vars() {
|
||||
if k.eq("DISCORD_TOKEN") {
|
||||
token = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
test_environment();
|
||||
let token= env::var("DISCORD_TOKEN").unwrap();
|
||||
let application_id: u64 = "860553396578811914".parse().expect("Wrong format");
|
||||
|
||||
let needed_intents = [
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::env;
|
||||
use mongodb::bson::{Bson, doc, Document, from_bson, to_bson};
|
||||
use mongodb::{Client, Collection, options::ClientOptions};
|
||||
use futures::stream::{TryStreamExt};
|
||||
|
@ -59,7 +60,9 @@ pub async fn get_all_status_messages() -> Vec<StatusMessage> {
|
|||
|
||||
#[allow(dead_code)]
|
||||
async fn get_mongo_client() -> Client {
|
||||
let mut client_options = ClientOptions::parse("mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false").await.expect("Can't connect to db");
|
||||
let host = env::var("MONGO_HOST").unwrap();
|
||||
let port = env::var("MONGO_PORT").unwrap();
|
||||
let mut client_options = ClientOptions::parse(format!("mongodb://{}:{}/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false", host, port)).await.expect("Can't connect to db");
|
||||
client_options.app_name = Some("Drunk Venti".to_string());
|
||||
client_options.default_database = Some("drunk_venti".to_string());
|
||||
|
||||
|
|
Loading…
Reference in a new issue