Add discord online-status
This commit is contained in:
parent
0c9e763e8c
commit
21c4b82658
31
src/main.rs
31
src/main.rs
@ -30,20 +30,28 @@ const CONFIG_PATH: &'static str = "./config.json";
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let config: Config = serde_json::from_slice(&fs::read(CONFIG_PATH).unwrap()).unwrap();
|
||||
|
||||
let client = Client::builder(&config.discord_token, GatewayIntents::empty())
|
||||
let mut client = Client::builder(&config.discord_token, GatewayIntents::empty())
|
||||
.await
|
||||
.expect("Err creating client");
|
||||
|
||||
let addr = SocketAddr::from((config.host, config.port));
|
||||
let listener = TcpListener::bind(addr).await?;
|
||||
|
||||
let cache = client.cache.clone();
|
||||
let http = client.http.clone();
|
||||
|
||||
let client_handle = tokio::task::spawn(async move {
|
||||
client.start().await.unwrap();
|
||||
});
|
||||
|
||||
let loop_handle = tokio::task::spawn(async move {
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await?;
|
||||
let (stream, _) = listener.accept().await.unwrap();
|
||||
|
||||
let io = TokioIo::new(stream);
|
||||
|
||||
let cache = client.cache.clone();
|
||||
let http = client.http.clone();
|
||||
let cache = cache.clone();
|
||||
let http = http.clone();
|
||||
let config = config.clone();
|
||||
|
||||
// Spawn a tokio task to serve multiple connections concurrently
|
||||
@ -65,6 +73,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let (res1, res2) = tokio::join!(client_handle, loop_handle);
|
||||
res1.unwrap();
|
||||
res2.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn hello(
|
||||
@ -136,12 +151,6 @@ async fn send(user: User, ctx: impl CacheHttp + Copy, event: MinifluxEvent, conf
|
||||
}
|
||||
|
||||
fn message_from_entry(entry: &Entry, feed: &Feed, config: &Config) -> CreateMessage {
|
||||
let content = MessageBuilder::new()
|
||||
.push("New article from feed ")
|
||||
.push_named_link(&feed.title, &feed.site_url)
|
||||
.push(" published!")
|
||||
.build();
|
||||
|
||||
let author = CreateEmbedAuthor::new(&feed.title).url(&feed.site_url);
|
||||
let footer = CreateEmbedFooter::new(format!("{} minutes", entry.reading_time.to_string()));
|
||||
|
||||
@ -171,5 +180,5 @@ fn message_from_entry(entry: &Entry, feed: &Feed, config: &Config) -> CreateMess
|
||||
let external_button = CreateButton::new_link(&entry.url).label("external").emoji('📤');
|
||||
let minreq_button = CreateButton::new_link(minreq_url).label("minreq").emoji('📩');
|
||||
|
||||
CreateMessage::new().content(content).embed(embed).button(external_button).button(minreq_button)
|
||||
CreateMessage::new().embed(embed).button(external_button).button(minreq_button)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user