from typing import List
import requests
from telegram import Message, Update, Bot, MessageEntity
from telegram.ext import CommandHandler, run_async
from emilia import dispatcher
from emilia.modules.disable import DisableAbleCommandHandler
from emilia.modules.helper_funcs.alternate import send_message
import pynewtonmath as newton
import math
@run_async
def simplify(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.simplify('{}'.format(args[0])))

@run_async
def factor(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.factor('{}'.format(args[0])))

@run_async
def derive(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.derive('{}'.format(args[0])))

@run_async
def integrate(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.integrate('{}'.format(args[0])))

@run_async
def zeroes(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.zeroes('{}'.format(args[0])))

@run_async
def tangent(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.tangent('{}'.format(args[0])))

@run_async
def area(update, context):
    args=context.args
    args=str(args)
    message = update.effective_message
    message.reply_text(newton.area('{}'.format(args[0])))





@run_async
def cos(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.cos(int(args[0])))

@run_async
def sin(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.sin(int(args[0])))

@run_async
def tan(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.tan(int(args[0])))

@run_async
def arccos(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.acos(int(args[0])))

@run_async
def arcsin(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.asin(int(args[0])))

@run_async
def arctan(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.atan(int(args[0])))

@run_async
def abs(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.fabs(int(args[0])))

@run_async
def log(update, context):
    args = context.args
    message = update.effective_message
    message.reply_text(math.log(int(args[0])))

__help__ = """
Under Developmeent.. More features soon
 - /cos: Cosine `/cos pi`
 - /sin: Sine `/sin 0`
 - /tan: Tangent `/tan 0`
 - /arccos: Inverse Cosine `/arccos 1`
 - /arcsin: Inverse Sine `/arcsin 0`
 - /arctan: Inverse Tangent `/arctan 0`
 - /abs: Absolute Value `/abs -1`
 - /log: Logarithm `/log 2l8`
__Keep in mind__: To find the tangent line of a function at a certain x value, send the request as c|f(x) where c is the given x value and f(x) is the function expression, the separator is a vertical bar '|'. See the table above for an example request.
To find the area under a function, send the request as c:d|f(x) where c is the starting x value, d is the ending x value, and f(x) is the function under which you want the curve between the two x values.
To compute fractions, enter expressions as numerator(over)denominator. For example, to process 2/4 you must send in your expression as 2(over)4. The result expression will be in standard math notation (1/2, 3/4).
"""



SIMPLIFY_HANDLER = DisableAbleCommandHandler("math", simplify, pass_args=True)
FACTOR_HANDLER = DisableAbleCommandHandler("factor", factor, pass_args=True)
DERIVE_HANDLER = DisableAbleCommandHandler("derive", derive, pass_args=True)
INTEGRATE_HANDLER = DisableAbleCommandHandler("integrate", integrate, pass_args=True)
ZEROES_HANDLER = DisableAbleCommandHandler("zeroes", zeroes, pass_args=True)
TANGENT_HANDLER = DisableAbleCommandHandler("tangent", tangent, pass_args=True)
AREA_HANDLER = DisableAbleCommandHandler("area", area, pass_args=True)
COS_HANDLER = DisableAbleCommandHandler("cos", cos, pass_args=True)
SIN_HANDLER = DisableAbleCommandHandler("sin", sin, pass_args=True)
TAN_HANDLER = DisableAbleCommandHandler("tan", tan, pass_args=True)
ARCCOS_HANDLER = DisableAbleCommandHandler("arccos", arccos, pass_args=True)
ARCSIN_HANDLER = DisableAbleCommandHandler("arcsin", arcsin, pass_args=True)
ARCTAN_HANDLER = DisableAbleCommandHandler("arctan", arctan, pass_args=True)
ABS_HANDLER = DisableAbleCommandHandler("abs", abs, pass_args=True)
LOG_HANDLER = DisableAbleCommandHandler("log", log, pass_args=True)

dispatcher.add_handler(SIMPLIFY_HANDLER)
dispatcher.add_handler(FACTOR_HANDLER)
dispatcher.add_handler(DERIVE_HANDLER)
dispatcher.add_handler(INTEGRATE_HANDLER)
dispatcher.add_handler(ZEROES_HANDLER)
dispatcher.add_handler(TANGENT_HANDLER) 
dispatcher.add_handler(AREA_HANDLER)
dispatcher.add_handler(COS_HANDLER)
dispatcher.add_handler(SIN_HANDLER)
dispatcher.add_handler(TAN_HANDLER)
dispatcher.add_handler(ARCCOS_HANDLER)
dispatcher.add_handler(ARCSIN_HANDLER)
dispatcher.add_handler(ARCTAN_HANDLER)
dispatcher.add_handler(ABS_HANDLER)
dispatcher.add_handler(LOG_HANDLER)

__mod_name__ = "Math"
__command_list__ = ["math","factor","derive","integrate","zeroes","tangent","area","cos","sin","tan","arccos","arcsin","arctan","abs","log"]
__handlers__ = [
    SIMPLIFY_HANDLER,FACTOR_HANDLER,DERIVE_HANDLER,INTEGRATE_HANDLER,TANGENT_HANDLER,ZEROES_HANDLER,AREA_HANDLER,COS_HANDLER,SIN_HANDLER,TAN_HANDLER,ARCCOS_HANDLER,ARCSIN_HANDLER,ARCTAN_HANDLER,ABS_HANDLER,LOG_HANDLER
]

