{"action":"created","comment":{"url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/comments/172651478","pull_request_review_id":101704394,"id":172651478,"diff_hunk":"@@ -0,0 +1,281 @@\n+# Starboard\n+\n+This is a long awaited feature, requested by many people.\n+\n+Let's begin by talking about what a starboard is. This is an example taken from the Discord.js Official Server.\n+\n+![Starboard](/assets/starboard.png)\n+\n+> Before we start, there is one thing you need to now. This code is compatible with only Guidebot Class. This is due to a restriction with passing `client` to the messageReactionAdd and messageReactionRemove events.\n+\n+So, let's begin!\n+\n+```js\n+module.exports = class {\n+  constructor(client) {\n+    this.client = client;\n+\n+    this.starEmbed = async (color, description, author, authorURL, timestamp, footer, image) => {\n+      const embed = { \n+        'color': color, \n+        'description': description, \n+        'author': { \n+          'name': author,\n+          'icon_url': authorURL\n+        },\n+        'image': { \n+          'url': image \n+        }, \n+        'timestamp': timestamp, \n+        'footer': { \n+          'text': footer \n+        } \n+      };\n+      return embed; \n+    };\n+\n+    this.extension = async (reaction, attachment) => {\n+      const imageLink = attachment.split('.');\n+      const typeOfImage = imageLink[imageLink.length - 1];\n+      const image = /(jpg|jpeg|png|gif)/gi.exec(typeOfImage);\n+      if (!image) return '';\n+      return attachment;\n+    };\n+  }\n+}\n+```\n+\n+Alright, let's break this down. \n+\n+```js\n+this.starEmbed = async (color, description, author, authorURL, timestamp, footer, image) => {\n+  const embed = { \n+    'color': color, \n+    'description': description, \n+    'author': { \n+    'name': author,\n+      'icon_url': authorURL\n+    },\n+    'image': { \n+      'url': image \n+    }, \n+    'timestamp': timestamp, \n+    'footer': { \n+      'text': footer \n+    } \n+  };\n+  return embed; \n+};\n+\n+this.extension = async (reaction, attachment) => {\n+  const imageLink = attachment.split('.');\n+  const typeOfImage = imageLink[imageLink.length - 1];\n+  const image = /(jpg|jpeg|png|gif)/gi.exec(typeOfImage);\n+  if (!image) return '';\n+  return attachment;\n+};\n+```\n+\n+This creates 2 functions attached to `this.` for later convenience. `this.starEmbed` will create the embed for us to send. Next, we create a function that will determine whether or not there is an image attached to the message.\n+\n+Let's keep going.\n+\n+```js\n+async run(reaction, user) {\n+  const message = reaction.message;\n+  const { starboardChannel } = this.client.settings.get(message.guild.id)\n+  if (reaction.emoji.name !== '⭐') return;\n+  if (message.author.id === user.id) return message.channel.send(`${user}, you cannot star your own messages.`);\n+  if (message.author.bot) return message.channel.send(`${user}, you cannot star bot messages.`);\n+}\n+```\n+\n+This is some simple setup for later on. For ease, I define message as `message`, but this is completely optional. Next, we grab the starboardChannel key from the guilds settings. Then, we preform a couple of checks on the reaction and the message. First, we check if the reaction is the unicode star emote. Then, we preform two checks on the message, which are checking if the user who added the star is the author of the message, and then we check if the author of the message is a bot. If neither of these checks return true, then we're good to go. Let's move on.\n+\n+```js\n+async run(reaction, user) {\n+  const message = reaction.message;\n+  const { starboardChannel } = this.client.settings.get(message.guild.id)\n+  if (reaction.emoji.name !== '⭐') return;\n+  if (message.author.id === user.id) return message.channel.send(`${user}, you cannot star your own messages.`);\n+  if (message.author.bot) return message.channel.send(`${user}, you cannot star bot messages.`);\n+  try {\n+    const fetch = await message.guild.channels.find('name', starboardChannel).fetchMessages({ limit: 100 });\n+    const stars = fetch.find(m => m.embeds[0].footer.text.startsWith('⭐') && m.embeds[0].footer.text.endsWith(message.id));\n+    if (stars) {\n+      const star = /\\⭐\\s([0-9]{1,3})\\s\\|\\s([0-9]{17,20})/g.exec(stars.embeds[0].footer.text);\n+      const _star = stars.embeds[0];\n+      const image = message.attachments.size > 0 ? await this.extension(reaction, message.attachments.array()[0].url) : '';\n+      const embed = await this.starEmbed(_star.color, _star.description, _star.author.name, _star.author.displayAvatarURL, _star.createdTimestamp, `⭐ ${parseInt(star[1])+1} | ${message.id}`, `${image}`);\n+      const starMsg = await message.guild.channels.find('name', starboardChannel).fetchMessage(stars.id);\n+      await starMsg.edit({ embed });\n+    }\n+  } catch (error) {\n+    throw error;","path":"coding-guides/starboard.md","position":114,"original_position":114,"commit_id":"4073cda106ae1a30fea064f4b372e2708a94c51d","original_commit_id":"4073cda106ae1a30fea064f4b372e2708a94c51d","user":{"login":"kyranet","id":24852502,"avatar_url":"https://avatars0.githubusercontent.com/u/24852502?v=4","gravatar_id":"","url":"https://api.github.com/users/kyranet","html_url":"https://github.com/kyranet","followers_url":"https://api.github.com/users/kyranet/followers","following_url":"https://api.github.com/users/kyranet/following{/other_user}","gists_url":"https://api.github.com/users/kyranet/gists{/gist_id}","starred_url":"https://api.github.com/users/kyranet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kyranet/subscriptions","organizations_url":"https://api.github.com/users/kyranet/orgs","repos_url":"https://api.github.com/users/kyranet/repos","events_url":"https://api.github.com/users/kyranet/events{/privacy}","received_events_url":"https://api.github.com/users/kyranet/received_events","type":"User","site_admin":false},"body":"Useless throw error, they bubble up, you don't need to re-throw them.","created_at":"2018-03-06T20:36:42Z","updated_at":"2018-03-06T20:42:41Z","html_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide/pull/10#discussion_r172651478","pull_request_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/comments/172651478"},"html":{"href":"https://github.com/AnIdiotsGuide/discordjs-bot-guide/pull/10#discussion_r172651478"},"pull_request":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10","id":172352228,"html_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide/pull/10","diff_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide/pull/10.diff","patch_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide/pull/10.patch","issue_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues/10","number":10,"state":"open","locked":false,"title":"Starboard","user":{"login":"OGNova","id":26777028,"avatar_url":"https://avatars3.githubusercontent.com/u/26777028?v=4","gravatar_id":"","url":"https://api.github.com/users/OGNova","html_url":"https://github.com/OGNova","followers_url":"https://api.github.com/users/OGNova/followers","following_url":"https://api.github.com/users/OGNova/following{/other_user}","gists_url":"https://api.github.com/users/OGNova/gists{/gist_id}","starred_url":"https://api.github.com/users/OGNova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OGNova/subscriptions","organizations_url":"https://api.github.com/users/OGNova/orgs","repos_url":"https://api.github.com/users/OGNova/repos","events_url":"https://api.github.com/users/OGNova/events{/privacy}","received_events_url":"https://api.github.com/users/OGNova/received_events","type":"User","site_admin":false},"body":"This PR adds starboard.md, a guide on creating a starboard with Guidebot Class. ","created_at":"2018-03-01T21:00:11Z","updated_at":"2018-03-06T20:42:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"89f933163edeff6a00b724011b692accc196bfce","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10/commits","review_comments_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10/comments","review_comment_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues/10/comments","statuses_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/statuses/4073cda106ae1a30fea064f4b372e2708a94c51d","head":{"label":"OGNova:master","ref":"master","sha":"4073cda106ae1a30fea064f4b372e2708a94c51d","user":{"login":"OGNova","id":26777028,"avatar_url":"https://avatars3.githubusercontent.com/u/26777028?v=4","gravatar_id":"","url":"https://api.github.com/users/OGNova","html_url":"https://github.com/OGNova","followers_url":"https://api.github.com/users/OGNova/followers","following_url":"https://api.github.com/users/OGNova/following{/other_user}","gists_url":"https://api.github.com/users/OGNova/gists{/gist_id}","starred_url":"https://api.github.com/users/OGNova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OGNova/subscriptions","organizations_url":"https://api.github.com/users/OGNova/orgs","repos_url":"https://api.github.com/users/OGNova/repos","events_url":"https://api.github.com/users/OGNova/events{/privacy}","received_events_url":"https://api.github.com/users/OGNova/received_events","type":"User","site_admin":false},"repo":{"id":123372552,"name":"discordjs-bot-guide","full_name":"OGNova/discordjs-bot-guide","owner":{"login":"OGNova","id":26777028,"avatar_url":"https://avatars3.githubusercontent.com/u/26777028?v=4","gravatar_id":"","url":"https://api.github.com/users/OGNova","html_url":"https://github.com/OGNova","followers_url":"https://api.github.com/users/OGNova/followers","following_url":"https://api.github.com/users/OGNova/following{/other_user}","gists_url":"https://api.github.com/users/OGNova/gists{/gist_id}","starred_url":"https://api.github.com/users/OGNova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OGNova/subscriptions","organizations_url":"https://api.github.com/users/OGNova/orgs","repos_url":"https://api.github.com/users/OGNova/repos","events_url":"https://api.github.com/users/OGNova/events{/privacy}","received_events_url":"https://api.github.com/users/OGNova/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/OGNova/discordjs-bot-guide","description":null,"fork":true,"url":"https://api.github.com/repos/OGNova/discordjs-bot-guide","forks_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/forks","keys_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/teams","hooks_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/hooks","issue_events_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/issues/events{/number}","events_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/events","assignees_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/assignees{/user}","branches_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/branches{/branch}","tags_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/tags","blobs_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/git/refs{/sha}","trees_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/statuses/{sha}","languages_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/languages","stargazers_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/stargazers","contributors_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/contributors","subscribers_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/subscribers","subscription_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/subscription","commits_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/commits{/sha}","git_commits_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/git/commits{/sha}","comments_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/comments{/number}","issue_comment_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/issues/comments{/number}","contents_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/contents/{+path}","compare_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/merges","archive_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/downloads","issues_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/issues{/number}","pulls_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/pulls{/number}","milestones_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/milestones{/number}","notifications_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/labels{/name}","releases_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/releases{/id}","deployments_url":"https://api.github.com/repos/OGNova/discordjs-bot-guide/deployments","created_at":"2018-03-01T02:45:20Z","updated_at":"2018-02-22T13:27:15Z","pushed_at":"2018-03-04T02:16:47Z","git_url":"git://github.com/OGNova/discordjs-bot-guide.git","ssh_url":"git@github.com:OGNova/discordjs-bot-guide.git","clone_url":"https://github.com/OGNova/discordjs-bot-guide.git","svn_url":"https://github.com/OGNova/discordjs-bot-guide","homepage":null,"size":1022,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"AnIdiotsGuide:master","ref":"master","sha":"507af4dd21a07945a2a2005ed99c3b873c258bef","user":{"login":"AnIdiotsGuide","id":29665791,"avatar_url":"https://avatars1.githubusercontent.com/u/29665791?v=4","gravatar_id":"","url":"https://api.github.com/users/AnIdiotsGuide","html_url":"https://github.com/AnIdiotsGuide","followers_url":"https://api.github.com/users/AnIdiotsGuide/followers","following_url":"https://api.github.com/users/AnIdiotsGuide/following{/other_user}","gists_url":"https://api.github.com/users/AnIdiotsGuide/gists{/gist_id}","starred_url":"https://api.github.com/users/AnIdiotsGuide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AnIdiotsGuide/subscriptions","organizations_url":"https://api.github.com/users/AnIdiotsGuide/orgs","repos_url":"https://api.github.com/users/AnIdiotsGuide/repos","events_url":"https://api.github.com/users/AnIdiotsGuide/events{/privacy}","received_events_url":"https://api.github.com/users/AnIdiotsGuide/received_events","type":"Organization","site_admin":false},"repo":{"id":117981381,"name":"discordjs-bot-guide","full_name":"AnIdiotsGuide/discordjs-bot-guide","owner":{"login":"AnIdiotsGuide","id":29665791,"avatar_url":"https://avatars1.githubusercontent.com/u/29665791?v=4","gravatar_id":"","url":"https://api.github.com/users/AnIdiotsGuide","html_url":"https://github.com/AnIdiotsGuide","followers_url":"https://api.github.com/users/AnIdiotsGuide/followers","following_url":"https://api.github.com/users/AnIdiotsGuide/following{/other_user}","gists_url":"https://api.github.com/users/AnIdiotsGuide/gists{/gist_id}","starred_url":"https://api.github.com/users/AnIdiotsGuide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AnIdiotsGuide/subscriptions","organizations_url":"https://api.github.com/users/AnIdiotsGuide/orgs","repos_url":"https://api.github.com/users/AnIdiotsGuide/repos","events_url":"https://api.github.com/users/AnIdiotsGuide/events{/privacy}","received_events_url":"https://api.github.com/users/AnIdiotsGuide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide","description":null,"fork":false,"url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide","forks_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/forks","keys_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/teams","hooks_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/hooks","issue_events_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues/events{/number}","events_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/events","assignees_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/assignees{/user}","branches_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/branches{/branch}","tags_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/tags","blobs_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/git/refs{/sha}","trees_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/statuses/{sha}","languages_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/languages","stargazers_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/stargazers","contributors_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/contributors","subscribers_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/subscribers","subscription_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/subscription","commits_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/commits{/sha}","git_commits_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/git/commits{/sha}","comments_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/comments{/number}","issue_comment_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues/comments{/number}","contents_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/contents/{+path}","compare_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/merges","archive_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/downloads","issues_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues{/number}","pulls_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls{/number}","milestones_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/milestones{/number}","notifications_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/labels{/name}","releases_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/releases{/id}","deployments_url":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/deployments","created_at":"2018-01-18T12:42:30Z","updated_at":"2018-02-22T13:27:15Z","pushed_at":"2018-03-04T02:16:49Z","git_url":"git://github.com/AnIdiotsGuide/discordjs-bot-guide.git","ssh_url":"git@github.com:AnIdiotsGuide/discordjs-bot-guide.git","clone_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide.git","svn_url":"https://github.com/AnIdiotsGuide/discordjs-bot-guide","homepage":null,"size":992,"stargazers_count":9,"watchers_count":9,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":6,"open_issues":1,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10"},"html":{"href":"https://github.com/AnIdiotsGuide/discordjs-bot-guide/pull/10"},"issue":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues/10"},"comments":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/AnIdiotsGuide/discordjs-bot-guide/statuses/4073cda106ae1a30fea064f4b372e2708a94c51d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"kyranet"}}