KiTTY, un bot Discord qui est un petit chat :) Il est basé sur une ancienne version du bot Red, sous Python 3.6 et qui a des fonctionnalités bien sympatiques !
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

81 lines
1.9KB

  1. def error(text):
  2. return "\N{NO ENTRY SIGN} {}".format(text)
  3. def warning(text):
  4. return "\N{WARNING SIGN} {}".format(text)
  5. def info(text):
  6. return "\N{INFORMATION SOURCE} {}".format(text)
  7. def question(text):
  8. return "\N{BLACK QUESTION MARK ORNAMENT} {}".format(text)
  9. def bold(text):
  10. return "**{}**".format(text)
  11. def box(text, lang=""):
  12. ret = "```{}\n{}\n```".format(lang, text)
  13. return ret
  14. def inline(text):
  15. return "`{}`".format(text)
  16. def italics(text):
  17. return "*{}*".format(text)
  18. def pagify(text, delims=["\n"], *, escape=True, shorten_by=8,
  19. page_length=2000):
  20. """DOES NOT RESPECT MARKDOWN BOXES OR INLINE CODE"""
  21. in_text = text
  22. if escape:
  23. num_mentions = text.count("@here") + text.count("@everyone")
  24. shorten_by += num_mentions
  25. page_length -= shorten_by
  26. while len(in_text) > page_length:
  27. closest_delim = max([in_text.rfind(d, 0, page_length)
  28. for d in delims])
  29. closest_delim = closest_delim if closest_delim != -1 else page_length
  30. if escape:
  31. to_send = escape_mass_mentions(in_text[:closest_delim])
  32. else:
  33. to_send = in_text[:closest_delim]
  34. yield to_send
  35. in_text = in_text[closest_delim:]
  36. if escape:
  37. yield escape_mass_mentions(in_text)
  38. else:
  39. yield in_text
  40. def strikethrough(text):
  41. return "~~{}~~".format(text)
  42. def underline(text):
  43. return "__{}__".format(text)
  44. def escape(text, *, mass_mentions=False, formatting=False):
  45. if mass_mentions:
  46. text = text.replace("@everyone", "@\u200beveryone")
  47. text = text.replace("@here", "@\u200bhere")
  48. if formatting:
  49. text = (text.replace("`", "\\`")
  50. .replace("*", "\\*")
  51. .replace("_", "\\_")
  52. .replace("~", "\\~"))
  53. return text
  54. def escape_mass_mentions(text):
  55. return escape(text, mass_mentions=True)