Advertisement
n3k4a

Untitled

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