silly goober bot

chore: store `reqwest::Client` in userdata

authored by

Kaitlyn~Ethylia and committed by isabelroses.com 95063783 b124f7ad

+13 -10
+3 -2
src/commands/misc/nixpkgs.rs
··· 1 1 use color_eyre::eyre::Result; 2 2 use git_tracker::Tracker; 3 3 use poise::{serenity_prelude as serenity, CreateReply}; 4 - use reqwest; 5 4 use serde::Deserialize; 6 5 use std::env; 7 6 ··· 23 22 let github_token = env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN not set"); 24 23 let tracker = Tracker::from_path(&nixpkgs_path)?; 25 24 25 + let client = &ctx.data().client; 26 + 26 27 // find out what commit our PR was merged in 27 28 let Some(commit_sha) = ({ 28 29 let url = format!("https://api.github.com/repos/nixos/nixpkgs/pulls/{pr}"); 29 - let resp = reqwest::Client::new() 30 + let resp = client 30 31 .get(&url) 31 32 .header("User-Agent", "blahaj") 32 33 .header("Authorization", format!("Bearer {github_token}"))
+10 -8
src/main.rs
··· 2 2 mod event_handler; 3 3 4 4 use dotenv::dotenv; 5 + use reqwest::Client; 5 6 use std::env; 6 7 7 8 use color_eyre::eyre::{Report, Result}; 8 9 use poise::serenity_prelude::{self as serenity, ActivityData, GatewayIntents}; 9 10 10 11 #[derive(Debug)] 11 - pub struct Data {} // User data, which is stored and accessible in all command invocations 12 + pub struct Data { // User data, which is stored and accessible in all command invocations 13 + client: Client, 14 + } 12 15 13 16 pub type Context<'a> = poise::Context<'a, Data, Report>; 14 17 ··· 45 48 commands::fun::bottom::topify(), 46 49 commands::fun::bottom::bottomify(), 47 50 ], 48 - event_handler: |ctx, event, _, data| { 49 - Box::pin(async move { 50 - crate::event_handler::event_handler(ctx, event, data).await?; 51 - Ok(()) 52 - }) 53 - }, 51 + event_handler: |ctx, event, _, data| Box::pin(crate::event_handler::event_handler(ctx, event, data)), 54 52 ..Default::default() 55 53 }; 56 54 ··· 70 68 .set_commands(ctx, commands) 71 69 .await?; 72 70 73 - Ok(Data {}) 71 + Ok(Data { 72 + client: Client::builder() 73 + .user_agent("blahaj") 74 + .build()?, 75 + }) 74 76 }) 75 77 }) 76 78 .options(opts)