Using discord uuids as player ids and fixed issue with add_time

msg_refactor
Joey Hines 2022-03-15 18:29:06 -06:00
parent 935e0bb3f3
commit 5dd1b5daa7
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
2 changed files with 6 additions and 4 deletions

View File

@ -270,8 +270,6 @@ async fn add_time(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
let mut global_data = global_data.lock().await;
global_data.game_state.next_phase();
let duration = match args.single::<u64>() {
Ok(d) => d,
Err(_) => {
@ -352,7 +350,7 @@ async fn vote(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
.game_state
.get_player_from_channel_mut(msg.channel_id.0)
.unwrap();
player_data.vote_target = Some(target_player.channel);
player_data.vote_target = Some(target_player.discord_id);
vote_channel
.send_message(&ctx.http, |m| {

View File

@ -98,6 +98,10 @@ impl GameState {
self.player_data.iter().find(|p| p.channel == channel_id)
}
pub fn get_player_from_discord_id(&self, discord_id: u64) -> Option<&PlayerData> {
self.player_data.iter().find(|p| p.discord_id == discord_id)
}
pub fn get_player_from_channel_mut(&mut self, channel_id: u64) -> Option<&mut PlayerData> {
self.player_data
.iter_mut()
@ -141,7 +145,7 @@ impl GameState {
for player in &self.player_data {
if let Some(vote_target) = player.vote_target {
let target = self.get_player_from_channel(vote_target);
let target = self.get_player_from_discord_id(vote_target);
if let Some(target) = target {
*vote_set.entry(target.codename.clone()).or_insert(0) += 1;
}