Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Dev changes into main #428

Merged
merged 10 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ thiserror = "1.0.47"
jsonwebtoken = "8.3.0"
log = "0.4.20"
async-trait = "0.1.73"
chorus-macros = { path = "chorus-macros", version = "0.1.0" }
chorus-macros = "0.2.0"

[dev-dependencies]
tokio = { version = "1.32.0", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion chorus-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chorus-macros"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
license = "AGPL-3.0"
description = "Macros for the chorus crate."
Expand Down
19 changes: 19 additions & 0 deletions chorus-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ pub fn jsonfield_macro_derive(input: TokenStream) -> TokenStream {
.into()
}

#[proc_macro_derive(SourceUrlField)]
pub fn source_url_macro_derive(input: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(input).unwrap();

let name = &ast.ident;
// No need for macro hygiene, we're only using this in chorus
quote! {
impl SourceUrlField for #name {
fn get_source_url(&self) -> String {
self.source_url.clone()
}
fn set_source_url(&mut self, url: String) {
self.source_url = url;
}
}
}
.into()
}

#[proc_macro_attribute]
pub fn observe_option(_args: TokenStream, input: TokenStream) -> TokenStream {
input
Expand Down
7 changes: 5 additions & 2 deletions src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::gateway::events::Events;
use crate::types::{
self, AutoModerationRule, AutoModerationRuleUpdate, Channel, ChannelCreate, ChannelDelete,
ChannelUpdate, Composite, Guild, GuildRoleCreate, GuildRoleUpdate, JsonField, RoleObject,
Snowflake, ThreadUpdate, UpdateMessage, WebSocketEvent,
Snowflake, SourceUrlField, ThreadUpdate, UpdateMessage, WebSocketEvent,
};
use async_trait::async_trait;
use std::any::Any;
Expand Down Expand Up @@ -343,6 +343,7 @@ pub struct Gateway {
websocket_receive: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
kill_send: tokio::sync::broadcast::Sender<()>,
store: Arc<Mutex<HashMap<Snowflake, Arc<RwLock<ObservableObject>>>>>,
url: String,
}

impl Gateway {
Expand Down Expand Up @@ -406,6 +407,7 @@ impl Gateway {
websocket_receive,
kill_send: kill_send.clone(),
store: store.clone(),
url: websocket_url.clone(),
};

// Now we can continuously check for messages in a different task, since we aren't going to receive another hello
Expand Down Expand Up @@ -534,6 +536,7 @@ impl Gateway {
let downcasted = unsafe { Arc::from_raw(ptr as *const RwLock<$update_type>).clone() };
drop(inner_object);
message.set_json(json.to_string());
message.set_source_url(self.url.clone());
message.update(downcasted.clone());
} else {
warn!("Received {} for {}, but it has been observed to be a different type!", $name, id)
Expand Down Expand Up @@ -914,7 +917,7 @@ impl<T: WebSocketEvent> GatewayEvent<T> {
}
}

mod events {
pub mod events {
use super::*;

#[derive(Default, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::types::types::subconfigs::limits::rates::RateLimits;
use crate::types::{GeneralConfiguration, Limit, LimitType, User, UserSettings};
use crate::UrlBundle;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
/// The [`Instance`]; what you will be using to perform all sorts of actions on the Spacebar server.
/// If `limits_information` is `None`, then the instance will not be rate limited.
pub struct Instance {
Expand All @@ -25,7 +25,7 @@ pub struct Instance {
pub client: Client,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct LimitsInformation {
pub ratelimits: HashMap<LimitType, Limit>,
pub configuration: RateLimits,
Expand Down
Loading
Loading