Selaa lähdekoodia

using api submodule

singulart 2 vuotta sitten
vanhempi
commit
f974fd7491
3 muutettua tiedostoa jossa 13 lisäystä ja 10 poistoa
  1. 3 0
      scripts/wg-bot/README.md
  2. 10 10
      scripts/wg-bot/src/index.ts
  3. 0 0
      scripts/wg-bot/src/joystream/discord.ts

+ 3 - 0
scripts/wg-bot/README.md

@@ -7,5 +7,8 @@ Supports new Working Groups introduced in Olympia network. (Add context link)
 
 # Installation
 
+Build with `yarn`
+
+Run using `TOKEN=<BOT TOKEN> RPC_ENDPOINT=wss://rome-rpc-endpoint.joystream.org:9944 ts-node src/index.ts`
 
 # Troubleshooting

+ 10 - 10
scripts/wg-bot/src/index.ts

@@ -1,8 +1,11 @@
 import { connectUpstream } from './joystream/ws'
 import { ApiPromise } from '@polkadot/api'
-import { BlockHash, EventRecord, Header } from '@polkadot/types/interfaces'
+import { BlockHash, Event, EventRecord, Header } from '@polkadot/types/interfaces'
 import { wgEvents, workingGroups } from './config'
 import Discord, { Intents } from 'discord.js';
+import { getWorker, getMember, getEvents, getBlockHash } from './lib/api';
+import { Vec } from '@polkadot/types';
+
 
 const TYPES_AVAILABLE = [] as const
 type ApiType = typeof TYPES_AVAILABLE[number]
@@ -23,13 +26,13 @@ const discordBotToken = process.env.TOKEN || undefined // environment variable T
     await client.login(discordBotToken); 
     console.log('Bot logged in successfully');    
     
-    connectUpstream().then( async (api: any) => {
+    connectUpstream().then( async (api: ApiPromise) => {
         api.rpc.chain.subscribeNewHeads(async (header: Header) => {
-          const id = +header.number
-          const hash = await getBlockHash(api, id)
-          const blockEvents = await api.query.system.events.at(hash)
-          blockEvents.forEach(async ({ event }: EventRecord) => {
-            let { section, method, data } = event
+          const id = +header.number;
+          const hash = await getBlockHash(api, id);
+          const blockEvents = await getEvents(api, hash);
+          blockEvents.forEach(async (value: EventRecord, index: number, array: EventRecord[]) => {
+            let { section, method, data } = value.event;
             if (wgEvents.includes(method) && Object.keys(workingGroups).includes(section)) {
                 console.log(section);
                 console.log(method);
@@ -54,6 +57,3 @@ const discordBotToken = process.env.TOKEN || undefined // environment variable T
         })  
       })
 })()
-
-const getBlockHash = (api: ApiPromise, blockId: number) =>
-  api.rpc.chain.getBlockHash(blockId).then((hash: BlockHash) => hash.toString())

+ 0 - 0
scripts/wg-bot/src/joystream/discord.ts