Skip to content

Commit

Permalink
Fix how prefixes work
Browse files Browse the repository at this point in the history
Reference prefixes portion at bdashore3/CourtJester@c651a26

Signed-off-by: kingbri <bdashore3@gmail.com>
  • Loading branch information
bdashore3 committed Sep 17, 2020
1 parent 899794d commit fa3925a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {

#[hook]
async fn dynamic_prefix(ctx: &Context, msg: &Message) -> Option<String> {
let prefixes = ctx.data.read().await
.get::<PrefixMap>().cloned().unwrap();
let guild_id = msg.guild_id.unwrap();
let (prefixes, default_prefix) = {
let data = ctx.data.read().await;
let prefixes = data.get::<PrefixMap>().cloned().unwrap();
let default_prefix = data.get::<PubCreds>().unwrap()
.get("default prefix").cloned().unwrap();

(prefixes, default_prefix)
};

let guild_id = msg.guild_id.unwrap();

match prefixes.get(&guild_id) {
Some(prefix_guard) => Some(prefix_guard.value().to_owned()),
None => None
None => Some(default_prefix)
}
}

let prefix = pub_creds.get("default prefix").unwrap();

// Link everything together!
let framework = StandardFramework::new()
.configure(|c| c
.prefix(prefix)
.dynamic_prefix(dynamic_prefix)
.on_mention(Some(bot_id))
.owners(owners)
Expand Down

0 comments on commit fa3925a

Please sign in to comment.