| 159 # Substitute some mathematical constants |
167 # Substitute some mathematical constants |
| 160 expr = mathsubstitute (expr, 'pi' , 3.14159265358979323846264338327950288419716939937510) |
168 expr = mathsubstitute (expr, 'pi' , 3.14159265358979323846264338327950288419716939937510) |
| 161 expr = mathsubstitute (expr, 'e' , 2.71828182845904523536028747135266249775724709369995) |
169 expr = mathsubstitute (expr, 'e' , 2.71828182845904523536028747135266249775724709369995) |
| 162 expr = mathsubstitute (expr, 'phi', 1.6180339887498948482) # golden ratio |
170 expr = mathsubstitute (expr, 'phi', 1.6180339887498948482) # golden ratio |
| 163 |
171 |
| 164 result = subprocess.check_output (['calc', expr], stderr=subprocess.STDOUT) \ |
172 result = subprocess.check_output (['calc', '--', expr], stderr=subprocess.STDOUT) \ |
| 165 .replace ('\t', '') \ |
173 .replace ('\t', '') \ |
| 166 .replace ('\n', '') |
174 .replace ('\n', '') |
| 167 |
175 |
| 168 errmatch = re.compile (r'^.*\bError\b.*$').match (result) |
176 errmatch = re.compile (r'^.*\bError\b.*$').match (result) |
| 169 |
177 |
| 175 except subprocess.CalledProcessError as e: |
183 except subprocess.CalledProcessError as e: |
| 176 command_error (e.output.split('\n')[0]) |
184 command_error (e.output.split('\n')[0]) |
| 177 except OSError as e: |
185 except OSError as e: |
| 178 command_error ('failed to execute calc: ' + e.strerror) |
186 command_error ('failed to execute calc: ' + e.strerror) |
| 179 |
187 |
| 180 def cmd_more (bot, replyto, **rest): |
188 def cmd_more (commandObject, **rest): |
| 181 ModuleCore.print_responses (bot, replyto) |
189 ModuleCore.print_responses (commandObject) |
| 182 |
190 |
| 183 def cmd_yes (**k): |
191 def cmd_yes (**k): |
| 184 ModuleCore.confirm (k, True) |
192 ModuleCore.confirm (k, True) |
| 185 |
193 |
| 186 def cmd_no (**k): |
194 def cmd_no (**k): |
| 187 ModuleCore.confirm (k, False) |
195 ModuleCore.confirm (k, False) |
| |
196 |
| |
197 def cmd_bitly (reply, args, **k): |
| |
198 reply ('Result: %s' % utility.shorten_link (args['link'])) |