Skip to content

Commit

Permalink
Merge pull request #87 from DavidAmison/add_bot
Browse files Browse the repository at this point in the history
Simple calculator bot
  • Loading branch information
LanceMaverick committed Feb 4, 2017
2 parents f92fd7e + 8dfdc66 commit 51815a2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
43 changes: 43 additions & 0 deletions beards/mathbeard/python/mathbeard/__init__.py
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)
1 change: 1 addition & 0 deletions beards/mathbeard/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sympy
5 changes: 5 additions & 0 deletions beards/mathbeard/setup_beard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from skybeard.utils import setup_beard

setup_beard(
"mathbeard",
)

0 comments on commit 51815a2

Please sign in to comment.