Explorar el Código

AppliedOnOpening added

singulart hace 2 años
padre
commit
c88d9544ff

+ 1 - 1
scripts/wg-bot/src/config.ts

@@ -13,7 +13,7 @@ export const workingGroups = {
 
 
 export const wgEvents = [
-    'AcceptedApplications', 
+    // 'AcceptedApplications', internal event ?
     'ApplicationTerminated',
     'ApplicationWithdrawn',
     'AppliedOnOpening',

+ 11 - 3
scripts/wg-bot/src/joystream/api_extension.ts

@@ -1,5 +1,5 @@
-import { OpeningOf } from "@joystream/types/augment-codec/all";
-import { Opening, OpeningId } from "@joystream/types/hiring";
+import { ApplicationOf, OpeningOf } from "@joystream/types/augment-codec/all";
+import { Application, ApplicationId, Opening, OpeningId } from "@joystream/types/hiring";
 import { ApiPromise } from "@polkadot/api";
 import { Hash } from "@polkadot/types/interfaces";
 
@@ -9,4 +9,12 @@ export const getOpening = async (api: ApiPromise, group: string, hash: Hash, ope
 
 export const getHiringOpening = async (api: ApiPromise, hash: Hash, openingId: OpeningId): Promise<Opening> => {
     return (await api.query.hiring.openingById.at(hash, openingId))
-}
+}
+
+export const getApplication = async (api: ApiPromise, group: string, hash: Hash, applicationId: ApplicationId): Promise<ApplicationOf> => {
+    return api.query[group].applicationById.at(hash, applicationId)
+}
+
+export const getHiringApplication = async (api: ApiPromise, group: string, hash: Hash, applicationId: ApplicationId): Promise<Application> => {
+    return api.query.hiring.applicationById.at(hash, applicationId)
+}

+ 27 - 3
scripts/wg-bot/src/joystream/discord.ts

@@ -1,13 +1,13 @@
 import { EventRecord } from '@polkadot/types/interfaces'
 import { getWorker, getMember, getMint, getEvents, getBlockHash, getWorkerReward } from '../lib/api';
-import { getHiringOpening, getOpening } from './api_extension';
-import { getLeaderSetEmbed, getLeaderUnsetEmbed, getMintCapacityChangedEmbed, getOpeningAddedEmbed, getOpeningFilledEmbed, getWorkerExitedEmbed, getWorkerRewardAmountUpdatedEmbed, getWorkerTerminatedEmbed } from './embeds';
+import { getApplication, getHiringApplication, getHiringOpening, getOpening } from './api_extension';
+import { getApplicationTerminatedEmbed, getApplicationWithdrawnEmbed, getAppliedOnOpeningEmbed, getLeaderSetEmbed, getLeaderUnsetEmbed, getMintCapacityChangedEmbed, getOpeningAddedEmbed, getOpeningFilledEmbed, getWorkerExitedEmbed, getWorkerRewardAmountUpdatedEmbed, getWorkerTerminatedEmbed } from './embeds';
 
 import { wgEvents, workingGroups } from '../config'
 import Discord from 'discord.js';
 import { ApiPromise } from '@polkadot/api';
 import { MintBalanceOf, MintId } from '@joystream/types/mint';
-import { OpeningId } from '@joystream/types/hiring';
+import { ApplicationId, OpeningId } from '@joystream/types/hiring';
 import { RationaleText, WorkerId } from '@joystream/types/working-group';
 
 export const processBlock = async (api: ApiPromise, client: Discord.Client, blockNumber: number) => {
@@ -21,6 +21,30 @@ export const processBlock = async (api: ApiPromise, client: Discord.Client, bloc
             const channel: Discord.TextChannel = client.channels.cache.get(workingGroups[section]) as Discord.TextChannel;
             if (channel) {
                 switch(method) {
+                    case "ApplicationTerminated":
+                        const id = data[0] as ApplicationId
+                        const terminatedApplication = await getApplication(api, section, hash, id);
+                        const memberTerminatedApplication = await getMember(api, terminatedApplication.member_id);
+                        channel.send({ embeds: [getApplicationTerminatedEmbed(id, terminatedApplication, memberTerminatedApplication, blockNumber, value)] });
+                        break;
+                    case "ApplicationWithdrawn":
+                        const withdrawnId = data[0] as ApplicationId
+                        const withdrawnApplication = await getApplication(api, section, hash, withdrawnId);
+                        const memberWithdrawnApplication = await getMember(api, withdrawnApplication.member_id);
+                        channel.send({ embeds: [getApplicationWithdrawnEmbed(id, withdrawnApplication, memberWithdrawnApplication, blockNumber, value)] });
+                        break;
+                    case "AppliedOnOpening":
+                        const applicationOpeningId = data[0] as OpeningId;
+                        const applicationId = data[1] as ApplicationId;
+                        const application = await getApplication(api, section, hash, applicationId);
+                        const hiringApplication = await getHiringApplication(api, section, hash, applicationId);
+                        const hiringApplicationText = JSON.parse(hiringApplication.human_readable_text.toString());
+                        const openingObject = await getOpening(api, section, hash, applicationOpeningId);
+                        const hiringOpening = await getHiringOpening(api, hash, openingObject.hiring_opening_id);
+                        const openingText = JSON.parse(hiringOpening.human_readable_text.toString());
+                        const applicant = await getMember(api, application.member_id);
+                        channel.send({ embeds: [getAppliedOnOpeningEmbed(applicationId, application, openingText, hiringApplicationText, applicant, blockNumber, value)] });
+                        break;
                     case "MintCapacityChanged":
                         const mintId = (data[0] as MintId).toNumber();
                         const minted = (data[1] as MintBalanceOf).toNumber();

+ 46 - 1
scripts/wg-bot/src/joystream/embeds.ts

@@ -3,7 +3,7 @@ import { formatBalance } from '@polkadot/util';
 import { u128 } from '@polkadot/types';
 import { EventRecord } from '@polkadot/types/interfaces';
 import Discord from 'discord.js';
-import { Membership, OpeningOf, RewardRelationship } from '@joystream/types/augment-codec/all';
+import { ApplicationId, ApplicationOf, Membership, OpeningOf, RewardRelationship } from '@joystream/types/augment-codec/all';
 
 
 export const getMintCapacityChangedEmbed = (minted: number, mint: u128, blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
@@ -26,6 +26,7 @@ export const getOpeningAddedEmbed = (opening: any, openingObject: OpeningOf, blo
         .setTitle(`⛩ ${opening.headline} ⛩`)
         .setDescription(opening.job.description)
         .addFields(
+            { name: 'ID', value: openingObject.hiring_opening_id + "", inline: true },
             { name: 'Reward', value: opening.reward, inline: true },
             { name: 'Application Stake', value: openingObject.policy_commitment.application_staking_policy.unwrap().amount.toString() || 'Not Set', inline: true },
             { name: 'Role Stake', value: openingObject.policy_commitment.role_staking_policy.unwrap().amount.toString() || 'Not Set', inline: true },
@@ -48,6 +49,23 @@ export const getOpeningFilledEmbed = (opening: any, member: Membership, blockNum
         .setTimestamp();
 }
 
+export const getAppliedOnOpeningEmbed = (applicationId: ApplicationId, application: ApplicationOf, 
+    openingText: any, hiringApplicationText: any, applicant: Membership, blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
+
+    return new Discord.MessageEmbed()
+        .setColor(joystreamBlue)
+        .setTitle(`🏛 ${applicant.handle} applied to opening ${openingText.job.title}`)
+        .setDescription(hiringApplicationText['About you']['What makes you a good fit for the job?'])
+        .addFields(
+            { name: 'Application ID', value: applicationId.toString(), inline: true},
+            { name: 'Opening', value:  openingText.headline, inline: true},
+            { name: 'Applicant', value: `[${application.member_id}] ${hiringApplicationText['About you']['Your name']}`, inline: true},
+            { name: 'Block', value: blockNumber + "", inline: true },
+            { name: 'Tx', value: event.hash.toString(), inline: true },
+        )
+        .setTimestamp();
+}
+
 
 export const getWorkerRewardAmountUpdatedEmbed = (reward: RewardRelationship, member: Membership, 
     blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
@@ -110,4 +128,31 @@ export const getWorkerExitedOrTerminatedEmbed = (action: string, member: Members
             { name: 'Tx', value: event.hash.toString(), inline: true },
         )
         .setTimestamp();
+}
+
+export const getApplicationTerminatedEmbed = (applicationId: ApplicationId, application: ApplicationOf, member: Membership,
+    blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
+
+    return getApplicationTerminatedOrWithdrawEmbed("terminated", applicationId, application, member, blockNumber, event);
+}
+
+export const getApplicationWithdrawnEmbed = (applicationId: ApplicationId, application: ApplicationOf, member: Membership,
+    blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
+
+    return getApplicationTerminatedOrWithdrawEmbed("withdrawn", applicationId, application, member, blockNumber, event);
+}
+
+export const getApplicationTerminatedOrWithdrawEmbed = (action: string, applicationId: ApplicationId, application: ApplicationOf, member: Membership,
+    blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
+
+    return new Discord.MessageEmbed()
+        .setColor(joystreamBlue)
+        .setTitle(`🏛 Application of ${member.handle} ${action}`)
+        .addFields(
+            { name: 'Application ID', value: applicationId.toString(), inline: true },
+            { name: 'Opening ID', value: application.opening_id.toString(), inline: true },
+            { name: 'Block', value: blockNumber + "", inline: true },
+            { name: 'Tx', value: event.hash.toString(), inline: true },
+        )
+        .setTimestamp();
 }

+ 2 - 1
scripts/wg-bot/src/simulate.ts

@@ -8,7 +8,8 @@ const eventsMapping = {
     'MintCapacityChanged': 4211575,
     'OpeningFilled': 4206250,
     'OpeningAdded': 4224720,
-    'WorkerRewardAmountUpdated': 4222426
+    'WorkerRewardAmountUpdated': 4222426,
+    'AppliedOnOpening': 4252114,
 }