Advertisement
n3k4a

Untitled

May 28th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const request = require("request");
  3. const { readFile, readFileSync } = require('fs-nextra');
  4. const { get } = require('snekfetch');
  5. const prefix = "-"
  6. client.on('ready', () => {
  7. console.log("Hello, I'm ready")
  8.  
  9. })
  10.  
  11. const jimp = require('jimp');
  12. const Canvas = require("canvas");
  13. client.on('message', message => {
  14. if (message.content == ('-clock')) {
  15.  
  16. const w = ['./file.png'];
  17.  
  18. let Image = Canvas.Image,
  19. canvas = new Canvas.Canvas(400, 400),
  20. ctx = canvas.getContext('2d');
  21. var radius = canvas.height / 2;
  22. var currentTime = new Date(),
  23. hours = currentTime.getHours() + 2,
  24. minute = currentTime.getMinutes() + 5;
  25. var second = currentTime.getSeconds();
  26. ctx.translate(radius, radius);
  27. radius = radius * 0.90
  28.  
  29. ctx.patternQuality = 'bilinear';
  30. ctx.filter = 'bilinear';
  31. ctx.antialias = 'subpixel';
  32. ctx.shadowColor = 'rgba(0, 0, 0, 0.4)';
  33. ctx.shadowOffsetY = 2;
  34. ctx.shadowBlur = 2;
  35. fs.readFile(`${w[Math.floor(Math.random() * w.length)]}`, function (err, Background) {
  36. if (err) return console.log(err);
  37. let BG = Canvas.Image;
  38. let ground = new Image;
  39. ground.src = Background;
  40. ctx.drawImage(ground, 0, 0, 400, 169);
  41. })
  42.  
  43.  
  44. ctx = canvas.getContext('2d');
  45. ctx.patternQuality = 'bilinear';
  46. ctx.filter = 'bilinear';
  47. ctx.antialias = 'subpixel';
  48. ctx.shadowColor = 'rgba(0, 0, 0, 0.4)';
  49. ctx.shadowOffsetY = 2;
  50. ctx.shadowBlur = 2;
  51. fs.readFile(`${w[Math.floor(Math.random() * w.length)]}`, function (err, Background) {
  52. if (err) return console.log(err);
  53. let BG = Canvas.Image;
  54.  
  55. })
  56. let user = message.mentions.users.first();
  57. var men = message.mentions.users.first();
  58. var heg;
  59. if (men) {
  60. heg = men
  61. } else {
  62. heg = message.author
  63. }
  64. var mentionned = message.mentions.members.first();
  65. var h;
  66. if (mentionned) {
  67. h = mentionned
  68. } else {
  69. h = message.member
  70. }
  71. var ment = message.mentions.users.first();
  72. var getvalueof;
  73. if (ment) {
  74. getvalueof = ment;
  75. } else {
  76. getvalueof = message.author;
  77. } //ظ…ط§ ط®طµظƒ ,_,
  78. let url = getvalueof.displayAvatarURL.endsWith(".webp") ? getvalueof.displayAvatarURL.slice(5, -20) + ".png" : getvalueof.displayAvatarURL;
  79. jimp.read(url, (err, ava) => {
  80. if (err) return console.log(err);
  81. ava.getBuffer(jimp.MIME_PNG, (err, buf) => {
  82. if (err) return console.log(err);
  83.  
  84.  
  85. function drawFace(ctx, radius) {
  86. var grad;
  87. ctx.beginPath();
  88. ctx.arc(0, 0, radius, 0, 2 * Math.PI);
  89. ctx.fillStyle = 'white';
  90. ctx.fill();
  91. grad = ctx.createRadialGradient(0, 0, radius * 0.95, 0, 0, radius * 1.05);
  92. grad.addColorStop(0, '#333');
  93. grad.addColorStop(0.5, 'black');
  94. grad.addColorStop(1, '#333');
  95. ctx.strokeStyle = grad;
  96. ctx.lineWidth = radius * 0.1;
  97. ctx.stroke();
  98. ctx.beginPath();
  99. ctx.arc(0, 0, radius * 0.1, 0, 2 * Math.PI);
  100. ctx.fillStyle = '#333';
  101. ctx.fill();
  102. }
  103. drawClock();
  104.  
  105. function drawClock() {
  106. drawFace(ctx, radius);
  107. drawNumbers(ctx, radius);
  108. drawTime(ctx, radius);
  109. }
  110.  
  111. function drawNumbers(ctx, radius) {
  112. var ang;
  113. var num;
  114. ctx.font = radius * 0.15 + "px arial";
  115. ctx.textBaseline = "middle";
  116. ctx.textAlign = "center";
  117. for (num = 1; num < 13; num++) {
  118. ang = num * Math.PI / 6;
  119. ctx.rotate(ang);
  120. ctx.translate(0, -radius * 0.85);
  121. ctx.rotate(-ang);
  122. ctx.fillText(num.toString(), 0, 0);
  123. ctx.rotate(ang);
  124. ctx.translate(0, radius * 0.85);
  125. ctx.rotate(-ang);
  126. }
  127. }
  128.  
  129. function drawTime(ctx, radius) {
  130.  
  131. if (hours > 12) {
  132. hours -= 12;
  133. } else if (hours == 0) {
  134. hours = "12";
  135. }
  136. if (minute < 10) {
  137. minute = '0' + minute;
  138. }
  139. //hour
  140. hours = hours % 12;
  141. hours = (hours * Math.PI / 6) +
  142. (minute * Math.PI / (6 * 60)) +
  143. (second * Math.PI / (360 * 60));
  144. drawHand(ctx, hours, radius * 0.5, radius * 0.07);
  145. //minute
  146. minute = (minute * Math.PI / 30) + (second * Math.PI / (30 * 60));
  147. drawHand(ctx, minute, radius * 0.8, radius * 0.07);
  148. }
  149.  
  150. function drawHand(ctx, pos, length, width) {
  151. ctx.beginPath();
  152. ctx.lineWidth = width;
  153. ctx.lineCap = "round";
  154. ctx.moveTo(0, 0);
  155. ctx.rotate(pos);
  156. ctx.lineTo(0, -length);
  157. ctx.stroke();
  158. ctx.rotate(-pos);
  159. }
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. var currentTime = new Date(),
  167. hours2 = currentTime.getHours(),
  168. minutes2 = currentTime.getMinutes(),
  169. seconds2 = currentTime.getSeconds();
  170.  
  171. if (hours2 > 12) {
  172. hours2 -= 12;
  173. } else if (hours2 == 0) {
  174. hours2 = "12";
  175. }
  176. if (minutes2 < 10) {
  177. minutes2 = '0' + minutes2;
  178. }
  179.  
  180. message.channel.send((`**:clock: | الساعة في الوقت الحالي : ${hours2}:${minutes2}:${seconds2}**`));
  181.  
  182.  
  183.  
  184. message.channel.sendFile(canvas.toBuffer());
  185.  
  186.  
  187.  
  188.  
  189. })
  190. })
  191. }
  192. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement