Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
.vscode

.DS_Store
.direnv
.env
5 changes: 5 additions & 0 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 src/discord/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ impl Channel for DiscordChannel {
fn get_receiver(&self) -> broadcast::Receiver<Self::Message> {
self.receiver.resubscribe()
}
}
}
34 changes: 22 additions & 12 deletions src/discord/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
use std::{collections::HashMap, rc::Rc, sync::Arc};

use serenity::{all::{Context, EventHandler, GatewayIntents, Message}, async_trait, futures::SinkExt};
use serenity::{
all::{Context, EventHandler, GatewayIntents, Message},
async_trait,
futures::SinkExt,
};
use tokio::sync::{broadcast, Mutex, RwLock};

use crate::{message::{author::{DiscordMessageAuthor, DisplayName}, content::DiscordMessageContent, DiscordMessage}, snowflake::{self, Snowflake}};
use crate::{
message::{
author::{DiscordMessageAuthor, DisplayName},
content::DiscordMessageContent,
DiscordMessage,
},
snowflake::{self, Snowflake},
};

#[derive(Default)]
pub struct DiscordClient {
channel_message_event_handlers: HashMap<Snowflake, Vec<broadcast::Sender<DiscordMessage>>>
channel_message_event_handlers: HashMap<Snowflake, Vec<broadcast::Sender<DiscordMessage>>>,
}

impl DiscordClient {
Expand All @@ -16,10 +27,7 @@ impl DiscordClient {
let remote = RemoteDiscordClient(client.clone());

tokio::spawn(async {
let mut client = serenity::Client::builder(token, GatewayIntents::all())
.event_handler(remote)
.await
.expect("Error creating client");
let mut client = serenity::Client::builder(token, GatewayIntents::all()).event_handler(remote).await.expect("Error creating client");

if let Err(why) = client.start().await {
panic!("Client error: {why:?}");
Expand All @@ -45,7 +53,9 @@ impl EventHandler for RemoteDiscordClient {
async fn message(&self, _: Context, msg: Message) {
println!("Got message: {:?} {:?}", msg.channel_id, msg.content);

let snowflake = Snowflake { content: msg.channel_id.get() };
let snowflake = Snowflake {
content: msg.channel_id.get(),
};

if let Some(vec) = self.0.read().await.channel_message_event_handlers.get(&snowflake) {
for sender in vec {
Expand All @@ -55,13 +65,13 @@ impl EventHandler for RemoteDiscordClient {
id: snowflake,
author: DiscordMessageAuthor {
display_name: DisplayName(msg.author.name.clone()),
icon: msg.author.avatar_url().unwrap_or(msg.author.default_avatar_url())
icon: msg.author.avatar_url().unwrap_or(msg.author.default_avatar_url()),
},
content: DiscordMessageContent {
content: msg.content.clone()
}
content: msg.content.clone(),
},
});
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/discord/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod message;
pub mod snowflake;
pub mod channel;
pub mod client;
pub mod message;
pub mod snowflake;
2 changes: 1 addition & 1 deletion src/discord/src/message/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ impl RenderOnce for DisplayName {
fn render(self, _: &mut WindowContext) -> impl IntoElement {
div().text_sm().child(self.0)
}
}
}
2 changes: 1 addition & 1 deletion src/discord/src/message/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ impl RenderOnce for DiscordMessageContent {
fn render(self, _: &mut WindowContext) -> impl IntoElement {
self.content.clone()
}
}
}
3 changes: 1 addition & 2 deletions src/discord/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use scope_chat::message::Message;

use crate::snowflake::Snowflake;

pub mod content;
pub mod author;
pub mod content;

#[derive(Clone)]
pub struct DiscordMessage {
Expand All @@ -28,4 +28,3 @@ impl Message for DiscordMessage {
self.id.to_string()
}
}

4 changes: 2 additions & 2 deletions src/discord/src/snowflake.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[derive(Clone, Hash, PartialEq, Eq, Copy)]
pub struct Snowflake {
pub content: u64
pub content: u64,
}

impl ToString for Snowflake {
fn to_string(&self) -> String {
self.content.to_string()
}
}
}
10 changes: 7 additions & 3 deletions src/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "scope"
version = "0.1.0"
edition = "2021"
authors = [
"Rose Kodsi-Hall <rose@hall.ly>"
"Rose Kodsi-Hall <rose@hall.ly>",
# Add yourself here if you contribute!
]
description = "discord client for power users"
Expand All @@ -13,9 +13,13 @@ repository = "https://github.com/scopeclient/scope"
keywords = ["discord", "scope", "reticle"]

[dependencies]
gpui = { git = "https://github.com/zed-industries/zed.git", version = "0.1.0", default-features = false, features = ["http_client", "font-kit"]}
reqwest_client = { git = "https://github.com/zed-industries/zed.git", version = "0.1.0"}
gpui = { git = "https://github.com/zed-industries/zed.git", version = "0.1.0", default-features = false, features = [
"http_client",
"font-kit",
] }
reqwest_client = { git = "https://github.com/zed-industries/zed.git", version = "0.1.0" }
scope-chat = { version = "0.1.0", path = "../chat" }
scope-util = { version = "0.1.0", path = "../util" }
scope-backend-discord = { version = "0.1.0", path = "../discord" }
dotenv = "0.15.0"
env_logger = "0.11.5"
Expand Down
Loading