Function get_data_followed_summoner

Source
pub async fn get_data_followed_summoner(
    collection: Collection<SummonerFollowedData>,
    guild_id: String,
) -> Result<Value, Box<dyn Error + Send + Sync>>
Expand description

⚙️ Function: Fetches the list of summoners followed in a specific Discord guild.

This asynchronous function retrieves data about summoners followed within a particular Discord guild. It queries the provided MongoDB collection for records matching the specified guild_id and returns a list of summoners, along with the remaining follow duration for each. If the follow has ended, it will return “Follow ended” for that summoner.

§Parameters:

  • collection: The MongoDB collection containing follow data, where each document represents a summoner being followed.
  • guild_id: A String representing the unique identifier of the Discord guild. This is used to filter the summoners being followed in that specific guild.

§Returns:

  • Result<Value, Error>: On success, it returns a serde_json::Value object containing a list of tracked summoners, each with their name and time_remaining (formatted as a human-readable string or “Follow ended” if the follow has expired). In case of an error, it returns an Error object.

§⚠️ Notes:

  • The function calculates the remaining follow duration by comparing the current timestamp with the time_end_follow value from each summoner’s record.
  • If a summoner’s follow has expired, the time remaining is returned as “Follow ended”.
  • The duration is formatted as a readable string for convenience.

§Example:

let collection: Collection<SummonerFollowedData> = db.collection("follower_summoner");
let guild_id = "1234567890".to_string();
let result = get_data_followed_summoner(collection, guild_id).await?;

// The result would look like:
/// ```json
/// {
///   "tracked_summoners": [
///     {
///       "name": "Summoner1",
///       "time_remaining": "2 hours 15 minutes"
///     },
///     {
///       "name": "Summoner2",
///       "time_remaining": "Follow ended"
///     }
///   ]
/// }