mirror of
https://codeberg.org/JasterV/gofish_bot.git
synced 2026-04-26 18:10:09 +00:00
bugfix
This commit is contained in:
parent
906c8997c6
commit
b3254deef9
3 changed files with 18 additions and 28 deletions
|
|
@ -64,10 +64,9 @@ impl GameActor {
|
|||
}
|
||||
|
||||
pub fn is_over(&self) -> bool {
|
||||
if let GameState::GameOver(_) = self.game.state {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
match self.game.state {
|
||||
GameState::GameOver(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,18 +80,11 @@ impl GameActor {
|
|||
|
||||
async fn join(&mut self, cx: &Cx) -> Result<()> {
|
||||
let user = cx.update.from().unwrap();
|
||||
|
||||
self.game.execute(Action::Join(
|
||||
user.id.clone().to_string(),
|
||||
user.first_name.clone(),
|
||||
))?;
|
||||
|
||||
cx.answer(format!(
|
||||
"Hi {}, welcome to Go Fish!",
|
||||
user.first_name.clone()
|
||||
))
|
||||
.await?;
|
||||
|
||||
cx.answer(welcome(&user.first_name)).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -137,21 +129,17 @@ impl GameActor {
|
|||
.game
|
||||
.execute(Action::Draw(format!("{}", from.id), card as u8))?;
|
||||
for event in events {
|
||||
match event {
|
||||
TurnEvent::Drawn(drawn) => {
|
||||
cx.answer(drawn_card(&from.first_name)).await?;
|
||||
if drawn == (card as u8) {
|
||||
cx.answer(drawn_expected_card(&from.first_name, drawn))
|
||||
.await?;
|
||||
}
|
||||
let msg = match event {
|
||||
TurnEvent::Drawn(drawn) if drawn == (card as u8) => {
|
||||
Some(drawn_expected_card(&from.first_name, drawn))
|
||||
}
|
||||
TurnEvent::DeckEmpty => {
|
||||
cx.answer(EMPTY_DECK).await?;
|
||||
}
|
||||
TurnEvent::Group(card) => {
|
||||
cx.answer(made_group(&from.first_name, card)).await?;
|
||||
}
|
||||
_ => {}
|
||||
TurnEvent::Drawn(_) => Some(drawn_card(&from.first_name)),
|
||||
TurnEvent::DeckEmpty => Some(EMPTY_DECK.into()),
|
||||
TurnEvent::Group(card) => Some(made_group(&from.first_name, card)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(msg) = msg {
|
||||
cx.answer(msg).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -185,8 +185,6 @@ impl Game {
|
|||
winners: winners.iter().map(|p| p.name.clone()).collect(),
|
||||
score: winners[0].score,
|
||||
});
|
||||
self.deck = Deck::new();
|
||||
self.players = vec![]
|
||||
}
|
||||
|
||||
fn has_started(&self) -> bool {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ pub const ALREADY_JOINED: &'static str = "You have already joined!";
|
|||
pub const EMPTY_DECK: &'static str = "The deck is empty!!!";
|
||||
pub const UNKNOWN_ERROR: &'static str = "An error sending a message occurred!\n\nMake sure that all game participants have started the bot on their private chats to receive your cards!!\n\nOtherwise, open an issue to: https://github.com/JasterV/gofish_bot";
|
||||
|
||||
pub fn welcome(name: &str) -> String {
|
||||
format!("Hi {}, welcome to Go Fish!", name)
|
||||
}
|
||||
|
||||
pub fn no_cards(name: &str) -> String {
|
||||
format!("{} had no cards with that number, lets draw!", name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue