-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* functionality for getting the vote status * backbone for reaction event handling * ability to convert ReactionType to SimpleEmoji * add list_for_channel to StarboardConfig * cache channel nsfws * Put guild emojis inside CachedGuild struct * create async-safe wrappers for DashMap/DashSet * fix constant name * progress for reaction handling * Add `contains_key` to AsyndDashMap * more progress for creating votes on reaction_add * formatting * user caching * finish logic for vote creation * actually get the channels nsfw info * don't cache channel nsfw info * implement vote removal * unused import * VoteStatus takes ownership of configs * send messages to starboard 🎉 * send the points rather than "hello" * edit the original if it exists
- Loading branch information
1 parent
95d999b
commit 6ecb946
Showing
29 changed files
with
1,366 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
use async_trait::async_trait; | ||
use dashmap::DashSet; | ||
use twilight_model::gateway::payload::incoming::{GuildCreate, GuildDelete, GuildEmojisUpdate}; | ||
|
||
use crate::cache::{cache::Cache, update::UpdateCache}; | ||
use crate::cache::{cache::Cache, models::guild::CachedGuild, update::UpdateCache}; | ||
|
||
#[async_trait] | ||
impl UpdateCache for GuildCreate { | ||
async fn update_cache(&self, cache: &Cache) { | ||
// update emojis | ||
cache | ||
.guild_emojis | ||
.insert(self.id, self.emojis.iter().map(|e| e.id).collect()); | ||
let guild = CachedGuild { | ||
emojis: self | ||
.emojis | ||
.iter() | ||
.map(|e| e.id) | ||
.collect::<DashSet<_>>() | ||
.into(), | ||
}; | ||
cache.guilds.insert(self.id, guild); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl UpdateCache for GuildDelete { | ||
async fn update_cache(&self, cache: &Cache) { | ||
// delete emojis | ||
cache.guild_emojis.remove(&self.id); | ||
cache.guilds.remove(&self.id); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl UpdateCache for GuildEmojisUpdate { | ||
async fn update_cache(&self, cache: &Cache) { | ||
cache | ||
.guild_emojis | ||
.insert(self.guild_id, self.emojis.iter().map(|e| e.id).collect()); | ||
cache.guilds.alter(&self.guild_id, |_, guild| { | ||
for emoji in &self.emojis { | ||
guild.emojis.insert(emoji.id); | ||
} | ||
guild | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use async_trait::async_trait; | ||
use twilight_model::gateway::payload::incoming::{MemberAdd, MemberChunk}; | ||
|
||
use crate::cache::{cache::Cache, update::UpdateCache}; | ||
|
||
#[async_trait] | ||
impl UpdateCache for MemberChunk { | ||
async fn update_cache(&self, cache: &Cache) { | ||
for member in &self.members { | ||
cache.users.insert(member.user.id, (&member.user).into()); | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl UpdateCache for MemberAdd { | ||
async fn update_cache(&self, cache: &Cache) { | ||
cache.users.insert(self.user.id, (&self.user).into()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod guild; | ||
pub mod member; | ||
pub mod message; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use twilight_model::id::{marker::EmojiMarker, Id}; | ||
|
||
use crate::utils::async_dash::AsyncDashSet; | ||
|
||
pub struct CachedGuild { | ||
pub emojis: AsyncDashSet<Id<EmojiMarker>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
use twilight_model::channel::{embed::Embed, Attachment}; | ||
use twilight_model::{ | ||
channel::{embed::Embed, Attachment, Message}, | ||
id::{marker::UserMarker, Id}, | ||
}; | ||
|
||
pub struct CachedMessage { | ||
pub author_id: Id<UserMarker>, | ||
pub attachments: Vec<Attachment>, | ||
pub embeds: Vec<Embed>, | ||
} | ||
|
||
impl From<Message> for CachedMessage { | ||
fn from(msg: Message) -> Self { | ||
Self { | ||
author_id: msg.author.id, | ||
attachments: msg.attachments, | ||
embeds: msg.embeds, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
pub mod guild; | ||
pub mod message; | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use twilight_model::user::User; | ||
|
||
pub struct CachedUser { | ||
pub is_bot: bool, | ||
} | ||
|
||
impl From<&User> for CachedUser { | ||
fn from(user: &User) -> Self { | ||
Self { is_bot: user.bot } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
use crate::core::starboard::config::StarboardConfig; | ||
|
||
pub struct Embedder { | ||
pub points: i16, | ||
pub config: StarboardConfig, | ||
pub struct Embedder<'config> { | ||
pub points: i32, | ||
pub config: &'config StarboardConfig, | ||
} | ||
|
||
impl<'config> Embedder<'config> { | ||
pub fn new(points: i32, config: &'config StarboardConfig) -> Self { | ||
Self { points, config } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.