mirror of
https://github.com/Noratrieb/killjoy-turret.git
synced 2026-01-14 14:45:01 +01:00
log properly
This commit is contained in:
parent
e6414abaf1
commit
1488568e12
6 changed files with 119 additions and 31 deletions
88
Cargo.lock
generated
88
Cargo.lock
generated
|
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
|
|
@ -15,6 +17,21 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.50"
|
||||
|
|
@ -465,11 +482,14 @@ dependencies = [
|
|||
name = "killjoy_turret"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serenity",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -899,12 +919,27 @@ dependencies = [
|
|||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.4.0"
|
||||
|
|
@ -938,6 +973,15 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
|
|
@ -1024,9 +1068,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
|
|||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.26"
|
||||
version = "0.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d"
|
||||
checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"log",
|
||||
|
|
@ -1037,9 +1081,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.15"
|
||||
version = "0.1.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2"
|
||||
checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -1048,11 +1092,37 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.18"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052"
|
||||
checksum = "aa31669fa42c09c34d94d8165dd2012e8ff3c66aca50f3bb226b68f216f2706c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"log",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e0ab7bdc962035a87fba73f3acca9b8a8d0034c2e6f60b84aeaaddddc155dce"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1155,6 +1225,12 @@ version = "0.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
|||
serde = { version = "1.0.126", features = ["derive"] }
|
||||
serde_json = "1.0.64"
|
||||
regex = "1.5.4"
|
||||
tracing = "0.1.32"
|
||||
tracing-subscriber = "0.3.9"
|
||||
anyhow = "1.0.56"
|
||||
|
||||
[dependencies.serenity]
|
||||
version = "0.10.7"
|
||||
|
|
|
|||
15
Dockerfile
15
Dockerfile
|
|
@ -1,17 +1,14 @@
|
|||
#FROM rust:latest as build
|
||||
#RUN sudo apt-get install musl-tools
|
||||
#WORKDIR /app
|
||||
#COPY . ./
|
||||
#RUN rustup target add x86_64-unknown-linux-musl
|
||||
#RUN cargo build --release --target x86_64-unknown-linux-musl
|
||||
FROM rust:alpine3.15 as build
|
||||
WORKDIR /app
|
||||
COPY . ./
|
||||
RUN cargo build --release
|
||||
|
||||
FROM alpine:latest
|
||||
#COPY --from=build /app/target/x86_64-unknown-linux-musl/release/killjoy_turret /app/killjoy_turret
|
||||
COPY ./target/x86_64-unknown-linux-musl/debug/killjoy_turret /usr/local/bin/killjoy_turret
|
||||
COPY --from=build /app/target/release/killjoy_turret /usr/local/bin/killjoy_turret
|
||||
|
||||
COPY ./config.json /app/config.json
|
||||
COPY ./entrypoint.sh /app/entrypoint.sh
|
||||
|
||||
ENV CONFIG_PATH=/app/config.json
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/killjoy_turret"]
|
||||
ENTRYPOINT ["sh", "./entrypoint.sh"]
|
||||
|
|
@ -7,6 +7,7 @@ use serenity::model::prelude::*;
|
|||
use serenity::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
use tracing::info;
|
||||
|
||||
pub struct AutoRoleDataKey;
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ async fn autorole(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
|||
|
||||
while let Some(answer) = &msg.author.await_reply(&ctx).timeout(Duration::from_secs(30)).await {
|
||||
if let Some(emote) = answer.content.split(' ').next() {
|
||||
println!("should add emote: {}", emote);
|
||||
info!(%emote, "should add emote");
|
||||
answer.react(http, '☑').await?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
use serenity::framework::standard::macros::hook;
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ConfigFile {
|
||||
|
|
@ -21,8 +22,8 @@ pub async fn normal_message(ctx: &Context, msg: &Message) {
|
|||
let lowercase_content = msg.content.to_lowercase();
|
||||
for (trigger, reaction) in &reactions.auto_react {
|
||||
if lowercase_content.contains(trigger) {
|
||||
if let Err(why) = msg.react(&ctx.http, ReactionType::Unicode(reaction.clone())).await {
|
||||
eprintln!("Error reacting {}", why);
|
||||
if let Err(err) = msg.react(&ctx.http, ReactionType::Unicode(reaction.clone())).await {
|
||||
error!(%err, "Error reacting");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
36
src/main.rs
36
src/main.rs
|
|
@ -2,6 +2,7 @@ mod autorole;
|
|||
mod commands;
|
||||
mod general;
|
||||
|
||||
use anyhow::{bail, Context as _};
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
|
|
@ -13,24 +14,33 @@ use serenity::framework::StandardFramework;
|
|||
use serenity::http::Http;
|
||||
use serenity::model::id::UserId;
|
||||
use serenity::{async_trait, model::gateway::Ready, prelude::*};
|
||||
use tracing::{info, Level};
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
info!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_level(true)
|
||||
.with_timer(tracing_subscriber::fmt::time::time())
|
||||
.with_ansi(true)
|
||||
.with_thread_names(false)
|
||||
.with_max_level(Level::INFO)
|
||||
.init();
|
||||
|
||||
let file_path = std::env::var("CONFIG_PATH").unwrap_or_else(|_| "./config.json".to_string());
|
||||
let file = fs::read_to_string(&file_path).unwrap_or_else(|err| {
|
||||
eprintln!("Error reading config file ({file_path}): {err}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
let config = serde_json::from_str::<ConfigFile>(&file).unwrap();
|
||||
let file = fs::read_to_string(&file_path)
|
||||
.context("Error reading config file")
|
||||
.context(file_path)?;
|
||||
|
||||
let config = serde_json::from_str::<ConfigFile>(&file).context("parse config")?;
|
||||
|
||||
let token = &config.token;
|
||||
|
||||
|
|
@ -42,10 +52,10 @@ async fn main() {
|
|||
owners.insert(UserId(414755070161453076)); //nils
|
||||
match http.get_current_user().await {
|
||||
Ok(bot_id) => (owners, bot_id.id),
|
||||
Err(why) => panic!("Could not access the bot id: {:?}", why),
|
||||
Err(why) => bail!("Could not access the bot id: {:?}", why),
|
||||
}
|
||||
}
|
||||
Err(why) => panic!("Could not access application info: {:?}", why),
|
||||
Err(why) => bail!("Could not access application info: {:?}", why),
|
||||
};
|
||||
|
||||
let framework = StandardFramework::new()
|
||||
|
|
@ -64,7 +74,7 @@ async fn main() {
|
|||
.event_handler(Handler)
|
||||
.framework(framework)
|
||||
.await
|
||||
.expect("Err creating client");
|
||||
.context("creating client")?;
|
||||
|
||||
{
|
||||
let mut data = client.data.write().await;
|
||||
|
|
@ -72,7 +82,7 @@ async fn main() {
|
|||
data.insert::<ConfigFile>(config);
|
||||
}
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
println!("Client error: {:?}", why);
|
||||
}
|
||||
client.start().await.context("running bot")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue