diff options
author | jan <jan@ruken.pw> | 2016-04-07 12:30:25 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-04-07 12:30:25 (UTC) |
commit | 0720a83bcdc22684c68759755afb007579e0ebcc (patch) | |
tree | 694c75acc0a565d634a4d6066ce74dd5000bdeed /src | |
parent | 314047dda73387fff1fd4ccdb35f5db6ea6d7d5a (diff) |
keine warnings beim compilen mehr. Jisoku kann jetzt auch mehrfach verwendet werden anstatt fuer die Ewigkeit geblockt zu sein.
Diffstat (limited to 'src')
-rw-r--r-- | src/feature/jisoku.rs | 25 | ||||
-rw-r--r-- | src/feature/mod.rs | 1 | ||||
-rw-r--r-- | src/feature/tasterank.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 2 |
4 files changed, 20 insertions, 13 deletions
diff --git a/src/feature/jisoku.rs b/src/feature/jisoku.rs index 70bc886..8f88e81 100644 --- a/src/feature/jisoku.rs +++ b/src/feature/jisoku.rs | |||
@@ -1,16 +1,15 @@ | |||
1 | extern crate telegram_bot; | 1 | extern crate telegram_bot; |
2 | use telegram_bot::{Api, Message, MessageType}; | 2 | use telegram_bot::{Api, Message, MessageType}; |
3 | use std::sync::{Arc, Mutex}; | ||
4 | use std::thread; | 3 | use std::thread; |
5 | use std::time::Duration; | 4 | use std::time::Duration; |
6 | 5 | use std::sync::Arc; | |
7 | use std::ascii::AsciiExt; | 6 | use std::sync::atomic::{AtomicBool, Ordering}; |
8 | 7 | ||
9 | use feature::FeatureResult; | 8 | use feature::FeatureResult; |
10 | use feature::Feature; | 9 | use feature::Feature; |
11 | 10 | ||
12 | pub struct Jisoku { | 11 | pub struct Jisoku { |
13 | running: bool, | 12 | running: Arc<AtomicBool>, |
14 | } | 13 | } |
15 | 14 | ||
16 | const MESSAGES: [&'static str; 5] = ["JISOKU METER FURIKIRI UBAU GAME", | 15 | const MESSAGES: [&'static str; 5] = ["JISOKU METER FURIKIRI UBAU GAME", |
@@ -33,15 +32,24 @@ impl Feature for Jisoku { | |||
33 | return Ok(FeatureResult::Skip); | 32 | return Ok(FeatureResult::Skip); |
34 | } | 33 | } |
35 | 34 | ||
36 | if self.running { | 35 | if self.running.compare_and_swap(false, true, Ordering::SeqCst) { |
37 | return Ok(FeatureResult::Skip); | 36 | return Ok(FeatureResult::Skip); |
38 | } | 37 | } |
39 | self.running = true; | 38 | let running = self.running.clone(); |
40 | thread::spawn(move || { | 39 | thread::spawn(move || { |
41 | for s in MESSAGES.into_iter() { | 40 | for s in MESSAGES.into_iter() { |
42 | a.send_message(m.chat.id(), (*s).to_owned(), None, None, None, None); | 41 | if let Err(e) = a.send_message(m.chat.id(), |
42 | (*s).to_owned(), | ||
43 | None, | ||
44 | None, | ||
45 | None, | ||
46 | None) { | ||
47 | println!("{}", e); | ||
48 | break; | ||
49 | }; | ||
43 | thread::sleep(Duration::new(1, 0)); | 50 | thread::sleep(Duration::new(1, 0)); |
44 | } | 51 | } |
52 | running.store(false, Ordering::SeqCst); | ||
45 | }); | 53 | }); |
46 | Ok(FeatureResult::Handled) | 54 | Ok(FeatureResult::Handled) |
47 | } | 55 | } |
@@ -49,7 +57,6 @@ impl Feature for Jisoku { | |||
49 | 57 | ||
50 | impl Jisoku { | 58 | impl Jisoku { |
51 | pub fn new() -> Jisoku { | 59 | pub fn new() -> Jisoku { |
52 | let mut j = Jisoku { running: false }; | 60 | Jisoku { running: Arc::new(AtomicBool::new(false)) } |
53 | j | ||
54 | } | 61 | } |
55 | } | 62 | } |
diff --git a/src/feature/mod.rs b/src/feature/mod.rs index 5e00620..a52bb2c 100644 --- a/src/feature/mod.rs +++ b/src/feature/mod.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | use std::boxed::Box; | 1 | use std::boxed::Box; |
2 | use std::error::Error; | ||
3 | 2 | ||
4 | extern crate telegram_bot; | 3 | extern crate telegram_bot; |
5 | use telegram_bot::{Api, Message}; | 4 | use telegram_bot::{Api, Message}; |
diff --git a/src/feature/tasterank.rs b/src/feature/tasterank.rs index c4a29f9..13730e1 100644 --- a/src/feature/tasterank.rs +++ b/src/feature/tasterank.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | use std::option::Option; | ||
2 | use std::io; | 1 | use std::io; |
3 | use std::io::prelude::*; | 2 | use std::io::prelude::*; |
4 | use std::fs::File; | 3 | use std::fs::File; |
@@ -33,7 +32,9 @@ impl Feature for Tasterank { | |||
33 | for (i, rank) in self.ranks.iter().enumerate() { | 32 | for (i, rank) in self.ranks.iter().enumerate() { |
34 | msg.push_str(&format!("{}. {}\n", i + 1, rank)); | 33 | msg.push_str(&format!("{}. {}\n", i + 1, rank)); |
35 | } | 34 | } |
36 | a.send_message(m.chat.id(), msg, None, None, Some(m.message_id), None); | 35 | if let Err(e) = a.send_message(m.chat.id(), msg, None, None, Some(m.message_id), None) { |
36 | println!("{}", e); | ||
37 | } | ||
37 | return Ok(FeatureResult::Handled); | 38 | return Ok(FeatureResult::Handled); |
38 | } | 39 | } |
39 | Ok(FeatureResult::Skip) | 40 | Ok(FeatureResult::Skip) |
diff --git a/src/main.rs b/src/main.rs index eaec1f4..ef5c8e8 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | extern crate telegram_bot; | 1 | extern crate telegram_bot; |
2 | use telegram_bot::{Api, ListeningMethod, ListeningAction, Update}; | 2 | use telegram_bot::{Api, ListeningMethod, ListeningAction}; |
3 | 3 | ||
4 | mod feature; | 4 | mod feature; |
5 | use feature::{Feature, FeatureResult}; | 5 | use feature::{Feature, FeatureResult}; |