-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from DavidAmison/add_bot
Simple calculator bot
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sat Feb 4 15:56:52 2017 | ||
@author: David Amison | ||
""" | ||
import sympy as sp | ||
|
||
import telepot | ||
import telepot.aio | ||
from skybeard.decorators import onerror | ||
from skybeard.utils import get_args | ||
from skybeard.beards import BeardChatHandler | ||
from skybeard.predicates import regex_predicate | ||
|
||
class Calculator(BeardChatHandler): | ||
__userhelp__ = ''' | ||
A calculator for doing numerical mathematics (not algebraic) | ||
Functions: | ||
/calc 'equation' Calculates the answer to the equation input. The answer | ||
is output based on the current format chosen and can be changed | ||
using the /settings function | ||
''' | ||
|
||
__commands__ = [ | ||
('calc','calculate','Performs a calculation')] | ||
|
||
@onerror | ||
async def calculate(self, msg): | ||
|
||
#extract the equation input by the user | ||
equation = get_args(msg, return_string = True) | ||
|
||
await self.sender.sendMessage(equation) | ||
|
||
#solve the equation | ||
eq = sp.sympify(equation) | ||
result = eq.evalf(10) | ||
|
||
|
||
await self.sender.sendMessage(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sympy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from skybeard.utils import setup_beard | ||
|
||
setup_beard( | ||
"mathbeard", | ||
) |