Skip to content

Commit

Permalink
allow to run without discord
Browse files Browse the repository at this point in the history
  • Loading branch information
mrq1911 committed Dec 12, 2024
1 parent 7ebd64b commit d126f2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export async function initApi(rpc) {
provider = new WsProvider(rpc);
_api = await ApiPromise.create({provider});
initialized = true;
const version = await _api.query.system.lastRuntimeUpgrade();
const {specVersion, specName} = version.toJSON();
console.log(`connected to ${specName}/${specVersion} on ${rpc}`);
}

export async function disconnect() {
Expand Down
12 changes: 8 additions & 4 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import {endpoints} from "./endpoints.js";
async function main() {
console.log('🐍⌚');
console.log('snakewatch', sha);

await initApi(rpc);
const {rpc: {system}} = api();
const [chain, version] = await Promise.all([system.chain(), system.version()]);
console.log(`connected to ${rpc} (${chain} ${version})`);
await initDiscord(token, channel);

if (!token || !channel) {
console.log('missing discord token or channel');
console.log('discord disabled');
} else {
await initDiscord(token, channel);
}

await endpoints.start();

Expand Down
3 changes: 3 additions & 0 deletions src/utils/assethub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ async function api() {
if (!_api && ahRpc) {
const provider = new WsProvider(ahRpc);
_api = await ApiPromise.create({provider});
const version = await _api.query.system.lastRuntimeUpgrade();
const {specVersion, specName} = version.toJSON();
console.log(`connected to ${specName}/${specVersion} on ${ahRpc}`);
}
return _api;
}
Expand Down

0 comments on commit d126f2a

Please sign in to comment.