This commit is contained in:
Cadey Ratio 2020-11-04 11:03:04 -05:00
parent 79eb929f26
commit 90b9d53bf8
4 changed files with 10 additions and 15 deletions

View File

@ -29,8 +29,6 @@ api_secret = "..."
# the API. # the API.
[global.mastodon] [global.mastodon]
instance = "..." instance = "..."
app_id = "..."
app_secret = "..."
token = "..." token = "..."
account = "..." account = "..."

View File

@ -9,7 +9,7 @@ use color_eyre::eyre::Result;
use rocket_contrib::helmet::SpaceHelmet; use rocket_contrib::helmet::SpaceHelmet;
use rocket_prometheus::PrometheusMetrics; use rocket_prometheus::PrometheusMetrics;
use ::mi::{api, paseto, web, MainDatabase, APPLICATION_NAME}; use ::mi::{api, paseto, web::*, MainDatabase, APPLICATION_NAME};
#[get("/.within/botinfo")] #[get("/.within/botinfo")]
fn botinfo() -> &'static str { fn botinfo() -> &'static str {
@ -43,11 +43,11 @@ fn main() -> Result<()> {
.attach(MainDatabase::fairing()) .attach(MainDatabase::fairing())
.attach(SpaceHelmet::default()) .attach(SpaceHelmet::default())
.attach(paseto::ed25519_keypair()) .attach(paseto::ed25519_keypair())
.attach(web::discord_webhook::Client::fairing()) .attach(discord_webhook::Client::fairing())
.attach(web::mastodon::Client::fairing()) .attach(mastodon::Client::fairing())
.attach(web::pluralkit::Client::fairing()) .attach(pluralkit::Client::fairing())
.attach(web::switchcounter::Client::fairing()) .attach(switchcounter::Client::fairing())
.attach(web::twitter::Client::fairing()) .attach(twitter::Client::fairing())
.mount("/metrics", prometheus) .mount("/metrics", prometheus)
.mount("/", routes![botinfo]) .mount("/", routes![botinfo])
.mount( .mount(

View File

@ -44,7 +44,9 @@ impl Client {
} }
pub fn send(&self, body: String) -> Result<()> { pub fn send(&self, body: String) -> Result<()> {
let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(Body::new(body))?); let resp = ureq::post(&self.webhook_url)
.set("User-Agent", crate::APPLICATION_NAME)
.send_json(serde_json::to_value(Body::new(body))?);
if resp.ok() { if resp.ok() {
Ok(()) Ok(())

View File

@ -3,8 +3,6 @@ use rocket::fairing::AdHoc;
pub struct Client { pub struct Client {
instance_url: String, instance_url: String,
app_id: String,
app_secret: String,
token: String, token: String,
account_name: String, account_name: String,
} }
@ -15,15 +13,11 @@ impl Client {
let cfg = rocket.config(); let cfg = rocket.config();
let table = cfg.get_table("mastodon").unwrap(); let table = cfg.get_table("mastodon").unwrap();
let instance_url = table["instance"].as_str().unwrap().to_string(); let instance_url = table["instance"].as_str().unwrap().to_string();
let app_id = table["app_id"].as_str().unwrap().to_string();
let app_secret = table["app_secret"].as_str().unwrap().to_string();
let token = table["token"].as_str().unwrap().to_string(); let token = table["token"].as_str().unwrap().to_string();
let account_name = table["account"].as_str().unwrap().to_string(); let account_name = table["account"].as_str().unwrap().to_string();
let cli = Client { let cli = Client {
instance_url: instance_url, instance_url: instance_url,
app_id: app_id,
app_secret: app_secret,
token: token, token: token,
account_name: account_name, account_name: account_name,
}; };
@ -41,6 +35,7 @@ impl Client {
let resp = ureq::post(url) let resp = ureq::post(url)
.set("Authorization", &format!("bearer {}", self.token)) .set("Authorization", &format!("bearer {}", self.token))
.set("User-Agent", crate::APPLICATION_NAME)
.send_form(&[("status", body.as_str())]); .send_form(&[("status", body.as_str())]);
if resp.ok() { if resp.ok() {