@@ -95,7 +95,20 @@ impl Playbot {
95
95
/// Parse a command sent to playbot (playbot's name needs to be stripped beforehand)
96
96
///
97
97
/// 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
+
99
112
let code = if self . conn . current_nickname ( ) . contains ( "mini" ) {
100
113
String :: from ( code)
101
114
} else {
@@ -111,10 +124,10 @@ fn main() {{
111
124
{code}
112
125
}});
113
126
}}
114
- "# , version = self . rust_versions[ DEFAULT_CHANNEL as usize ] , code = code)
127
+ "# , version = self . rust_versions[ channel as usize ] , code = code)
115
128
} ;
116
129
117
- let out = try!( self . run_code ( & code, DEFAULT_CHANNEL ) ) ;
130
+ let out = try!( self . run_code ( & code, channel ) ) ;
118
131
if out. len ( ) > 5000 {
119
132
return Ok ( String :: from ( "output too long, bailing out :(" ) ) ;
120
133
}
@@ -166,7 +179,7 @@ fn main() {{
166
179
return ;
167
180
}
168
181
169
- let command = & msg[ 1 ..] ;
182
+ let command = msg[ 1 ..] . trim ( ) ;
170
183
info ! ( "{}: <{}> {}" , chan, from, command) ;
171
184
self . handle_cmd ( chan, command) ;
172
185
}
0 commit comments