Skip to content

Commit

Permalink
Add an is_new to the arguments of the guild_create handler
Browse files Browse the repository at this point in the history
To make a better distinction from a guild that the bot's already in and from the ones it's joining
  • Loading branch information
arqunis committed Jul 5, 2017
1 parent fbc1ac7 commit 3017f6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ fn handle_event<H: EventHandler + Send + Sync + 'static>(event: Event,
thread::spawn(move || h.on_guild_ban_removal(context, event.guild_id, event.user));
},
Event::GuildCreate(event) => {
#[cfg(feature="cache")]
let _is_new = {
let cache = CACHE.read().unwrap();

!cache.unavailable_guilds.contains(&event.guild.id)
};

update!(update_with_guild_create, event);

#[cfg(feature="cache")]
Expand All @@ -285,7 +292,11 @@ fn handle_event<H: EventHandler + Send + Sync + 'static>(event: Event,
let context = context(conn, data);

let h = event_handler.clone();
thread::spawn(move || h.on_guild_create(context, event.guild));
feature_cache! {{
thread::spawn(move || h.on_guild_create(context, event.guild, _is_new));
} else {
thread::spawn(move || h.on_guild_create(context, event.guild));
}}
},
Event::GuildDelete(event) => {
let _full = update!(update_with_guild_delete, event);
Expand Down
4 changes: 3 additions & 1 deletion src/client/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use ::model::*;
#[cfg(feature="cache")]
use std::sync::RwLock;

#[allow(type_complexity)]
pub trait EventHandler {
#[cfg(feature="cache")]
fn on_cached(&self, _: Context, _: Vec<GuildId>) {}
Expand All @@ -23,6 +22,9 @@ pub trait EventHandler {
fn on_channel_update(&self, _: Context, _: Channel) {}
fn on_guild_ban_addition(&self, _: Context, _: GuildId, _: User) {}
fn on_guild_ban_removal(&self, _: Context, _: GuildId, _: User) {}
#[cfg(feature="cache")]
fn on_guild_create(&self, _: Context, _: Guild, _: bool) {}
#[cfg(not(feature="cache"))]
fn on_guild_create(&self, _: Context, _: Guild) {}
#[cfg(feature="cache")]
fn on_guild_delete(&self, _: Context, _: PartialGuild, _: Option<Arc<RwLock<Guild>>>) {}
Expand Down

0 comments on commit 3017f6d

Please sign in to comment.