uploaded new bot for V2 groups

master
whoami 3 years ago
parent 907676a905
commit 4607e26c71

@ -0,0 +1,109 @@
onst fs = require('fs')
const SessionClient = require('./session-client.js')
const client = new SessionClient()
// load place in inbox if available
if (fs.existsSync('lastHash.txt')) {
client.lastHash = fs.readFileSync('lastHash.txt').toString()
}
client.loadIdentity({
seed: fs.existsSync('seed.txt') && fs.readFileSync('seed.txt').toString(),
displayName: 'Session Bot',
}).then(async () => {
// output recovery phrase if making an identity
console.log(client.identityOutput)
// persist place in inbox incase we restart
client.on('updateLastHash', hash => {
fs.writeFileSync('lastHash.txt', hash)
})
const openGroupV2URL = 'http://202.61.245.158/test?public_key=f3ea00d5a2f8ec3fbc6db632a66a7e489aeb37f18690e320f180ca3de9b25e42'
const ogv2Handle = await client.joinOpenGroupV2(openGroupV2URL)
// handle incoming messages
client.on('messages', msgs => {
msgs.forEach(async msg => {
if (msg.room) {
console.log(`New message, In group: ${msg.id} in ${msg.room}`)
} else {
console.log('New message, Private')
}
console.log(`From: ${msg.profile && msg.profile.displayName} (${msg.source})`)
console.log(msg.body)
if (msg.body) msg.body = msg.body.trim();
let response;
let options = { displayName: "Session Bot" };
if (msg.body === "/help")
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 = "sessiongroups.com\nThis is NOT maintained and moderated by the Session team"
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\nhttps://imaginary.stream/sn\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\n\nHow to buy?\n\n1.Fiat (€, $, ...) > ETH or BTC\n2.ETH or BTC > OXEN\n3.Transfer to your private OXEN wallet."
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)";
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 return;
if(ogv2Handle){
await client.sendOpenGroupV2Message(ogv2Handle, response, options)
console.log("Response sent")
}
})
})
// the await here allows send to reuse the cache it builds
await client.open()
});
//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;
}
Loading…
Cancel
Save