pub async fn process_followed_summoner(
collection: &Collection<SummonerFollowedData>,
followed_summoner: &SummonerFollowedData,
riot_api_key: &str,
http: Arc<Http>,
collection_emojis: Collection<EmojiId>,
) -> Result<(), Box<dyn Error + Send + Sync>>Expand description
⚙️ Function: Processes a followed summoner by checking if their follow time has expired or if they have played a new match.
This asynchronous function handles the logic for a followed summoner. It checks if the follow time has expired and removes the summoner from the database if necessary. If the follow time is still valid, it checks for new matches and updates the summoner’s information accordingly.
§Parameters:
collection: A reference to a MongoDBCollection<SummonerFollowedData>that stores the followed summoners’ data.followed_summoner: A reference to aSummonerFollowedDatastruct containing the summoner’s information, including their follow duration and last match details.riot_api_key: A string slice containing the Riot Games API key for authenticating the API request.http: AnArc<Http>object used to send messages via the Discord API.collection_emojis: A MongoDBCollectioncontaining emoji mappings, used to enrich the Discord embeds with custom emojis for roles and champions.
§Returns:
Result<(), Error>: ReturnsOk(())if the summoner was successfully processed (either by removing them from the database or updating their match info), or an error if something went wrong.
§Example:
This function is typically called as part of a loop or scheduled task that checks the status of followed summoners:
let result = process_followed_summoner(collection, &followed_summoner, riot_api_key, http.clone(), collection_emojis).await;
if result.is_err() {
// Handle error (e.g., log failure or retry)
}§Notes:
- The function begins by checking if the follow time for the summoner has expired using the
is_follow_time_expiredfunction. - If the follow time has expired, the summoner is removed from the MongoDB collection by calling
delete_follower. - If the summoner is still being followed, the function calls
update_follower_if_new_matchto check for new matches and potentially send an update to the associated Discord channel. - This function ensures that summoners are only followed for the specified duration and that Discord channels are updated with relevant match information during the follow period.