Forráskód Böngészése

OpeningAdded improved

singulart 2 éve
szülő
commit
9928c3ccc7

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

@@ -1,7 +1,12 @@
-import { IOpening } from "@joystream/types/hiring";
+import { OpeningOf } from "@joystream/types/augment-codec/all";
+import { Opening, OpeningId } from "@joystream/types/hiring";
 import { ApiPromise } from "@polkadot/api";
 import { Hash } from "@polkadot/types/interfaces";
 
-export const getOpening = async (api: ApiPromise, hash: Hash, openingId: number): Promise<IOpening> => {
-    return api.query.hiring.openingById.at(hash, openingId)
+export const getOpening = async (api: ApiPromise, group: string, hash: Hash, openingId: number): Promise<OpeningOf> => {
+    return api.query[group].openingById.at(hash, openingId)
+}
+
+export const getHiringOpening = async (api: ApiPromise, hash: Hash, openingId: OpeningId): Promise<Opening> => {
+    return (await api.query.hiring.openingById.at(hash, openingId))
 }

+ 15 - 7
scripts/wg-bot/src/joystream/discord.ts

@@ -1,6 +1,6 @@
 import { EventRecord } from '@polkadot/types/interfaces'
 import { getWorker, getMember, getMint, getEvents, getBlockHash } from '../lib/api';
-import { getOpening } from './api_extension';
+import { getHiringOpening, getOpening } from './api_extension';
 
 import { wgEvents, workingGroups, joystreamBlue } from '../config'
 import Discord from 'discord.js';
@@ -39,13 +39,18 @@ export const processBlock = async (api: ApiPromise, client: Discord.Client, bloc
                     channel.send({ embeds: [exampleEmbed] });
                 } else if (method === 'OpeningAdded') {
                     const openingId = (data[0] as u32).toNumber()
-                    const opening = (await getOpening(api, hash, openingId)).human_readable_text.toJSON()
+                    const openingObject = await getOpening(api, section, hash, openingId)
+                    const hiringOpening = await getHiringOpening(api, hash, openingObject.hiring_opening_id)
+                    const opening = JSON.parse(hiringOpening.human_readable_text.toString())
                     const exampleEmbed = new Discord.MessageEmbed()
                         .setColor(joystreamBlue)
-                        .setTitle(`Apply for new Opening!`)
-                        .setDescription(opening)
+                        .setTitle(`⛩ ${opening.headline} ⛩`)
+                        .setDescription(opening.job.description)
                         .addFields(
-                            //   { name: 'Opening', value: , 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 },
+                            { name: 'Created By', value: opening.creator.membership.handle, inline: true },
                             { name: 'Block', value: blockNumber + "", inline: true },
                             { name: 'Tx', value: value.hash.toString(), inline: true },
                         )
@@ -56,10 +61,13 @@ export const processBlock = async (api: ApiPromise, client: Discord.Client, bloc
                     const workerId = Object.values(JSON.parse(data[1].toString()))[0] as number
                     const worker = (await getWorker(api, section, hash, workerId))
                     const member = (await getMember(api, worker.member_id))
-                    const opening = (await getOpening(api, hash, openingId)).human_readable_text.toJSON()
+                    const openingObject = await getOpening(api, section, hash, openingId)
+                    const hiringOpening = await getHiringOpening(api, hash, openingObject.hiring_opening_id)
+                    const opening = JSON.parse(hiringOpening.human_readable_text.toString())
                     const exampleEmbed = new Discord.MessageEmbed()
                         .setColor(joystreamBlue)
-                        .setTitle(`🎉 🥳 👏🏻 ${member.handle} was hired as ${JSON.parse(opening).job.title} 🎉 🥳 👏🏻`)
+                        .setTitle(`🎉 🥳 👏🏻 ${member.handle} was hired as ${opening.job.title} 🎉 🥳 👏🏻`)
+                        // .setTitle(`🎉 🥳 👏🏻 ${member.handle} was hired as !!!!!!!!!!!!!!!!!!!!!!!!!! 🎉 🥳 👏🏻`)
                         .addFields(
                             { name: 'Block', value: blockNumber + "", inline: true },
                             { name: 'Tx', value: value.hash.toString(), inline: true },

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

@@ -7,6 +7,7 @@ import { workingGroups } from './config'
 const eventsMapping = {
     'MintCapacityChanged': 4211575,
     'OpeningFilled': 4206250,
+    'OpeningAdded': 4224720,
     'WorkerRewardAmountUpdated': 4222426
 }