Current bot.js file for Session Bot

whoami 3 years ago
parent 6de737fd9b
commit 907676a905

@ -0,0 +1,98 @@
const fs = require("fs");
const rp = require("request-promise");
const fetch = require("node-fetch");
const request = require("request");
const SessionClient = require("./session-client.js");
const { existsSync, readFileSync, writeFileSync, unlinkSync, createWriteStream } = fs;
const { execSync } = requrie("child_process");
const client = new SessionClient();
const seedFile = "seed.txt";
const lastHashFile = "lastHash.txt";
const cryptoRegExp = new RegExp(/^\/([a-z]|[0-9])+$/);
if (existsSync(lastHashFile))
client.lastHash = readFileSync(lastHashFile).toString()
seed: existsSync(seedFile) && readFileSync(seedFile).toString(),
displayName: "Session Bot",
// avatar:
}).then(async() => {
client.on("updateLastHash", hash => writeFileSync(lastHashFile, hash));
["", "", ""].forEach(async url => await client.joinOpenGroupV2(url));
client.on("messages", msgs => {
msgs.forEach(async msg => {
if (msg.body) msg.body = msg.body.trim();
let response;
let options = { displayName: "Session Bot" };
if (msg.body === "/help" , "/h" , "/SessionBot")
response = " /news\n /session.faq\n /session.groups\n /session.issues\n /lokinet\n /lokinet.faq\n /lokinet.exit\n /oxen\n /oxen.wallet\n /oxen.price\n /\n /sn (currently inactive)\n /sn.deb\n /optf\n /donate\n";
else if (msg.body === "/session.faq")
response = "Session's FAQ:\n";
else if (msg.body === "/session.groups")
response = "Session's Open Groups:\n\nAndroid\n\n\nUnix\n";
else if (msg.body === "/session.issues")
response = "Report a Session development issue:\nAndroid:\n\nDesktop:\n\niOS:\n";
else if (msg.body === "/news")
response = "Session's blog:\n\n\nOPTF blog:\n\n\nOxen (weekly) dev updates:\n\n\nYouTube Channel:\n";
else if (msg.body === "/lokinet")
response = "What, why, how to install, how to use lokinet?\n\n\nHow to browse the clearnet with lokinet?\n\n\nLooking for a simple RPi (router) implementation of lokinet?\n";
else if (msg.body === "/lokinet.faq")
response = "";
else if (msg.body === "/lokinet.exit")
response = "exit.loki (Germany)\ntixe.loki (France)\nexit-gondor.loki (Netherlands)\nexit-arda.loki (Norway)";
else if (msg.body === "/oxen")
response = "Overview, how to stack and economics:\n\n\nHow to setup your own Oxen Service Node?\n\n\nHow to stack without running your own Oxen Service Node?\n\nWhere to buy OXEN?\n\n\n\How to buy?\n1.Fiat (€, $, ...) > ETH or BTC\n2.ETH or BTC > OXEN\n 3.Transfer to your private OXEN wallet.";
else if (msg.body === "/oxen.wallet")
response = "Download your Oxen wallet:\n\n\nAlways verify the download before using\n\n(Tip:\n\n Always BACKUP your wallet seed!\n\n NEVER share your wallet seed!";
else if (msg.body === "/")
response = "Monitor the OXEN and Service Node network:\n\n\n";
else if (msg.body === "/sn")
response = "Active SN: XX.XXX\nVersions: X.X.X\nSN stake req.: 15,000 OXEN\nSN reward: 16.5 OXEN\nDaily reward: ~ X.XX OXEN\nRewards time: \nOpen for contribution:\nDecomissioned SN:";
else if (msg.body === "/sn.deb")
response = "Commands to check and control your service (Debian package)\n\nShow general status of the process:\nsudo systemctl status oxen-node\nsudo systemctl status oxen-storage-server\nsudo systemctl status lokinet-router\n\nStart/stop/restart a service:\nsudo systemctl start oxen-node\nsudo systemctl restart oxen-node\nsudo systemctl stop oxen-node\n\nQuery oxend for status (does not need sudo)\noxend status";
else if (msg.body === "/optf")
response = "Accessibility\nA free and open internet is essential to upholding democratic principles, including freedom of expression and freedom of the press.\n\nDemocratic freedoms\nA free and open internet is essential to upholding democratic principles, including freedom of expression and freedom of the press.\n\nEducation\nPeople need education and resources to help them understand and exercise their right to privacy.\n\nPrivacy\nDigital technology must be designed to protect user privacy by default.\n\nCommunity\nOnline communities are strongest when they are open and welcoming, and promote human dignity.\n\nThe Oxen Privacy Tech Foundation\n";
else if (msg.body === "/donate")
response = "Support Session Bot development:\n\nBot developer:\nLT2mP2DrmGD82gFnH16ty8ZtP6f33czpA6XgQdnuTVeT5bNGyy3vnaUezzKq1rEYyq3cvb2GBZ5LjCC6uqDyKnbvFki9aAX\n\nBot Dev Supporter:\nLUYB9Mq6RgnBssy5FHYziWdH6oY1z4dfdewp8c4fftiAfjbJ6JSNEsUWSmqiM16LQNeUo43rmKWPMYJb4MkQh4MiRb6w6Xt";
else if (msg.body.startsWith("/oxen.price")) {
const currentPriceUSD = await askPrice("oxen", "usd");
const currentPriceEUR = await askPrice("oxen", "eur");
response = "OXEN = " + currentPriceUSD.toString() + " USD\n" + "OXEN = " + currentPriceEUR.toString() + " EUR\n" + "base tx fee ~0.005 OXEN (~3s)\nblink tx fee ~0.015 OXEN (~20min)";
if (msg.openGroup)
await client.sendOpenGroupMessage(msg.openGroup, response, options);
await client.send(msg.source, response, options)
//price call example
async function askPrice(cryptoId, fiatSymbol) {
if (cryptoId === "oxen" || cryptoId === "loki") {
cryptoId = "loki-network"
let result = await fetch("" + cryptoId + "&vs_currencies=" + fiatSymbol);
result = await result.json();
if (cryptoId in result) {
return result[cryptoId][fiatSymbol];
return result;
//askPrice("oxen", "usd").then(e => console.log(e));
//askPrice("monero", "usd").then(e => console.log(e));