[((3826, 3885), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""math"""', 'simplify'], {'pass_args': '(True)'}), "('math', simplify, pass_args=True)\n", (3851, 3885), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((3903, 3962), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""factor"""', 'factor'], {'pass_args': '(True)'}), "('factor', factor, pass_args=True)\n", (3928, 3962), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((3980, 4039), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""derive"""', 'derive'], {'pass_args': '(True)'}), "('derive', derive, pass_args=True)\n", (4005, 4039), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4060, 4125), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""integrate"""', 'integrate'], {'pass_args': '(True)'}), "('integrate', integrate, pass_args=True)\n", (4085, 4125), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4143, 4202), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""zeroes"""', 'zeroes'], {'pass_args': '(True)'}), "('zeroes', zeroes, pass_args=True)\n", (4168, 4202), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4221, 4282), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""tangent"""', 'tangent'], {'pass_args': '(True)'}), "('tangent', tangent, pass_args=True)\n", (4246, 4282), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4298, 4353), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""area"""', 'area'], {'pass_args': '(True)'}), "('area', area, pass_args=True)\n", (4323, 4353), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4368, 4421), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""cos"""', 'cos'], {'pass_args': '(True)'}), "('cos', cos, pass_args=True)\n", (4393, 4421), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4436, 4489), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""sin"""', 'sin'], {'pass_args': '(True)'}), "('sin', sin, pass_args=True)\n", (4461, 4489), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4504, 4557), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""tan"""', 'tan'], {'pass_args': '(True)'}), "('tan', tan, pass_args=True)\n", (4529, 4557), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4575, 4634), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""arccos"""', 'arccos'], {'pass_args': '(True)'}), "('arccos', arccos, pass_args=True)\n", (4600, 4634), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4652, 4711), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""arcsin"""', 'arcsin'], {'pass_args': '(True)'}), "('arcsin', arcsin, pass_args=True)\n", (4677, 4711), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4729, 4788), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""arctan"""', 'arctan'], {'pass_args': '(True)'}), "('arctan', arctan, pass_args=True)\n", (4754, 4788), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4803, 4856), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""abs"""', 'abs'], {'pass_args': '(True)'}), "('abs', abs, pass_args=True)\n", (4828, 4856), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4871, 4924), 'emilia.modules.disable.DisableAbleCommandHandler', 'DisableAbleCommandHandler', (['"""log"""', 'log'], {'pass_args': '(True)'}), "('log', log, pass_args=True)\n", (4896, 4924), False, 'from emilia.modules.disable import DisableAbleCommandHandler\n'), ((4926, 4966), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['SIMPLIFY_HANDLER'], {}), '(SIMPLIFY_HANDLER)\n', (4948, 4966), False, 'from emilia import dispatcher\n'), ((4967, 5005), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['FACTOR_HANDLER'], {}), '(FACTOR_HANDLER)\n', (4989, 5005), False, 'from emilia import dispatcher\n'), ((5006, 5044), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['DERIVE_HANDLER'], {}), '(DERIVE_HANDLER)\n', (5028, 5044), False, 'from emilia import dispatcher\n'), ((5045, 5086), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['INTEGRATE_HANDLER'], {}), '(INTEGRATE_HANDLER)\n', (5067, 5086), False, 'from emilia import dispatcher\n'), ((5087, 5125), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['ZEROES_HANDLER'], {}), '(ZEROES_HANDLER)\n', (5109, 5125), False, 'from emilia import dispatcher\n'), ((5126, 5165), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['TANGENT_HANDLER'], {}), '(TANGENT_HANDLER)\n', (5148, 5165), False, 'from emilia import dispatcher\n'), ((5167, 5203), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['AREA_HANDLER'], {}), '(AREA_HANDLER)\n', (5189, 5203), False, 'from emilia import dispatcher\n'), ((5204, 5239), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['COS_HANDLER'], {}), '(COS_HANDLER)\n', (5226, 5239), False, 'from emilia import dispatcher\n'), ((5240, 5275), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['SIN_HANDLER'], {}), '(SIN_HANDLER)\n', (5262, 5275), False, 'from emilia import dispatcher\n'), ((5276, 5311), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['TAN_HANDLER'], {}), '(TAN_HANDLER)\n', (5298, 5311), False, 'from emilia import dispatcher\n'), ((5312, 5350), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['ARCCOS_HANDLER'], {}), '(ARCCOS_HANDLER)\n', (5334, 5350), False, 'from emilia import dispatcher\n'), ((5351, 5389), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['ARCSIN_HANDLER'], {}), '(ARCSIN_HANDLER)\n', (5373, 5389), False, 'from emilia import dispatcher\n'), ((5390, 5428), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['ARCTAN_HANDLER'], {}), '(ARCTAN_HANDLER)\n', (5412, 5428), False, 'from emilia import dispatcher\n'), ((5429, 5464), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['ABS_HANDLER'], {}), '(ABS_HANDLER)\n', (5451, 5464), False, 'from emilia import dispatcher\n'), ((5465, 5500), 'emilia.dispatcher.add_handler', 'dispatcher.add_handler', (['LOG_HANDLER'], {}), '(LOG_HANDLER)\n', (5487, 5500), False, 'from emilia import dispatcher\n')]