Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. const prototypes = require('../../util/prototypes');
  2. const Discord = require('discord.js');
  3. module.exports = {
  4. name: 'embed',
  5. description: '',
  6. aliases: ['e'],
  7. public: true,
  8. async execute(client, message, args, config, settings) {
  9. let clear = function (str) {
  10. return str.replace(/(['`','*'])/g, "\\$1")
  11. }
  12. let error = function (name, pass, ex, send) {
  13. if (!name) name = 'Неизвестная ошибка';
  14. let embed = new Discord.RichEmbed()
  15. .setColor("RED")
  16. .setTitle("ERROR")
  17. .addField('Описание ошибки', name, true);
  18. if (pass) { embed.addField('Решение', pass, true) }
  19. if (ex) { embed.addField('Пример', ex, true) }
  20. if (send === false) {
  21. return embed;
  22. } else {
  23. return message.channel.send(embed).catch(err => message.channel.send("⚠ | Внимание, боту нужны права `Встраивать ссылки` чтобы отправлять сообщения и отчеты об ошибках"))
  24. }
  25. }
  26. try {
  27. let text = args.join(" ").replace(/\n/g, "\\n");
  28. if (!text) return error("Аргументы не обнаружены, советуем ознакомиться с `x!help embed` для продолжения")
  29. let embed = new Discord.RichEmbed();
  30. let footer = text.match(/{footer:(.*?)( \| icon: ?(.*?))?}/i);
  31. if (footer !== null) {
  32. embed.setFooter(footer[1], footer[3])
  33. }
  34. let image = text.match(/{image: ?(.*?)}/i);
  35. if (image !== null) {
  36. embed.attachFile({
  37. attachment: image[1],
  38. file: image[1].substring(image[1].lastIndexOf('/') + 1)
  39. }).setImage('attachment://' + image[1].substring(image[1].lastIndexOf('/') + 1));
  40. }
  41. let thumb = text.match(/{thumbnail: ?(.*?)}/i);
  42. if (thumb !== null) {
  43. embed.attachFile({
  44. attachment: thumb[1],
  45. file: thumb[1].substring(thumb[1].lastIndexOf('/') + 1)
  46. }).setThumbnail('attachment://' + thumb[1].substring(thumb[1].lastIndexOf('/') + 1));
  47. }
  48. let author = text.match(/{author:(.*?)( \| icon: ?(.*?))?( \| url: ?(.*?))?}/i);
  49. if (author !== null) {
  50. embed.setAuthor(author[1], author[3], author[5])
  51. }
  52. let title = text.match(/{title:(.*?)}/i);
  53. if (title !== null) {
  54. embed.setTitle(title[1])
  55. }
  56. let url = text.match(/{url: ?(.*?)}/i);
  57. if (url !== null) {
  58. embed.setURL(url[1])
  59. }
  60. let description = text.match(/{description:(.*?)}/i);
  61. if (description !== null) {
  62. embed.setDescription(description[1].replace(/\\n/g, '\n'))
  63. }
  64. let color = text.match(/{colou?r: ?(.*?)}/i);
  65. if (color !== null) {
  66. embed.setColor(color[1])
  67. }
  68. let timestamp = text.match(/{timestamp(: ?(.*?))?}/i);
  69. if (timestamp !== null) {
  70. if (timestamp[2] === undefined || timestamp[2] === null)
  71. embed.setTimestamp(new Date());
  72. else
  73. embed.setTimestamp(new Date(timestamp[2]));
  74. }
  75. let fields = text.match(/{field: ?(.*?) \| value: ?(.*?)( \| inline)?}/gi)
  76. if (fields !== null) {
  77. fields.forEach((item) => {
  78. if (item[1] == null || item[2] == null || typeof item[1] === "undefined" || typeof item[2] === "undefined") return;
  79. let matches = item.match(/{field: ?(.*?) \| value: ?(.*?)( \| inline)?}/i);
  80. embed.addField(matches[1], matches[2].replace(/\\n/g, '\n'), (matches[3] != null));
  81. });
  82. }
  83. message.channel.send({ embed });
  84. message.delete();
  85. message.author.send("Я оставлю это здесь на случай, если вам нужно будет отредактировать прошлое сообщение или вы потеряли шаблон..\n\n```" + args.join(" ") + "```");
  86. // message.author.send(":warning: | Команда `embed` скоро будет переведена в премиум, некоторые сервера могут получить 1 из 2 версий за бесплатно, подробнее на https://xeval.ga/donate");
  87. } catch (e) {
  88. error("Ошибка при генерации embed сообщения\n```" + e + "```", "Внимание, не пытайтесь вставить текст длинее 256 символов в TITLE или первое значение FIELD, они являются заголовками, а не местами для полноценного текста.")
  89. console.error(e);
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement