Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 4b4a81d

Browse files
authored
Merge pull request #236 from programble/feature/playbot-channel
Playbot: parse --nightly, etc. playbot message prefix
2 parents d83db57 + 72f4678 commit 4b4a81d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/bin/playbot.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,20 @@ impl Playbot {
9595
/// Parse a command sent to playbot (playbot's name needs to be stripped beforehand)
9696
///
9797
/// Returns the response to send to the user (each line is a NOTICE)
98-
fn parse_and_run(&mut self, code: &str) -> io::Result<String> {
98+
fn parse_and_run(&mut self, mut code: &str) -> io::Result<String> {
99+
let mut channel = DEFAULT_CHANNEL;
100+
101+
if code.starts_with("--") {
102+
let mut parts = code.splitn(2, ' ');
103+
match parts.next() {
104+
Some("--stable") => { channel = ReleaseChannel::Stable },
105+
Some("--beta") => { channel = ReleaseChannel::Beta },
106+
Some("--nightly") => { channel = ReleaseChannel::Nightly },
107+
_ => return Ok(String::from("unrecognized release channel")),
108+
}
109+
code = parts.next().unwrap_or("");
110+
}
111+
99112
let code = if self.conn.current_nickname().contains("mini") {
100113
String::from(code)
101114
} else {
@@ -111,10 +124,10 @@ fn main() {{
111124
{code}
112125
}});
113126
}}
114-
"#, version = self.rust_versions[DEFAULT_CHANNEL as usize], code = code)
127+
"#, version = self.rust_versions[channel as usize], code = code)
115128
};
116129

117-
let out = try!(self.run_code(&code, DEFAULT_CHANNEL));
130+
let out = try!(self.run_code(&code, channel));
118131
if out.len() > 5000 {
119132
return Ok(String::from("output too long, bailing out :("));
120133
}
@@ -166,7 +179,7 @@ fn main() {{
166179
return;
167180
}
168181

169-
let command = &msg[1..];
182+
let command = msg[1..].trim();
170183
info!("{}: <{}> {}", chan, from, command);
171184
self.handle_cmd(chan, command);
172185
}

0 commit comments

Comments
 (0)