excalc.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # ______ ______ ______ ______ ______ __ ______ ______
  2. # /\ ___\ /\ == \ /\ ___\ /\ __ \ /\__ _\ /\ \ /\___ \ /\ ___\
  3. # \ \ \____ \ \ __< \ \ __\ \ \ __ \ \/_/\ \/ \ \ \ \/_/ /__ \ \ __\
  4. # \ \_____\ \ \_\ \_\ \ \_____\ \ \_\ \_\ \ \_\ \ \_\ /\_____\ \ \_____\
  5. # \/_____/ \/_/ /_/ \/_____/ \/_/\/_/ \/_/ \/_/ \/_____/ \/_____/
  6. # Code is licensed under CC-BY-NC-ND 4.0 unless otherwise specified.
  7. # https://creativecommons.org/licenses/by-nc-nd/4.0/
  8. # You CANNOT edit this file without direct permission from the author.
  9. # You can redistribute this file without any changes.
  10. # meta developer: @creaz_mods, @daffmaybe
  11. # scope: hikka_min 1.6.2
  12. # requires: mpmath sympy
  13. from math import cos, factorial, radians, sin, sqrt, tan
  14. from hikkatl.types import Message
  15. from sympy import subfactorial
  16. from .. import loader, utils
  17. class Calc(loader.Module):
  18. strings = {
  19. "name": "Excalc",
  20. "err_int": "Only integral values",
  21. "_cls_doc": " Calculator with many functions. Only .e is better",
  22. "err_txt": "<b>[cl]</b> Error in a case",
  23. }
  24. strings_ru = {
  25. "err_int": "Только целые значения",
  26. "_cls_doc": " Калькулятор со множеством функций. Лучше только .e",
  27. "err_txt": "<b>[cl]</b> Ошибка в примере",
  28. }
  29. strings_es = {
  30. "err_int": "Solo valores enteros",
  31. "_cls_doc": "Una calculadora con muchas funciones. Mejor solo .e",
  32. "err_txt": "<b>[cl]</b> Error en el ejemplo",
  33. }
  34. strings_de = {
  35. "err_int": "Nur ganzzahlige Werte",
  36. "_cls_doc": "Ein Taschenrechner mit vielen Funktionen. Besser nur .e",
  37. "err_txt": "<b>[cl]</b> Fehler im Beispiel",
  38. }
  39. @loader.command()
  40. async def cl(self, message: Message):
  41. """- ваш пример"""
  42. args = utils.get_args_raw(message)
  43. try:
  44. await utils.answer(message, f"{args} = <code>{eval(args)}</code>")
  45. except:
  46. await utils.answer(message, self.strings("err_txt"))
  47. @loader.command()
  48. async def fct(self, message: Message):
  49. """- вычисляет факториал числа"""
  50. args = utils.get_args_raw(message)
  51. try:
  52. await utils.answer(
  53. message, f"{args}! = <code>{round(factorial(int(args)), 5)}</code>"
  54. )
  55. except:
  56. await utils.answer(message, self.strings("err_int"))
  57. @loader.command()
  58. async def sqrt(self, message: Message):
  59. """- вычисляет квадратный корень числа"""
  60. args = utils.get_args_raw(message)
  61. await utils.answer(
  62. message, f"√{args} = <code>{round(sqrt(float(args)), 5)}</code>"
  63. )
  64. @loader.command()
  65. async def sfct(self, message: Message):
  66. """- вычисляет субфакториал числа"""
  67. args = utils.get_args_raw(message)
  68. try:
  69. await utils.answer(
  70. message, f"!{args} = <code>{round(subfactorial(int(args)), 5)}</code>"
  71. )
  72. except:
  73. await utils.answer(message, self.strings("err_int"))
  74. @loader.command()
  75. async def cos(self, message: Message):
  76. """- вычисляет косинус числа"""
  77. args = utils.get_args_raw(message)
  78. await utils.answer(
  79. message, f"cos({args}) = <code>{round(cos(radians(float(args))), 5)}</code>"
  80. )
  81. @loader.command()
  82. async def sin(self, message: Message):
  83. """- вычисляет синус числа"""
  84. args = utils.get_args_raw(message)
  85. await utils.answer(
  86. message, f"sin({args}) = <code>{round(sin(radians(float(args))), 5)}</code>"
  87. )
  88. @loader.command()
  89. async def tan(self, message: Message):
  90. """- вычисляет тангенс числа"""
  91. args = utils.get_args_raw(message)
  92. await utils.answer(
  93. message, f"tg({args}) = <code>{round(tan(radians(float(args))), 5)}</code>"
  94. )