Parallel Message edit
This commit is contained in:
parent
c31ced4945
commit
b46f0bac46
4 changed files with 28 additions and 27 deletions
8
.idea/.gitignore
vendored
8
.idea/.gitignore
vendored
|
@ -1,8 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
|
@ -23,3 +23,4 @@ futures = "0.3.19"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
dotenv_codegen = "0.15.0"
|
dotenv_codegen = "0.15.0"
|
||||||
|
rayon = "1.5.3"
|
|
@ -1,3 +1,6 @@
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::ops::Add;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
|
@ -7,6 +10,7 @@ use serenity::{
|
||||||
};
|
};
|
||||||
use serenity::builder::CreateEmbed;
|
use serenity::builder::CreateEmbed;
|
||||||
use serenity::model::id::{ChannelId, MessageId};
|
use serenity::model::id::{ChannelId, MessageId};
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use serenity::model::interactions::application_command::ApplicationCommandInteraction;
|
use serenity::model::interactions::application_command::ApplicationCommandInteraction;
|
||||||
use serenity::model::interactions::InteractionApplicationCommandCallbackDataFlags;
|
use serenity::model::interactions::InteractionApplicationCommandCallbackDataFlags;
|
||||||
|
@ -27,30 +31,34 @@ pub fn copy_embed(from: &Vec<CreateEmbed>) -> Vec<CreateEmbed> {
|
||||||
pub async fn update_status_message(ctx: Context) {
|
pub async fn update_status_message(ctx: Context) {
|
||||||
let forever = tokio::task::spawn(async move {
|
let forever = tokio::task::spawn(async move {
|
||||||
let mut interval = tokio::time::interval(Duration::from_secs(60*60));
|
let mut interval = tokio::time::interval(Duration::from_secs(60*60));
|
||||||
|
let mut counter = Arc::new(Mutex::new(0));
|
||||||
loop {
|
loop {
|
||||||
let mut x = get_all_status_messages().await;
|
let mut x = get_all_status_messages().await;
|
||||||
x.reverse();
|
x.reverse();
|
||||||
|
|
||||||
let embeds = create_status_embed().await;
|
let embeds = create_status_embed().await;
|
||||||
for sm in x {
|
for sm in x {
|
||||||
if sm.channel_id == 0 {continue;}
|
let embeds : Vec<CreateEmbed> = (&embeds).clone();
|
||||||
let msg = ChannelId::from(sm.channel_id as u64).message(&ctx.http, sm.message_id as u64).await;
|
let ctx = ctx.borrow().clone();
|
||||||
match msg {
|
tokio::spawn( async move {
|
||||||
Ok(mut m) => {
|
if sm.channel_id == 0 { return }
|
||||||
let copies = copy_embed(&embeds);
|
let msg = ChannelId::from(sm.channel_id as u64).message(ctx.borrow().clone().http, sm.message_id as u64).await;
|
||||||
match m.edit(&ctx.http, |f| {
|
match msg {
|
||||||
f.set_embeds(copies)
|
Ok(mut m) => {
|
||||||
}).await {
|
match m.edit(&ctx.http, |f| {
|
||||||
Ok(_) => {},
|
f.set_embeds((*embeds).to_owned())
|
||||||
Err(e) => println!("Error while editing message {}", e)
|
}).await {
|
||||||
|
Ok(_) => {
|
||||||
|
},
|
||||||
|
Err(e) => println!("Error while editing message {}", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("Cannot update guild : {}", sm.channel_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
println!("Cannot update guild : {}", sm.channel_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ use mongodb::{Client, Collection, options::ClientOptions};
|
||||||
use futures::stream::{TryStreamExt};
|
use futures::stream::{TryStreamExt};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct StatusMessage {
|
pub struct StatusMessage {
|
||||||
pub(crate) guild_id: i64,
|
pub(crate) guild_id: i64,
|
||||||
pub(crate) message_id: i64,
|
pub(crate) message_id: i64,
|
||||||
|
|
Loading…
Reference in a new issue