Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Oct 14, 2024
1 parent 22f76d0 commit 0fc2624
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/twitch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::env::args;

use brainrot::{twitch, TwitchChat, TwitchChatEvent};
use brainrot::{TwitchChat, TwitchChatEvent, twitch};
use futures_util::StreamExt;

#[tokio::main]
Expand Down
3 changes: 2 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
edition = "2021"
version = "Two"
style_edition = "2024"
unstable_features = true

max_width = 160
Expand All @@ -24,6 +24,7 @@ single_line_if_else_max_width = 96

reorder_imports = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
reorder_modules = true
trailing_comma = "Never"
match_block_trailing_comma = false
Expand Down
21 changes: 9 additions & 12 deletions src/twitch/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use chrono::{DateTime, TimeZone, Utc};
use irc::proto::{Command, Response};
use uuid::Uuid;

use crate::util::{get_utf8_slice, MapNonempty};
use crate::util::{MapNonempty, get_utf8_slice};

/// A user's role.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -125,19 +125,16 @@ pub(crate) fn to_chat_event(message: irc::proto::Message) -> Option<ChatEvent> {
.collect::<HashMap<_, _>>();

let (username, user_display_name) = match message.prefix? {
irc::proto::Prefix::Nickname(n1, n2, _) => (
n1,
match tags.remove("display-name") {
Some(display_name) => {
if display_name.is_empty() {
n2
} else {
display_name
}
irc::proto::Prefix::Nickname(n1, n2, _) => (n1, match tags.remove("display-name") {
Some(display_name) => {
if display_name.is_empty() {
n2
} else {
display_name
}
None => n2
}
),
None => n2
}),
_ => return None
};

Expand Down
2 changes: 1 addition & 1 deletion src/twitch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{

use futures_util::{Stream, StreamExt};
use irc::{
client::{prelude::Config, Client, ClientStream},
client::{Client, ClientStream, prelude::Config},
proto::Capability
};

Expand Down
5 changes: 2 additions & 3 deletions src/youtube/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ use regex::Regex;
use url::Url;

use super::{
get_http_client,
Error, get_http_client,
types::streams_page::{
FeedContentsRenderer, PageContentsRenderer, RichGridItem, RichItemContent, TabItemRenderer, ThumbnailOverlay, VideoTimeStatus, YouTubeInitialData
},
Error
}
};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions src/youtube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub use self::{
context::{ChannelSearchOptions, ChatContext, LiveStreamStatus},
error::Error,
types::{
get_live_chat::{Action, ChatItem, MessageRendererBase},
ImageContainer, LocalizedRun, LocalizedText, Thumbnail, UnlocalizedText
ImageContainer, LocalizedRun, LocalizedText, Thumbnail, UnlocalizedText,
get_live_chat::{Action, ChatItem, MessageRendererBase}
}
};
use self::{
Expand Down
35 changes: 16 additions & 19 deletions src/youtube/signaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
use std::{collections::HashMap, io::BufRead, iter};

use rand::Rng;
use reqwest::{header, Response};
use reqwest::{Response, header};
use simd_json::{
base::{ValueAsContainer, ValueAsScalar},
OwnedValue
OwnedValue,
base::{ValueAsContainer, ValueAsScalar}
};
use url::Url;

use super::{util::SimdJsonResponseBody, Error};
use super::{Error, util::SimdJsonResponseBody};

const GCM_SIGNALER_SRQE: &str = "https://signaler-pa.youtube.com/punctual/v1/chooseServer";
const GCM_SIGNALER_PSUB: &str = "https://signaler-pa.youtube.com/punctual/multi-watch/channel";
Expand Down Expand Up @@ -135,21 +135,18 @@ impl SignalerChannelInner {

pub async fn get_session_stream(&self) -> Result<Response, Error> {
Ok(super::get_http_client()
.get(Url::parse_with_params(
GCM_SIGNALER_PSUB,
[
("VER", "8"),
("gsessionid", self.gsessionid.as_ref().unwrap()),
("key", &self.tango_key),
("RID", "rpc"),
("SID", self.sid.as_ref().unwrap()),
("AID", &self.aid.to_string()),
("CI", "0"),
("TYPE", "xmlhttp"),
("zx", &Self::gen_zx()),
("t", "1")
]
)?)
.get(Url::parse_with_params(GCM_SIGNALER_PSUB, [
("VER", "8"),
("gsessionid", self.gsessionid.as_ref().unwrap()),
("key", &self.tango_key),
("RID", "rpc"),
("SID", self.sid.as_ref().unwrap()),
("AID", &self.aid.to_string()),
("CI", "0"),
("TYPE", "xmlhttp"),
("zx", &Self::gen_zx()),
("t", "1")
])?)
.header(header::CONNECTION, "keep-alive")
.send()
.await?)
Expand Down
15 changes: 7 additions & 8 deletions src/youtube/types/get_live_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ use serde_aux::prelude::*;
use simd_json::{base::ValueAsContainer, derived::ValueObjectAccessAsScalar};

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (macos-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (macos-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`

Check warning on line 18 in src/youtube/types/get_live_chat.rs

View workflow job for this annotation

GitHub Actions / Build and test (macos-latest, stable)

unused imports: `base::ValueAsContainer` and `derived::ValueObjectAccessAsScalar`
use url::Url;

use super::{deserialize_datetime_utc_from_microseconds, Accessibility, CommandMetadata, Icon, ImageContainer, LocalizedText, UnlocalizedText};
use super::{Accessibility, CommandMetadata, Icon, ImageContainer, LocalizedText, UnlocalizedText, deserialize_datetime_utc_from_microseconds};
use crate::youtube::{
get_http_client,
util::{SimdJsonRequestBody, SimdJsonResponseBody},
ChatContext, Error, TANGO_LIVE_ENDPOINT, TANGO_REPLAY_ENDPOINT
ChatContext, Error, TANGO_LIVE_ENDPOINT, TANGO_REPLAY_ENDPOINT, get_http_client,
util::{SimdJsonRequestBody, SimdJsonResponseBody}
};

#[derive(Serialize, Debug)]
Expand Down Expand Up @@ -68,10 +67,10 @@ impl GetLiveChatResponse {
pub async fn fetch(options: &ChatContext, continuation: impl AsRef<str>) -> Result<Self, Error> {
let body = GetLiveChatRequestBody::new(continuation.as_ref(), &options.client_version, "WEB");
Ok(get_http_client()
.post(Url::parse_with_params(
if options.live_status.updates_live() { TANGO_LIVE_ENDPOINT } else { TANGO_REPLAY_ENDPOINT },
[("key", options.api_key.as_str()), ("prettyPrint", "false")]
)?)
.post(Url::parse_with_params(if options.live_status.updates_live() { TANGO_LIVE_ENDPOINT } else { TANGO_REPLAY_ENDPOINT }, [
("key", options.api_key.as_str()),
("prettyPrint", "false")
])?)
.simd_json(&body)?
.send()
.await?
Expand Down
2 changes: 1 addition & 1 deletion src/youtube/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use serde::{de::Error, Deserialize, Deserializer};
use serde::{Deserialize, Deserializer, de::Error};
use serde_aux::field_attributes::deserialize_number_from_string;
use simd_json::OwnedValue;

Expand Down
2 changes: 1 addition & 1 deletion src/youtube/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::future::Future;

use reqwest::{RequestBuilder, Response};
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};

use super::Error;

Expand Down

0 comments on commit 0fc2624

Please sign in to comment.