Skip to content

Commit

Permalink
yay back online !!
Browse files Browse the repository at this point in the history
  • Loading branch information
rndrmu committed Jul 11, 2024
1 parent 2e8793b commit f3c9e2d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 54 deletions.
24 changes: 12 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"prefix": "..",
"channels": {
"xp": "763684496767451164",
"rules": "996332160590028830",
"news": "1025699834717552660",
"logs": "1001395505256996944",
"ads": "1001395505256996944",
"xp": "1111387940359262299",
"rules": "1111387940359262299",
"news": "1111387940359262299",
"logs": "1111387940359262299",
"ads": "1111387940359262299",
"createChannel": "🔊 New VoiceChannel",
"mealplan": "899606239804268545"
"mealplan": "1111387940359262299"
},
"colors": {
"blue": "#4200ff",
Expand Down Expand Up @@ -42,12 +42,12 @@
"rssSettings": {
"postRss": true,
"rssFeedData": {
"1087740850395693096": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=IF+BA+ALL&title=Thema",
"1087742021684449320": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=GE+BA+ALL&title=Thema",
"1087742288706404454": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=WK+BA+ALL&title=Thema",
"1087742576213368852": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=GP+MED+BA+ALL&title=Thema",
"1087743074500878346": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=MI+MA+ALL&title=Thema",
"1087743506010873856": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=GEVC+MA+MG+ALL&title=Thema"
"1111387940359262299": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=IF+BA+ALL&title=Thema",
"1070021986849390623": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=GE+BA+ALL&title=Thema",
"1092093144490852452": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=WK+BA+ALL&title=Thema",
"1093600976390344855": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=GP+MED+BA+ALL&title=Thema",
"1093600999173795950": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=MI+MA+ALL&title=Thema",
"1093601024087961700": "https://infotresen.if.hs-kempten.de/dokuwiki/lib/plugins/feed/feed.php?plugin=tag&fn=getTopic&ns=announcements&tag=GEVC+MA+MG+ALL&title=Thema"
},
"rssCheckIntervalHours": 1,
"rssCheckAfterTimeHours": 8
Expand Down
38 changes: 14 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ mod tasks;
mod utils;

use chrono::{DateTime, FixedOffset};
use influxdb2::{Client, models::WriteDataPoint};
use influxdb2::models::{Query, DataPoint};
use influxdb2::models::{DataPoint, Query};
use influxdb2::{models::WriteDataPoint, Client};


use tokio::stream;
use tracing_subscriber::prelude::*;
use dashmap::DashMap;
use dotenv::dotenv;
use poise::{
Expand All @@ -20,6 +17,8 @@ use poise::{
};
use sqlx::postgres::PgPoolOptions;
use structs::CodeEmailPair;
use tokio::stream;
use tracing_subscriber::prelude::*;
use utils::CurrentEmail;

pub mod prelude {
Expand Down Expand Up @@ -94,9 +93,6 @@ pub struct Data {
pub influx: influxdb2::Client,
}




#[tokio::main]
async fn main() -> Result<(), prelude::Error> {
// only load .env file if it exists
Expand All @@ -115,42 +111,37 @@ async fn main() -> Result<(), prelude::Error> {

// setup tracing



// de-noise tracing by readin the RUST_LOG env var
let tracing_layer = tracing_subscriber::EnvFilter::try_from_default_env()
.or_else(|_| tracing_subscriber::EnvFilter::try_new("info"))
.unwrap();

tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().with_filter(tracing_layer))
.init();
.with(tracing_subscriber::fmt::layer().with_filter(tracing_layer))
.init();

tracing::info!("Starting up");

let token = std::env::var("DISCORD_TOKEN").expect("Expected a token in the environment");

let db_url = std::env::var("DATABASE_URL").expect("Expected a database url in the environment");


let pool = PgPoolOptions::new()
.max_connections(15)
.connect(&db_url)
.await
.map_err(prelude::Error::Database)?;

let influx_host = "http://localhost:8086";
let influx_org = "acme";
let influx_bucket = "faculty";
let influx_host = "https://us-east-1-1.aws.cloud2.influxdata.com";
let influx_org = "faculty_manager";
let influx_bucket = "faculty_manager";
let auth_token = std::env::var("INFLUX_TOKEN").expect("Expected a token in the environment");


let influx_client = influxdb2::Client::new("http://localhost:8086", "acme", auth_token);

let influx_client = influxdb2::Client::new(influx_host, influx_org, auth_token);

let (tx, mut rx) = tokio::sync::mpsc::channel::<CurrentEmail>(100);

let _ = tokio::spawn(async move {
let _ = tokio::spawn(async move {
tracing::info!("Starting email task");
loop {
if let Some(email) = rx.recv().await {
Expand All @@ -174,18 +165,15 @@ async fn main() -> Result<(), prelude::Error> {
commands::user::verify(),
commands::user::leaderboard(),
commands::user::xp(),

commands::administration::getmail(),
commands::administration::run_command(),
commands::administration::set_xp(),
commands::administration::force_post_mensaplan(),
commands::administration::rule_command(),

commands::moderation::pin(),
commands::moderation::delete_message(),
commands::moderation::promote_user(),
commands::moderation::demote_user(),

commands::help(),
],
prefix_options: poise::PrefixFrameworkOptions {
Expand All @@ -202,7 +190,9 @@ async fn main() -> Result<(), prelude::Error> {
})
.setup(move |ctx, _ready, framework| {
Box::pin(async move {
if let Ok(_) = poise::builtins::register_globally(ctx, &framework.options().commands).await {
if let Ok(_) =
poise::builtins::register_globally(ctx, &framework.options().commands).await
{
tracing::info!("Successfully registered Application Commands globally");
} else {
tracing::error!("Failed to register commands globally");
Expand Down
40 changes: 22 additions & 18 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
structs::{self},
Data,
};
use chrono::{Datelike, Timelike, Duration};
use chrono::{Datelike, Duration, Timelike};
use influxdb2::models::DataPoint;
use poise::serenity_prelude::{self as serenity, Mentionable, ShardId};
use rss::Channel;
Expand Down Expand Up @@ -140,8 +140,10 @@ pub async fn post_rss(ctx: serenity::Context, data: Data) -> Result<(), Error> {
// parse to chrono Local
let date = chrono::DateTime::parse_from_rfc2822(date_).unwrap();

// to combat spam, filter out old items (all before May 1st 2023)
if date < chrono::DateTime::parse_from_rfc2822("01 May 2023 00:00:00 +0200").unwrap()
// to combat spam, filter out old items (all before July 11th 2024)
if date
< chrono::DateTime::parse_from_rfc2822("Wed, 11 Jul 2024 00:00:00 +0200")
.unwrap()
{
continue;
} else {
Expand Down Expand Up @@ -194,6 +196,7 @@ pub async fn post_rss(ctx: serenity::Context, data: Data) -> Result<(), Error> {
} else {
// because let-else won't let me not return from this
// post
println!("Posting new rss item");
if let Err(why) = post_item(
&ctx,
&db,
Expand All @@ -210,7 +213,7 @@ pub async fn post_rss(ctx: serenity::Context, data: Data) -> Result<(), Error> {
}
}

tracing::debug!("Posting in channel: {}", channel_id.0);
tracing::info!("Posting in channel: {}", channel_id.0);
}
}

Expand Down Expand Up @@ -338,8 +341,6 @@ async fn post_item(
Ok(())
}



pub async fn log_latency_to_influx(
ctx: &serenity::Context,
sm: Arc<serenity::Mutex<serenity::ShardManager>>,
Expand All @@ -350,20 +351,23 @@ pub async fn log_latency_to_influx(
let shard = ctx.shard_id;
let locked = sm.lock().await;
let runner = locked.runners.lock().await;
let latency = runner.get(&ShardId(shard)).unwrap().latency.unwrap_or(std::time::Duration::from_nanos(0));


let points = vec![
DataPoint::builder("latency")
.field("latency", latency.as_millis() as i64)
.timestamp(chrono::Utc::now().timestamp_nanos())
.build()
.unwrap(),
];
let latency = runner
.get(&ShardId(shard))
.unwrap()
.latency
.unwrap_or(std::time::Duration::from_nanos(0));

let points = vec![DataPoint::builder("latency")
.field("latency", latency.as_millis() as i64)
.timestamp(chrono::Utc::now().timestamp_nanos())
.build()
.unwrap()];

influx.write("faculty", futures::stream::iter(points)).await.unwrap();
influx
.write("facultymanager", futures::stream::iter(points))
.await
.unwrap();

tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
}
}
}

0 comments on commit f3c9e2d

Please sign in to comment.