equal
deleted
inserted
replaced
1 use crate::{ |
1 use crate::{ |
|
2 protocol::messages::{ |
|
3 HWProtocolMessage::{self, Rnd}, |
|
4 HWServerMessage::{self, ChatMsg}, |
|
5 }, |
2 server::{actions::Action, core::HWServer}, |
6 server::{actions::Action, core::HWServer}, |
3 protocol::messages::{ |
|
4 HWProtocolMessage::{self, Rnd}, HWServerMessage::{self, ChatMsg}, |
|
5 } |
|
6 }; |
7 }; |
7 use rand::{self, Rng, thread_rng}; |
8 use rand::{self, thread_rng, Rng}; |
8 |
9 |
9 pub fn rnd_reply(options: &[String]) -> HWServerMessage { |
10 pub fn rnd_reply(options: &[String]) -> HWServerMessage { |
10 let mut rng = thread_rng(); |
11 let mut rng = thread_rng(); |
11 let reply = if options.is_empty() { |
12 let reply = if options.is_empty() { |
12 (*rng.choose(&["heads", "tails"]).unwrap()).to_owned() |
13 (*rng.choose(&["heads", "tails"]).unwrap()).to_owned() |
23 #[cfg(test)] |
24 #[cfg(test)] |
24 mod tests { |
25 mod tests { |
25 use super::*; |
26 use super::*; |
26 use crate::protocol::messages::HWServerMessage::ChatMsg; |
27 use crate::protocol::messages::HWServerMessage::ChatMsg; |
27 use crate::server::actions::{ |
28 use crate::server::actions::{ |
28 Action::{self, Send}, PendingMessage, |
29 Action::{self, Send}, |
|
30 PendingMessage, |
29 }; |
31 }; |
30 |
32 |
31 fn reply2string(r: HWServerMessage) -> String { |
33 fn reply2string(r: HWServerMessage) -> String { |
32 match r { |
34 match r { |
33 ChatMsg { msg: p, .. } => String::from(p), |
35 ChatMsg { msg: p, .. } => String::from(p), |