refactor: clean up clippy warnings
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -6474,6 +6474,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"redis-kiss",
|
"redis-kiss",
|
||||||
|
"revolt-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -101,9 +101,9 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr)
|
|||||||
|
|
||||||
info!("User {addr:?} authenticated as @{}", user.username);
|
info!("User {addr:?} authenticated as @{}", user.username);
|
||||||
|
|
||||||
let _ = db
|
db.update_session_last_seen(&session_id, Timestamp::now_utc())
|
||||||
.update_session_last_seen(&session_id, Timestamp::now_utc())
|
.await
|
||||||
.await;
|
.ok();
|
||||||
|
|
||||||
// Create local state.
|
// Create local state.
|
||||||
let mut state = State::from(user, session_id);
|
let mut state = State::from(user, session_id);
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update server data
|
/// Update server data
|
||||||
pub async fn update<'a>(
|
pub async fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
partial: PartialServer,
|
partial: PartialServer,
|
||||||
|
|||||||
@@ -7,11 +7,5 @@ mod rocket;
|
|||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
mod schema;
|
mod schema;
|
||||||
|
|
||||||
#[cfg(feature = "axum-impl")]
|
|
||||||
pub use self::axum::*;
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
pub use self::rocket::*;
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
pub use self::schema::*;
|
|
||||||
pub use model::*;
|
pub use model::*;
|
||||||
pub use ops::*;
|
pub use ops::*;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use ::mongodb::options::{Collation, CollationStrength, FindOneOptions, FindOptions};
|
use ::mongodb::options::{Collation, CollationStrength, FindOneOptions, FindOptions};
|
||||||
use authifier::models::Session;
|
use authifier::models::Session;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use iso8601_timestamp::{typenum as t, Timestamp, UtcOffset};
|
use iso8601_timestamp::Timestamp;
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::DocumentId;
|
use crate::DocumentId;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
|
|||||||
|
|
||||||
use crate::events::client::EventV1;
|
use crate::events::client::EventV1;
|
||||||
|
|
||||||
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(|| unbounded());
|
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(unbounded);
|
||||||
|
|
||||||
/// Get sender
|
/// Get sender
|
||||||
pub fn sender() -> Sender<AuthifierEvent> {
|
pub fn sender() -> Sender<AuthifierEvent> {
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ impl crate::Bot {
|
|||||||
avatar: user.avatar.map(|x| x.id).unwrap_or_default(),
|
avatar: user.avatar.map(|x| x.id).unwrap_or_default(),
|
||||||
description: user
|
description: user
|
||||||
.profile
|
.profile
|
||||||
.map(|profile| profile.content)
|
.and_then(|profile| profile.content)
|
||||||
.flatten()
|
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1114,7 +1113,7 @@ impl crate::User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert user object into user model without presence information
|
/// Convert user object into user model without presence information
|
||||||
pub async fn into_known_static<'a>(self, is_online: bool) -> User {
|
pub async fn into_known_static(self, is_online: bool) -> User {
|
||||||
let badges = self.get_badges().await;
|
let badges = self.get_badges().await;
|
||||||
|
|
||||||
User {
|
User {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ use revolt_rocket_okapi::{
|
|||||||
use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
impl<'r> OpenApiFromRequest<'r> for IdempotencyKey {
|
impl OpenApiFromRequest<'_> for IdempotencyKey {
|
||||||
fn from_request_input(
|
fn from_request_input(
|
||||||
_gen: &mut OpenApiGenerator,
|
_gen: &mut OpenApiGenerator,
|
||||||
_name: String,
|
_name: String,
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
self.cached_mutual_connection = Some(value);
|
self.cached_mutual_connection = Some(value);
|
||||||
matches!(value, true)
|
value
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,14 +310,14 @@ impl Channel {
|
|||||||
/// This returns a Result because the recipient name can't be determined here without a db call,
|
/// This returns a Result because the recipient name can't be determined here without a db call,
|
||||||
/// which can't be done since this is models, which can't reference the database crate.
|
/// which can't be done since this is models, which can't reference the database crate.
|
||||||
///
|
///
|
||||||
/// If it returns Err, you need to fetch the name from the db.
|
/// If it returns None, you need to fetch the name from the db.
|
||||||
pub fn name(&self) -> Result<&str, ()> {
|
pub fn name(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
Channel::DirectMessage { .. } => Err(()),
|
Channel::DirectMessage { .. } => None,
|
||||||
Channel::SavedMessages { .. } => Ok("Saved Messages"),
|
Channel::SavedMessages { .. } => Some("Saved Messages"),
|
||||||
Channel::TextChannel { name, .. }
|
Channel::TextChannel { name, .. }
|
||||||
| Channel::Group { name, .. }
|
| Channel::Group { name, .. }
|
||||||
| Channel::VoiceChannel { name, .. } => Ok(name),
|
| Channel::VoiceChannel { name, .. } => Some(name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ redis-is-patched = []
|
|||||||
# Async
|
# Async
|
||||||
async-std = { version = "1.8.0", features = ["attributes"] }
|
async-std = { version = "1.8.0", features = ["attributes"] }
|
||||||
|
|
||||||
|
# Config for loading Redis URI
|
||||||
|
revolt-config = { version = "0.8.7", path = "../config" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Utility
|
# Utility
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ mod tests {
|
|||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn it_works() {
|
async fn it_works() {
|
||||||
|
revolt_config::config().await;
|
||||||
|
|
||||||
// Clear the region before we start the tests:
|
// Clear the region before we start the tests:
|
||||||
clear_region(None).await;
|
clear_region(None).await;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub async fn fetch_public_bot(
|
|||||||
target: Reference,
|
target: Reference,
|
||||||
) -> Result<Json<PublicBot>> {
|
) -> Result<Json<PublicBot>> {
|
||||||
let bot = db.fetch_bot(&target.id).await?;
|
let bot = db.fetch_bot(&target.id).await?;
|
||||||
if !bot.public && user.map_or(true, |x| x.id != bot.owner) {
|
if !bot.public && user.is_none_or(|x| x.id != bot.owner) {
|
||||||
return Err(create_error!(NotFound));
|
return Err(create_error!(NotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ pub async fn message_send(
|
|||||||
// Create model user / members
|
// Create model user / members
|
||||||
let model_user = user
|
let model_user = user
|
||||||
.clone()
|
.clone()
|
||||||
.into_known_static(revolt_presence::is_online(&user.id).await).await;
|
.into_known_static(revolt_presence::is_online(&user.id).await)
|
||||||
|
.await;
|
||||||
|
|
||||||
let model_member: Option<v0::Member> = query
|
let model_member: Option<v0::Member> = query
|
||||||
.member_ref()
|
.member_ref()
|
||||||
@@ -491,7 +492,7 @@ mod test {
|
|||||||
let (_, _, other_user) = harness.new_user().await;
|
let (_, _, other_user) = harness.new_user().await;
|
||||||
let (server, _) = harness.new_server(&user).await;
|
let (server, _) = harness.new_server(&user).await;
|
||||||
let channel = harness.new_channel(&server).await;
|
let channel = harness.new_channel(&server).await;
|
||||||
let (role_id, mut role) = harness
|
let (role_id, _role) = harness
|
||||||
.new_role(
|
.new_role(
|
||||||
&server,
|
&server,
|
||||||
1,
|
1,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ pub async fn call(
|
|||||||
// - If not, create it.
|
// - If not, create it.
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let result = client
|
let result = client
|
||||||
.get(&format!(
|
.get(format!(
|
||||||
"{}/room/{}",
|
"{}/room/{}",
|
||||||
config.hosts.voso_legacy,
|
config.hosts.voso_legacy,
|
||||||
channel.id()
|
channel.id()
|
||||||
@@ -59,7 +59,7 @@ pub async fn call(
|
|||||||
reqwest::StatusCode::OK => (),
|
reqwest::StatusCode::OK => (),
|
||||||
reqwest::StatusCode::NOT_FOUND => {
|
reqwest::StatusCode::NOT_FOUND => {
|
||||||
if (client
|
if (client
|
||||||
.post(&format!(
|
.post(format!(
|
||||||
"{}/room/{}",
|
"{}/room/{}",
|
||||||
config.hosts.voso_legacy,
|
config.hosts.voso_legacy,
|
||||||
channel.id()
|
channel.id()
|
||||||
@@ -81,7 +81,7 @@ pub async fn call(
|
|||||||
|
|
||||||
// Then create a user for the room.
|
// Then create a user for the room.
|
||||||
if let Ok(response) = client
|
if let Ok(response) = client
|
||||||
.post(&format!(
|
.post(format!(
|
||||||
"{}/room/{}/user/{}",
|
"{}/room/{}/user/{}",
|
||||||
config.hosts.voso_legacy,
|
config.hosts.voso_legacy,
|
||||||
channel.id(),
|
channel.id(),
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
use revolt_database::{events::client::EventV1, Database, Report, Snapshot, SnapshotContent, User};
|
use revolt_database::{Database, User};
|
||||||
use revolt_models::v0::{ReportStatus, ReportedContent};
|
use revolt_result::Result;
|
||||||
use revolt_result::{create_error, Result};
|
|
||||||
use serde::Deserialize;
|
|
||||||
use ulid::Ulid;
|
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
use rocket::{serde::json::Json, State};
|
use rocket::State;
|
||||||
|
|
||||||
/// # Acknowledge Policy Changes
|
/// # Acknowledge Policy Changes
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ pub async fn root() -> Result<Json<RevoltConfig>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "FIXME: THIS TEST CAUSES cargo test TO SEG FAULT, I HAVE NO CLUE HOW")]
|
|
||||||
mod test {
|
mod test {
|
||||||
use crate::rocket;
|
use crate::rocket;
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ pub async fn webhook_execute(
|
|||||||
let permissions: PermissionValue = webhook.permissions.into();
|
let permissions: PermissionValue = webhook.permissions.into();
|
||||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::SendMessage)?;
|
permissions.throw_if_lacking_channel_permission(ChannelPermission::SendMessage)?;
|
||||||
|
|
||||||
if data.attachments.as_ref().map_or(false, |v| !v.is_empty()) {
|
if data.attachments.as_ref().is_some_and(|v| !v.is_empty()) {
|
||||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::UploadFiles)?;
|
permissions.throw_if_lacking_channel_permission(ChannelPermission::UploadFiles)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.embeds.as_ref().map_or(false, |v| !v.is_empty()) {
|
if data.embeds.as_ref().is_some_and(|v| !v.is_empty()) {
|
||||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::SendEmbeds)?;
|
permissions.throw_if_lacking_channel_permission(ChannelPermission::SendEmbeds)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ pub struct Event {
|
|||||||
#[derive(Debug, JsonSchema)]
|
#[derive(Debug, JsonSchema)]
|
||||||
pub struct EventHeader<'r>(pub &'r str);
|
pub struct EventHeader<'r>(pub &'r str);
|
||||||
|
|
||||||
impl<'r> std::ops::Deref for EventHeader<'r> {
|
impl std::ops::Deref for EventHeader<'_> {
|
||||||
type Target = str;
|
type Target = str;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
|||||||
@@ -109,8 +109,6 @@ fn resolve_bucket<'r>(request: &'r rocket::Request<'_>) -> (&'r str, Option<&'r
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(segment) = segment {
|
if let Some(segment) = segment {
|
||||||
let resource = resource;
|
|
||||||
|
|
||||||
let method = request.method();
|
let method = request.method();
|
||||||
match (segment, resource, method) {
|
match (segment, resource, method) {
|
||||||
("users", target, Method::Patch) => ("user_edit", target),
|
("users", target, Method::Patch) => ("user_edit", target),
|
||||||
@@ -254,7 +252,7 @@ impl<'r> FromRequest<'r> for Ratelimiter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> OpenApiFromRequest<'r> for Ratelimiter {
|
impl OpenApiFromRequest<'_> for Ratelimiter {
|
||||||
fn from_request_input(
|
fn from_request_input(
|
||||||
_gen: &mut OpenApiGenerator,
|
_gen: &mut OpenApiGenerator,
|
||||||
_name: String,
|
_name: String,
|
||||||
|
|||||||
@@ -198,10 +198,7 @@ impl TestHarness {
|
|||||||
(channel.clone(), member, message)
|
(channel.clone(), member, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn with_session<'c>(
|
pub async fn with_session(session: Session, request: LocalRequest<'_>) -> LocalResponse<'_> {
|
||||||
session: Session,
|
|
||||||
request: LocalRequest<'c>,
|
|
||||||
) -> LocalResponse<'c> {
|
|
||||||
request
|
request
|
||||||
.header(Header::new("x-session-token", session.token.to_string()))
|
.header(Header::new("x-session-token", session.token.to_string()))
|
||||||
.dispatch()
|
.dispatch()
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ pub async fn populate_special(original_url: String, metadata: &mut WebsiteMetada
|
|||||||
Special::Twitch { .. } => metadata.colour = Some("#7B68EE".to_string()),
|
Special::Twitch { .. } => metadata.colour = Some("#7B68EE".to_string()),
|
||||||
Special::Lightspeed { .. } => metadata.colour = Some("#7445D9".to_string()),
|
Special::Lightspeed { .. } => metadata.colour = Some("#7445D9".to_string()),
|
||||||
Special::Spotify { .. } => metadata.colour = Some("#1ABC9C".to_string()),
|
Special::Spotify { .. } => metadata.colour = Some("#1ABC9C".to_string()),
|
||||||
Special::Soundcloud { .. } => metadata.colour = Some("#FF7F50".to_string()),
|
Special::Soundcloud => metadata.colour = Some("#FF7F50".to_string()),
|
||||||
Special::AppleMusic { .. } => metadata.colour = Some("#FA233B".to_string()),
|
Special::AppleMusic { .. } => metadata.colour = Some("#FA233B".to_string()),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user