Current bot.js file for Session Bot

master
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()
client.loadIdentity({
seed: existsSync(seedFile) && readFileSync(seedFile).toString(),
displayName: "Session Bot",
// avatar:
}).then(async() => {
await client.open();
client.on("updateLastHash", hash => writeFileSync(lastHashFile, hash));
["http://open2.hesiod.network/build_a_bot?public_key=58dc124cc38e4d03449037e9a4a86a2e5c2a648938eb824a5cdf3b6a80fab07d", "http://open2.hesiod.network/android?public_key=58dc124cc38e4d03449037e9a4a86a2e5c2a648938eb824a5cdf3b6a80fab07d", "http://open2.hesiod.network/unix?public_key=58dc124cc38e4d03449037e9a4a86a2e5c2a648938eb824a5cdf3b6a80fab07d"].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 /oxen.observer\n /sn (currently inactive)\n /sn.deb\n /optf\n /donate\n";
else if (msg.body === "/session.faq")
response = "Session's FAQ:\nhttps://getsession.org/faq";
else if (msg.body === "/session.groups")
response = "Session's Open Groups:\n\nAndroid\nhttp://open2.hesiod.network/android?public_key=58dc124cc38e4d03449037e9a4a86a2e5c2a648938eb824a5cdf3b6a80fab07d\n\nUnix\nhttp://open2.hesiod.network/unix?public_key=58dc124cc38e4d03449037e9a4a86a2e5c2a648938eb824a5cdf3b6a80fab07d";
else if (msg.body === "/session.issues")
response = "Report a Session development issue:\nAndroid:\nhttps://github.com/oxen-io/session-android/issues\nDesktop:\nhttps://github.com/oxen-io/session-desktop/issues\niOS:\nhttps://github.com/oxen-io/session-ios/issues";
else if (msg.body === "/news")
response = "Session's blog:\nhttps://getsession.org/blog/\n\nOPTF blog:\nhttps://optf.ngo/blog\n\nOxen (weekly) dev updates:\nhttps://oxen.io/blog\n\nYouTube Channel:\nhttps://www.youtube.com/channel/UCN7LL0dEffQ7FSjbY5wwlnw";
else if (msg.body === "/lokinet")
response = "What, why, how to install, how to use lokinet?\nhttps://docs.oxen.io/products-built-on-oxen/lokinet\n\nHow to browse the clearnet with lokinet?\nhttps://docs.oxen.io/products-built-on-oxen/lokinet/exit-nodes\n\nLooking for a simple RPi (router) implementation of lokinet?\nhttps://github.com/necro-nemesis/LabyrinthAP";
else if (msg.body === "/lokinet.faq")
response = "https://lokinet.org/faqdark";
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:\nhttps://docs.oxen.io/\n\nHow to setup your own Oxen Service Node?\nhttps://docs.oxen.io/using-the-oxen-blockchain/oxen-service-node-guides/setting-up-an-oxen-service-node\n\nHow to stack without running your own Oxen Service Node?\nhttps://docs.oxen.io/using-the-oxen-blockchain/oxen-service-node-guides/staking-to-shared-service-node\nWhere to buy OXEN?\nhttps://www.kucoin.com\nhttps://tradeogre.com\nhttps://global.bittrex.com\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:\nhttps://docs.oxen.io/downloads\n\nAlways verify the download before using\nhttps://github.com/oxen-io/oxen-electron-gui-wallet/releases\n(Tip: https://www.youtube.com/watch?v=Lefnp-063go)\n\n Always BACKUP your wallet seed!\n\n NEVER share your wallet seed!";
else if (msg.body === "/oxen.observer")
response = "Monitor the OXEN and Service Node network:\nhttps://www.oxensn.com\nhttps://lokiblocks.com\nhttps://oxendashboard.com";
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\nhttps://optf.ngo";
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);
else
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("https://api.coingecko.com/api/v3/simple/price?ids=" + cryptoId + "&vs_currencies=" + fiatSymbol);
result = await result.json();
console.log(result);
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));
Loading…
Cancel
Save