Commit ee451eb
Changed files (3)
badges
reactions
stars
badges/reactions/reactions.ts
@@ -3,13 +3,15 @@ import { define, Reaction } from '#src'
type Where = {
count: number
url: string
+ content?: Reaction['content']
}
export default define({
url: import.meta.url,
- badges: ['confused'] as const,
+ badges: ['confused', 'self-upvote'] as const,
present(data, grant) {
const moreThan10: Where[] = []
+ const selfUpvotes: Where[] = []
for (const x of [
...data.issues,
@@ -22,14 +24,29 @@ export default define({
if (counts.CONFUSED > 10) {
moreThan10.push({ count: counts.CONFUSED, url: x.url })
}
+
+ for (const reaction of x.reactions) {
+ if (reaction.user?.login === data.user.login) {
+ selfUpvotes.push({
+ count: 1,
+ url: x.url,
+ content: reaction.content,
+ })
+ }
+ }
}
}
moreThan10.sort((a, b) => b.count - a.count)
-
if (moreThan10.length > 0) {
grant('confused', `I confused more than 10 people.`)
- .evidence(text(moreThan10))
+ .evidence(textWithCount(moreThan10))
+ .tier(1)
+ }
+
+ if (selfUpvotes.length > 0) {
+ grant('self-upvote', `I liked my own comment so much that I upvoted it.`)
+ .evidence(textWithContent(selfUpvotes))
.tier(1)
}
},
@@ -52,10 +69,30 @@ function count(reactions: Reaction[] | undefined) {
return counts
}
-function text(entries: Where[]): string {
+function textWithCount(entries: Where[]): string {
const lines: string[] = []
for (const where of entries) {
lines.push(`* <a href="${where.url}">${where.count} ๐</a>`)
}
return lines.join('\n')
}
+
+const emoji: Record<Reaction['content'], string> = {
+ CONFUSED: '๐',
+ EYES: '๐',
+ HEART: 'โค๏ธ',
+ HOORAY: '๐',
+ LAUGH: '๐',
+ ROCKET: '๐',
+ THUMBS_DOWN: '๐',
+ THUMBS_UP: '๐',
+} as const
+
+function textWithContent(entries: Where[]): string {
+ const lines: string[] = []
+ for (const where of entries) {
+ if (!where.content) continue
+ lines.push(`* <a href="${where.url}">${emoji[where.content]}</a>`)
+ }
+ return lines.join('\n')
+}
badges/reactions/self-upvote.png
Binary file
badges/stars/stars.test.ts
@@ -1,5 +1,5 @@
import { describe, test, expect } from 'vitest'
-import starsPresenter from '#badges/stars/stars.js'
+import starsPresenter from './stars.js'
import { badgeCollection } from '../../src/present-badges.js'
import { Data } from '../../src/data.js'
import { Badge } from '../../src/badges.js'