Browse Source

OpeningFilled, OpeningAdded, WorkerRewardAmountUpdated

singulart 2 years ago
parent
commit
88f151edd0

+ 7 - 0
scripts/wg-bot/src/joystream/api_extension.ts

@@ -0,0 +1,7 @@
+import { IOpening } 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)
+}

+ 47 - 4
scripts/wg-bot/src/joystream/discord.ts

@@ -1,5 +1,7 @@
 import { EventRecord} from '@polkadot/types/interfaces'
 import { getWorker, getMember, getMint, getEvents, getBlockHash } from '../lib/api';
+import { getOpening } from './api_extension';
+
 import { wgEvents, workingGroups, joystreamBlue } from '../config'
 import Discord from 'discord.js';
 import { ApiPromise } from '@polkadot/api';
@@ -22,20 +24,61 @@ export const processBlock = async (api: ApiPromise, client: Discord.Client, bloc
             if(method === 'MintCapacityChanged') {
                 const mintId = (data[0] as u32).toNumber()
                 const minted = (data[1] as u32).toNumber()
-                const mint = await getMint(api, undefined, mintId)
+                const mint = (await getMint(api, hash, mintId)).capacity
 
                 const exampleEmbed = new Discord.MessageEmbed()
                 .setColor(joystreamBlue) 
                 .setTitle(`💰 💵 💸 💴 💶 ${formatBalance(minted, {withUnit: 'JOY'})} minted to the Treasury 💰 💵 💸 💴 💶 `)
                 .addFields(
-                  { name: 'Balance', value: mint.capacity + "", inline: true },
+                  { name: 'Balance', value: formatBalance(mint, {withUnit: 'JOY'}), inline: true },
+                  { name: 'Block', value: blockNumber + "", inline: true },
+                  { name: 'Tx', value: value.hash.toString(), inline: true },
+                )
+                .setTimestamp();
+                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 exampleEmbed = new Discord.MessageEmbed()
+                .setColor(joystreamBlue) 
+                .setTitle(`Apply for new Opening!`)
+                .setDescription(opening)
+                .addFields(
+                //   { name: 'Opening', value: , inline: true },
                   { name: 'Block', value: blockNumber + "", inline: true },
                   { name: 'Tx', value: value.hash.toString(), inline: true },
                 )
                 .setTimestamp();
                 channel.send({ embeds: [exampleEmbed] });    
-              }
-          } else {
+            } else if (method === 'OpeningFilled') {
+                const openingId = (data[0] as u32).toNumber()
+                const opening = (await getOpening(api, hash, openingId)).human_readable_text.toJSON()
+                console.log(opening);
+                const exampleEmbed = new Discord.MessageEmbed()
+                .setColor(joystreamBlue) 
+                .setTitle(`XXXX was hired as ${JSON.parse(opening).job.title} 🎉 🥳 👏🏻`)
+                .setDescription(opening)
+                .addFields(
+                    { name: 'Block', value: blockNumber + "", inline: true },
+                    { name: 'Tx', value: value.hash.toString(), inline: true },
+                )
+                .setTimestamp();
+                channel.send({ embeds: [exampleEmbed] });
+            } else if (method === 'WorkerRewardAmountUpdated') {
+                const workerId = (data[0] as u32).toNumber()
+                const worker = (await getWorker(api, section, hash, workerId)) 
+                const member = (await getMember(api, worker.member_id))
+                const exampleEmbed = new Discord.MessageEmbed()
+                .setColor(joystreamBlue) 
+                .setTitle(`💰💰💰 Salary of ${member.handle} updated`)
+                .addFields(
+                    { name: 'Block', value: blockNumber + "", inline: true },
+                    { name: 'Tx', value: value.hash.toString(), inline: true },
+                )
+                .setTimestamp();
+                channel.send({ embeds: [exampleEmbed] });
+            }
+  } else {
               console.log(`Channel not configured for ${section}`);
           }
       }

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

@@ -5,7 +5,9 @@ import {processBlock} from './joystream/discord'
 import { workingGroups } from './config'
 
 const eventsMapping = {
-    'MintCapacityChanged': 4211575
+    'MintCapacityChanged': 4211575,
+    'OpeningFilled': 4206250,
+    'WorkerRewardAmountUpdated': 4222426
 }