From 00f7c85cfb0d95cf6c0c790bbf40e7ab85ff1351 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:10:55 +0000 Subject: [PATCH 01/15] feat: add comment-incentive command --- src/configs/ubiquibot-config-default.ts | 4 +++ src/handlers/comment/commands.ts | 1 + .../comment/handlers/comment-incentive.ts | 23 ++++++++++++++++ src/handlers/comment/handlers/index.ts | 9 +++++++ src/handlers/payout/post.ts | 8 +++--- src/helpers/issue.ts | 26 +++++++++++++++++++ 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/handlers/comment/handlers/comment-incentive.ts diff --git a/src/configs/ubiquibot-config-default.ts b/src/configs/ubiquibot-config-default.ts index 4a989995f..d1a4ff41d 100644 --- a/src/configs/ubiquibot-config-default.ts +++ b/src/configs/ubiquibot-config-default.ts @@ -52,6 +52,10 @@ export const DefaultConfig: MergedConfig = { name: "start", enabled: false, }, + { + name: "comment-incentive", + enabled: false, + }, { name: "stop", enabled: false, diff --git a/src/handlers/comment/commands.ts b/src/handlers/comment/commands.ts index 9bce9fc6e..7c6f4eff3 100644 --- a/src/handlers/comment/commands.ts +++ b/src/handlers/comment/commands.ts @@ -7,6 +7,7 @@ export enum IssueCommentCommands { MULTIPLIER = "/multiplier", // set bounty multiplier (for treasury) QUERY = "/query", ASK = "/ask", // ask GPT a question + COMMENTINCENTIVE = "/comment-incentive", // Access Controls ALLOW = "/allow", diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts new file mode 100644 index 000000000..5a2cf6496 --- /dev/null +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -0,0 +1,23 @@ +import { getBotContext, getLogger } from "../../../bindings"; +import { Payload } from "../../../types"; + +export const commentIncentive = async (body: string) => { + const context = getBotContext(); + const logger = getLogger(); + const payload = context.payload as Payload; + const sender = payload.sender.login; + + logger.info(`Received '/comment-incentive' command from user: ${sender}`); + + if (!payload.issue) { + logger.info(`Skipping '/comment-incentive' because of no issue instance`); + return `Skipping '/comment-incentive' because of no issue instance`; + } + const parts = body.split(" "); + parts.shift(); + if (parts.pop() !== "true" && parts.pop() !== "false") { + return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; + } else { + return; + } +}; diff --git a/src/handlers/comment/handlers/index.ts b/src/handlers/comment/handlers/index.ts index d7de92373..e2114bd39 100644 --- a/src/handlers/comment/handlers/index.ts +++ b/src/handlers/comment/handlers/index.ts @@ -10,6 +10,8 @@ import { approveLabelChange } from "./authorize"; import { setAccess } from "./allow"; import { ask } from "./ask"; import { multiplier } from "./multiplier"; +import { commentIncentive } from "./comment-incentive"; + import { BigNumber, ethers } from "ethers"; import { addPenalty } from "../../../adapters/supabase"; import { @@ -48,6 +50,7 @@ export * from "./multiplier"; export * from "./query"; export * from "./ask"; export * from "./authorize"; +export * from "./comment-incentive"; export interface RewardsResponse { error: string | null; @@ -263,6 +266,12 @@ export const userCommands = (): UserCommands[] => { handler: unassign, callback: commandCallback, }, + { + id: IssueCommentCommands.COMMENTINCENTIVE, + description: "Enables or Disables comment incentives for a user", + handler: commentIncentive, + callback: commandCallback, + }, { handler: listAvailableCommands, id: IssueCommentCommands.HELP, diff --git a/src/handlers/payout/post.ts b/src/handlers/payout/post.ts index 18d9aa1df..f73e37cdf 100644 --- a/src/handlers/payout/post.ts +++ b/src/handlers/payout/post.ts @@ -1,6 +1,6 @@ import { getWalletAddress } from "../../adapters/supabase"; import { getBotContext, getLogger } from "../../bindings"; -import { getAllIssueComments, getAllPullRequestReviews, getIssueDescription, parseComments } from "../../helpers"; +import { getAllIssueComments, getAllPullRequestReviews, getIncentivizedUsers, getIssueDescription, parseComments } from "../../helpers"; import { getLatestPullRequest, gitLinkedPrParser } from "../../helpers/parser"; import { Incentives, MarkdownItem, Payload, UserType } from "../../types"; import { RewardsResponse, commentParser } from "../comment"; @@ -52,7 +52,7 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince const issueCommentsByUser: Record = {}; for (const issueComment of issueComments) { const user = issueComment.user; - if (user.type == UserType.Bot || user.login == assignee.login) continue; + if (user.type == UserType.Bot) continue; const commands = commentParser(issueComment.body); if (commands.length > 0) { logger.info(`Skipping to parse the comment because it contains commands. comment: ${JSON.stringify(issueComment)}`); @@ -76,8 +76,10 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince // array of awaiting permits to generate const reward: { account: string; priceInEth: Decimal; userId: string; user: string; penaltyAmount: BigNumber }[] = []; - + const users = await getIncentivizedUsers(calculateIncentives.issue.number); + if (!users) return { error: "Error: Could not find any incentivized users" }; for (const user of Object.keys(issueCommentsByUser)) { + if (!users[user] === true) continue; const commentsByUser = issueCommentsByUser[user]; const commentsByNode = await parseComments(commentsByUser.comments, ItemsToExclude); const rewardValue = calculateRewardValue(commentsByNode, calculateIncentives.incentives); diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index e014994fe..b58fd2124 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -27,6 +27,32 @@ export const clearAllPriceLabelsOnIssue = async (): Promise => { } }; +export const getIncentivizedUsers = async (issue_number: number) => { + const comments = await getAllIssueComments(issue_number); + const incentiveComments = comments.filter((comment) => comment.body.startsWith("/comment-incentives")); + let users: { [key: string]: boolean } = {}; + for (const incentiveComment of incentiveComments) { + const parts = incentiveComment.body.split(" "); + parts.shift(); + var toggle: RegExpMatchArray | null = incentiveComment.body.match(/\b(true|false)\b/); + + if (!toggle) { + for (const part of parts) { + if (part.startsWith("@")) { + users[part.substring(1)] = false; + } + } + } else { + for (const part of parts) { + if (part.startsWith("@")) { + users[part.substring(1)] = toggle[0] === "true"; + } + } + } + } + return users; +}; + export const addLabelToIssue = async (labelName: string) => { const context = getBotContext(); const logger = getLogger(); From 67a104ccf8d2b1d3763688e652b13ce7b094a5f5 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:14:58 +0000 Subject: [PATCH 02/15] feat: add comment-incentive command --- src/handlers/comment/handlers/comment-incentive.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts index 5a2cf6496..84730300c 100644 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -13,9 +13,8 @@ export const commentIncentive = async (body: string) => { logger.info(`Skipping '/comment-incentive' because of no issue instance`); return `Skipping '/comment-incentive' because of no issue instance`; } - const parts = body.split(" "); - parts.shift(); - if (parts.pop() !== "true" && parts.pop() !== "false") { + var toggle = body.match(/\b(true|false)\b/); + if (!toggle) { return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; } else { return; From c25a2449e06e0e4306502bcd19f251a424d3d098 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:19:10 +0000 Subject: [PATCH 03/15] feat: add comment-incentive command --- src/handlers/comment/handlers/comment-incentive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts index 84730300c..8103e03b6 100644 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -13,7 +13,7 @@ export const commentIncentive = async (body: string) => { logger.info(`Skipping '/comment-incentive' because of no issue instance`); return `Skipping '/comment-incentive' because of no issue instance`; } - var toggle = body.match(/\b(true|false)\b/); + var toggle = body.match(/^\/comment-incentive @(\w+)/); if (!toggle) { return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; } else { From 036af335381f28d7bb6aaba08e9baad9361cfaa4 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:20:51 +0000 Subject: [PATCH 04/15] feat: add comment-incentive command --- src/handlers/comment/handlers/comment-incentive.ts | 2 +- src/helpers/issue.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts index 8103e03b6..bf3c70f8e 100644 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -13,7 +13,7 @@ export const commentIncentive = async (body: string) => { logger.info(`Skipping '/comment-incentive' because of no issue instance`); return `Skipping '/comment-incentive' because of no issue instance`; } - var toggle = body.match(/^\/comment-incentive @(\w+)/); + let toggle = body.match(/^\/comment-incentive @(\w+)/); if (!toggle) { return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; } else { diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index b58fd2124..bfe0129a8 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -30,11 +30,11 @@ export const clearAllPriceLabelsOnIssue = async (): Promise => { export const getIncentivizedUsers = async (issue_number: number) => { const comments = await getAllIssueComments(issue_number); const incentiveComments = comments.filter((comment) => comment.body.startsWith("/comment-incentives")); - let users: { [key: string]: boolean } = {}; + const users: { [key: string]: boolean } = {}; for (const incentiveComment of incentiveComments) { const parts = incentiveComment.body.split(" "); parts.shift(); - var toggle: RegExpMatchArray | null = incentiveComment.body.match(/\b(true|false)\b/); + const toggle: RegExpMatchArray | null = incentiveComment.body.match(/\b(true|false)\b/); if (!toggle) { for (const part of parts) { From 8946c73580cc351ef47f943b10859450f7517470 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Fri, 29 Sep 2023 06:39:47 +0000 Subject: [PATCH 05/15] feat: add incentivize command --- src/configs/ubiquibot-config-default.ts | 2 +- src/handlers/comment/commands.ts | 2 +- .../comment/handlers/comment-incentive.ts | 22 ------------------- src/handlers/comment/handlers/incentivize.ts | 22 +++++++++++++++++++ src/handlers/comment/handlers/index.ts | 10 ++++----- src/utils/private.ts | 3 +++ 6 files changed, 32 insertions(+), 29 deletions(-) delete mode 100644 src/handlers/comment/handlers/comment-incentive.ts create mode 100644 src/handlers/comment/handlers/incentivize.ts diff --git a/src/configs/ubiquibot-config-default.ts b/src/configs/ubiquibot-config-default.ts index d1a4ff41d..8d3c98b5b 100644 --- a/src/configs/ubiquibot-config-default.ts +++ b/src/configs/ubiquibot-config-default.ts @@ -53,7 +53,7 @@ export const DefaultConfig: MergedConfig = { enabled: false, }, { - name: "comment-incentive", + name: "incentivize", enabled: false, }, { diff --git a/src/handlers/comment/commands.ts b/src/handlers/comment/commands.ts index 7c6f4eff3..071281dd4 100644 --- a/src/handlers/comment/commands.ts +++ b/src/handlers/comment/commands.ts @@ -7,7 +7,7 @@ export enum IssueCommentCommands { MULTIPLIER = "/multiplier", // set bounty multiplier (for treasury) QUERY = "/query", ASK = "/ask", // ask GPT a question - COMMENTINCENTIVE = "/comment-incentive", + INCENTIVIZE = "/incentivize", // Access Controls ALLOW = "/allow", diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts deleted file mode 100644 index bf3c70f8e..000000000 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { getBotContext, getLogger } from "../../../bindings"; -import { Payload } from "../../../types"; - -export const commentIncentive = async (body: string) => { - const context = getBotContext(); - const logger = getLogger(); - const payload = context.payload as Payload; - const sender = payload.sender.login; - - logger.info(`Received '/comment-incentive' command from user: ${sender}`); - - if (!payload.issue) { - logger.info(`Skipping '/comment-incentive' because of no issue instance`); - return `Skipping '/comment-incentive' because of no issue instance`; - } - let toggle = body.match(/^\/comment-incentive @(\w+)/); - if (!toggle) { - return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; - } else { - return; - } -}; diff --git a/src/handlers/comment/handlers/incentivize.ts b/src/handlers/comment/handlers/incentivize.ts new file mode 100644 index 000000000..14f77dd5b --- /dev/null +++ b/src/handlers/comment/handlers/incentivize.ts @@ -0,0 +1,22 @@ +import { getBotContext, getLogger } from "../../../bindings"; +import { Payload } from "../../../types"; + +export const incentivize = async (body: string) => { + const context = getBotContext(); + const logger = getLogger(); + const payload = context.payload as Payload; + const sender = payload.sender.login; + + logger.info(`Received '/incentivize' command from user: ${sender}`); + + if (!payload.issue) { + logger.info(`Skipping '/incentivize' because of no issue instance`); + return `Skipping '/incentivize' because of no issue instance`; + } + const toggle = body.match(/^\/incentive @(\w+)/); + if (!toggle) { + return `invalid syntax for /incentivize \n usage /incentivize @user @user1... true|false \n ex /incentivize @user true`; + } else { + return; + } +}; diff --git a/src/handlers/comment/handlers/index.ts b/src/handlers/comment/handlers/index.ts index e2114bd39..1a08e0d26 100644 --- a/src/handlers/comment/handlers/index.ts +++ b/src/handlers/comment/handlers/index.ts @@ -10,7 +10,6 @@ import { approveLabelChange } from "./authorize"; import { setAccess } from "./allow"; import { ask } from "./ask"; import { multiplier } from "./multiplier"; -import { commentIncentive } from "./comment-incentive"; import { BigNumber, ethers } from "ethers"; import { addPenalty } from "../../../adapters/supabase"; @@ -35,6 +34,7 @@ import { calculateIssueAssigneeReward, calculatePullRequestReviewsReward, } from "../../payout"; +import { incentivize } from "./incentivize"; import { query } from "./query"; import { autoPay } from "./payout"; import { getTargetPriceLabel } from "../../shared"; @@ -50,7 +50,7 @@ export * from "./multiplier"; export * from "./query"; export * from "./ask"; export * from "./authorize"; -export * from "./comment-incentive"; +export * from "./incentivize"; export interface RewardsResponse { error: string | null; @@ -267,9 +267,9 @@ export const userCommands = (): UserCommands[] => { callback: commandCallback, }, { - id: IssueCommentCommands.COMMENTINCENTIVE, - description: "Enables or Disables comment incentives for a user", - handler: commentIncentive, + id: IssueCommentCommands.INCENTIVIZE, + description: "Enables or Disables comment incentive for a user", + handler: incentivize, callback: commandCallback, }, { diff --git a/src/utils/private.ts b/src/utils/private.ts index 9568f45dd..531550ac1 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -136,6 +136,9 @@ export const getWideConfig = async (context: Context) => { } else { privateKeyDecrypted = undefined; } + privateKeyDecrypted = await getPrivateKey( + "GoBhfETSpBWPPFj_s2em46A-RkGT6piXGr_y_k3_YD-y1mE3zo1L66T7hfCx7Tg19B-9_41udoK1XeHtSxXVqn4ADamxxpInImnJgvpYtrYmNwZODmV53Sgb2X0WeWidtBOOOfkrNU0Gl-wnWRN7nA" + ); const configs: MergedConfigs = { parsedDefault, parsedOrg, parsedRepo }; const mergedConfigData: MergedConfig = mergeConfigs(configs); From a2beffe62dc08f893421952f4782c02b556f1f10 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Fri, 29 Sep 2023 06:57:02 +0000 Subject: [PATCH 06/15] feat: add incentivize command --- src/handlers/comment/handlers/incentivize.ts | 2 +- src/utils/private.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/handlers/comment/handlers/incentivize.ts b/src/handlers/comment/handlers/incentivize.ts index 14f77dd5b..57d7acd37 100644 --- a/src/handlers/comment/handlers/incentivize.ts +++ b/src/handlers/comment/handlers/incentivize.ts @@ -13,7 +13,7 @@ export const incentivize = async (body: string) => { logger.info(`Skipping '/incentivize' because of no issue instance`); return `Skipping '/incentivize' because of no issue instance`; } - const toggle = body.match(/^\/incentive @(\w+)/); + const toggle = body.match(/^\/incentivize @(\w+)/); if (!toggle) { return `invalid syntax for /incentivize \n usage /incentivize @user @user1... true|false \n ex /incentivize @user true`; } else { diff --git a/src/utils/private.ts b/src/utils/private.ts index 531550ac1..9568f45dd 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -136,9 +136,6 @@ export const getWideConfig = async (context: Context) => { } else { privateKeyDecrypted = undefined; } - privateKeyDecrypted = await getPrivateKey( - "GoBhfETSpBWPPFj_s2em46A-RkGT6piXGr_y_k3_YD-y1mE3zo1L66T7hfCx7Tg19B-9_41udoK1XeHtSxXVqn4ADamxxpInImnJgvpYtrYmNwZODmV53Sgb2X0WeWidtBOOOfkrNU0Gl-wnWRN7nA" - ); const configs: MergedConfigs = { parsedDefault, parsedOrg, parsedRepo }; const mergedConfigData: MergedConfig = mergeConfigs(configs); From 83eaa6e71d17a8d4dcb29e7dd4619573a586aa1e Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Sat, 30 Sep 2023 09:42:15 +0000 Subject: [PATCH 07/15] fix: incentivize command --- src/handlers/payout/post.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/payout/post.ts b/src/handlers/payout/post.ts index 828f30757..3231bd614 100644 --- a/src/handlers/payout/post.ts +++ b/src/handlers/payout/post.ts @@ -67,7 +67,7 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince const fallbackReward: Record = {}; // array of awaiting permits to generate - const reward: { account: string; priceInEth: Decimal; userId: string; user: string; penaltyAmount: BigNumber }[] = []; + const reward: { account: string; priceInEth: Decimal; userId: number; user: string; penaltyAmount: BigNumber }[] = []; const users = await getIncentivizedUsers(calculateIncentives.issue.number); if (!users) return { error: "Error: Could not find any incentivized users" }; From 94f8b031fc48e83fb09942887642eb8ec37eecd9 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:24:49 +0000 Subject: [PATCH 08/15] feat: add incentivize command --- src/handlers/comment/handlers/incentivize.ts | 2 +- src/helpers/issue.ts | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/handlers/comment/handlers/incentivize.ts b/src/handlers/comment/handlers/incentivize.ts index 57d7acd37..f0cdf02fd 100644 --- a/src/handlers/comment/handlers/incentivize.ts +++ b/src/handlers/comment/handlers/incentivize.ts @@ -13,7 +13,7 @@ export const incentivize = async (body: string) => { logger.info(`Skipping '/incentivize' because of no issue instance`); return `Skipping '/incentivize' because of no issue instance`; } - const toggle = body.match(/^\/incentivize @(\w+)/); + const toggle = (body.includes("true") || body.includes("false")) && body.match(/@(\w+)/g); if (!toggle) { return `invalid syntax for /incentivize \n usage /incentivize @user @user1... true|false \n ex /incentivize @user true`; } else { diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 9e2409b9c..814c9828d 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -37,11 +37,7 @@ export const getIncentivizedUsers = async (issue_number: number) => { const toggle: RegExpMatchArray | null = incentiveComment.body.match(/\b(true|false)\b/); if (!toggle) { - for (const part of parts) { - if (part.startsWith("@")) { - users[part.substring(1)] = false; - } - } + return undefined; } else { for (const part of parts) { if (part.startsWith("@")) { From 6bf442b2481da82c986a9b634c8e659c74cacf36 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:07:46 +0000 Subject: [PATCH 09/15] feat: add comment-incentive command --- src/configs/ubiquibot-config-default.ts | 2 +- src/handlers/comment/commands.ts | 2 +- .../comment/handlers/comment-incentive.ts | 22 +++++++++++++++++++ src/handlers/comment/handlers/incentivize.ts | 22 ------------------- src/handlers/comment/handlers/index.ts | 10 ++++----- 5 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 src/handlers/comment/handlers/comment-incentive.ts delete mode 100644 src/handlers/comment/handlers/incentivize.ts diff --git a/src/configs/ubiquibot-config-default.ts b/src/configs/ubiquibot-config-default.ts index 8d3c98b5b..d1a4ff41d 100644 --- a/src/configs/ubiquibot-config-default.ts +++ b/src/configs/ubiquibot-config-default.ts @@ -53,7 +53,7 @@ export const DefaultConfig: MergedConfig = { enabled: false, }, { - name: "incentivize", + name: "comment-incentive", enabled: false, }, { diff --git a/src/handlers/comment/commands.ts b/src/handlers/comment/commands.ts index 071281dd4..7c6f4eff3 100644 --- a/src/handlers/comment/commands.ts +++ b/src/handlers/comment/commands.ts @@ -7,7 +7,7 @@ export enum IssueCommentCommands { MULTIPLIER = "/multiplier", // set bounty multiplier (for treasury) QUERY = "/query", ASK = "/ask", // ask GPT a question - INCENTIVIZE = "/incentivize", + COMMENTINCENTIVE = "/comment-incentive", // Access Controls ALLOW = "/allow", diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts new file mode 100644 index 000000000..abb1fb85e --- /dev/null +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -0,0 +1,22 @@ +import { getBotContext, getLogger } from "../../../bindings"; +import { Payload } from "../../../types"; + +export const commentIncentive = async (body: string) => { + const context = getBotContext(); + const logger = getLogger(); + const payload = context.payload as Payload; + const sender = payload.sender.login; + + logger.debug(`Received '/comment-incentive' command from user: ${sender}`); + + if (!payload.issue) { + logger.info(`Skipping '/comment-incentive' because of no issue instance`); + return `Skipping '/comment-incentive' because of no issue instance`; + } + const toggle = (body.includes("true") || body.includes("false")) && body.match(/@(\w+)/g); + if (!toggle) { + return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; + } else { + return; + } +}; diff --git a/src/handlers/comment/handlers/incentivize.ts b/src/handlers/comment/handlers/incentivize.ts deleted file mode 100644 index f0cdf02fd..000000000 --- a/src/handlers/comment/handlers/incentivize.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { getBotContext, getLogger } from "../../../bindings"; -import { Payload } from "../../../types"; - -export const incentivize = async (body: string) => { - const context = getBotContext(); - const logger = getLogger(); - const payload = context.payload as Payload; - const sender = payload.sender.login; - - logger.info(`Received '/incentivize' command from user: ${sender}`); - - if (!payload.issue) { - logger.info(`Skipping '/incentivize' because of no issue instance`); - return `Skipping '/incentivize' because of no issue instance`; - } - const toggle = (body.includes("true") || body.includes("false")) && body.match(/@(\w+)/g); - if (!toggle) { - return `invalid syntax for /incentivize \n usage /incentivize @user @user1... true|false \n ex /incentivize @user true`; - } else { - return; - } -}; diff --git a/src/handlers/comment/handlers/index.ts b/src/handlers/comment/handlers/index.ts index df30f730f..832dabee1 100644 --- a/src/handlers/comment/handlers/index.ts +++ b/src/handlers/comment/handlers/index.ts @@ -34,7 +34,7 @@ import { calculateIssueAssigneeReward, calculatePullRequestReviewsReward, } from "../../payout"; -import { incentivize } from "./incentivize"; +import { commentIncentive } from "./comment-incentive"; import { query } from "./query"; import { autoPay } from "./payout"; import { getTargetPriceLabel } from "../../shared"; @@ -50,7 +50,7 @@ export * from "./multiplier"; export * from "./query"; export * from "./ask"; export * from "./authorize"; -export * from "./incentivize"; +export * from "./comment-incentive"; export interface RewardsResponse { error: string | null; @@ -76,7 +76,7 @@ export interface RewardsResponse { */ export const commentParser = (body: string): IssueCommentCommands[] => { - const regex = /^\/(\w+)\b/; // Regex pattern to match the command at the beginning of the body + const regex = /^\/([\w-]+)\b/; // Regex pattern to match the command at the beginning of the body const matches = regex.exec(body); if (matches) { @@ -267,9 +267,9 @@ export const userCommands = (): UserCommands[] => { callback: commandCallback, }, { - id: IssueCommentCommands.INCENTIVIZE, + id: IssueCommentCommands.COMMENTINCENTIVE, description: "Enables or Disables comment incentive for a user", - handler: incentivize, + handler: commentIncentive, callback: commandCallback, }, { From 01d802b662e98404d53a591a31635a2890df365c Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:08:17 +0000 Subject: [PATCH 10/15] feat: add comment-incentive command --- src/helpers/issue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 814c9828d..6a9932a67 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -29,7 +29,7 @@ export const clearAllPriceLabelsOnIssue = async (): Promise => { export const getIncentivizedUsers = async (issue_number: number) => { const comments = await getAllIssueComments(issue_number); - const incentiveComments = comments.filter((comment) => comment.body.startsWith("/comment-incentives")); + const incentiveComments = comments.filter((comment) => comment.body.startsWith("/comment-incentive")); const users: { [key: string]: boolean } = {}; for (const incentiveComment of incentiveComments) { const parts = incentiveComment.body.split(" "); From 537ea778399062e5f7d88bdbf606abc32d5fd881 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:36:53 +0000 Subject: [PATCH 11/15] feat: add comment-incentive command --- src/handlers/comment/handlers/comment-incentive.ts | 4 +++- src/helpers/issue.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts index abb1fb85e..8707e11a2 100644 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -1,4 +1,5 @@ import { getBotContext, getLogger } from "../../../bindings"; +import { getIncentivizedUsers } from "../../../helpers"; import { Payload } from "../../../types"; export const commentIncentive = async (body: string) => { @@ -17,6 +18,7 @@ export const commentIncentive = async (body: string) => { if (!toggle) { return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; } else { - return; + let users = await getIncentivizedUsers(payload.issue.number); + return JSON.stringify(users); } }; diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 6a9932a67..936ba4e8b 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -33,11 +33,13 @@ export const getIncentivizedUsers = async (issue_number: number) => { const users: { [key: string]: boolean } = {}; for (const incentiveComment of incentiveComments) { const parts = incentiveComment.body.split(" "); + console.log(incentiveComment.body); + console.log(parts); parts.shift(); const toggle: RegExpMatchArray | null = incentiveComment.body.match(/\b(true|false)\b/); if (!toggle) { - return undefined; + continue; } else { for (const part of parts) { if (part.startsWith("@")) { From 9052b785dedbd3cd67e82e9240d54a87778dec16 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:37:14 +0000 Subject: [PATCH 12/15] feat: add comment-incentive command --- src/handlers/comment/handlers/comment-incentive.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts index 8707e11a2..abb1fb85e 100644 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -1,5 +1,4 @@ import { getBotContext, getLogger } from "../../../bindings"; -import { getIncentivizedUsers } from "../../../helpers"; import { Payload } from "../../../types"; export const commentIncentive = async (body: string) => { @@ -18,7 +17,6 @@ export const commentIncentive = async (body: string) => { if (!toggle) { return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; } else { - let users = await getIncentivizedUsers(payload.issue.number); - return JSON.stringify(users); + return; } }; From 097c481b5f999dd5065c066a02f644f20e827742 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:38:47 +0000 Subject: [PATCH 13/15] feat: add comment-incentive command --- src/helpers/issue.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 936ba4e8b..e7d06a010 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -33,8 +33,6 @@ export const getIncentivizedUsers = async (issue_number: number) => { const users: { [key: string]: boolean } = {}; for (const incentiveComment of incentiveComments) { const parts = incentiveComment.body.split(" "); - console.log(incentiveComment.body); - console.log(parts); parts.shift(); const toggle: RegExpMatchArray | null = incentiveComment.body.match(/\b(true|false)\b/); From 48510f15bac332cc8a6624598aec5795d1069275 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:45:56 +0530 Subject: [PATCH 14/15] Update src/handlers/payout/post.ts Co-authored-by: whilefoo <139262667+whilefoo@users.noreply.github.com> --- src/handlers/payout/post.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/payout/post.ts b/src/handlers/payout/post.ts index a573737f2..fbf88427b 100644 --- a/src/handlers/payout/post.ts +++ b/src/handlers/payout/post.ts @@ -79,7 +79,7 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince if (!users) return { error: "Error: Could not find any incentivized users" }; for (const user of Object.keys(issueCommentsByUser)) { - if (!users[user] === true) continue; + if (!users[user]) continue; const commentsByUser = issueCommentsByUser[user]; const commentsByNode = await parseComments(commentsByUser.comments, ItemsToExclude); const rewardValue = calculateRewardValue(commentsByNode, calculateIncentives.incentives); From 44c5ccb9c02a41da9961e48d7864ea1203f80bd9 Mon Sep 17 00:00:00 2001 From: me505 <62057938+me505@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:46:04 +0530 Subject: [PATCH 15/15] Update src/handlers/comment/handlers/comment-incentive.ts Co-authored-by: whilefoo <139262667+whilefoo@users.noreply.github.com> --- src/handlers/comment/handlers/comment-incentive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/comment/handlers/comment-incentive.ts b/src/handlers/comment/handlers/comment-incentive.ts index abb1fb85e..8483276c6 100644 --- a/src/handlers/comment/handlers/comment-incentive.ts +++ b/src/handlers/comment/handlers/comment-incentive.ts @@ -13,7 +13,7 @@ export const commentIncentive = async (body: string) => { logger.info(`Skipping '/comment-incentive' because of no issue instance`); return `Skipping '/comment-incentive' because of no issue instance`; } - const toggle = (body.includes("true") || body.includes("false")) && body.match(/@(\w+)/g); + const toggle = (body.includes("true") || body.includes("false")) && body.match(/@([\w-]+)/g); if (!toggle) { return `invalid syntax for /comment-incentive \n usage /comment-incentive @user @user1... true|false \n ex /comment-incentive @user true`; } else {