|
@@ -1,15 +1,11 @@
|
|
import { connectUpstream } from './joystream/ws'
|
|
import { connectUpstream } from './joystream/ws'
|
|
import { ApiPromise } from '@polkadot/api'
|
|
import { ApiPromise } from '@polkadot/api'
|
|
-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';
|
|
|
|
|
|
+import { Header } from '@polkadot/types/interfaces'
|
|
|
|
+import Discord, { Intents } from 'discord.js'
|
|
|
|
+import {processBlock} from './joystream/discord'
|
|
|
|
+import { workingGroups } from './config'
|
|
|
|
|
|
|
|
|
|
-const TYPES_AVAILABLE = [] as const
|
|
|
|
-type ApiType = typeof TYPES_AVAILABLE[number]
|
|
|
|
-
|
|
|
|
const discordBotToken = process.env.TOKEN || undefined // environment variable TOKEN must be set
|
|
const discordBotToken = process.env.TOKEN || undefined // environment variable TOKEN must be set
|
|
|
|
|
|
;(async () => {
|
|
;(async () => {
|
|
@@ -29,31 +25,7 @@ const discordBotToken = process.env.TOKEN || undefined // environment variable T
|
|
connectUpstream().then( async (api: ApiPromise) => {
|
|
connectUpstream().then( async (api: ApiPromise) => {
|
|
api.rpc.chain.subscribeNewHeads(async (header: Header) => {
|
|
api.rpc.chain.subscribeNewHeads(async (header: Header) => {
|
|
const id = +header.number;
|
|
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);
|
|
|
|
- console.log(data.toJSON());
|
|
|
|
-
|
|
|
|
- const channel: Discord.TextChannel = client.channels.cache.get(workingGroups[section]) as Discord.TextChannel;
|
|
|
|
- if(channel) {
|
|
|
|
- const exampleEmbed = new Discord.MessageEmbed()
|
|
|
|
- .setColor('#4038FF') // official joystream blue, see https://www.joystream.org/brand/guides/
|
|
|
|
- .setTitle('Working Group Update')
|
|
|
|
- .setDescription('//TODO')
|
|
|
|
- .addFields(
|
|
|
|
- { name: 'Data', value: data.toString(), inline: true },
|
|
|
|
- )
|
|
|
|
- .setTimestamp();
|
|
|
|
- channel.send({ embeds: [exampleEmbed] });
|
|
|
|
- } else {
|
|
|
|
- console.log(`Channel not configured for ${section}`);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ await processBlock(api, client, id);
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})()
|
|
})()
|