forked from snxraven/sshChat-CLI
changes, adding error handles for connections and command blocking
This commit is contained in:
parent
13cb96af14
commit
9a53fceaee
3
discordBridge/.env
Normal file
3
discordBridge/.env
Normal file
@ -0,0 +1,3 @@
|
||||
TOKEN=MTA2MjM4NjI4MjM1MDc3NjQzMA.GxffCt.RWpwcdgSS7zl4aivcXSL3vRL06lcfnmDIx_1Q0
|
||||
TOPIC_HASH=64ae5b405f523f45c7ee68287ff89c281c5d297fe2fce622d51650fad7975178
|
||||
CHANNEL=928115276438978632
|
45
discordBridge/bridge.js
Normal file
45
discordBridge/bridge.js
Normal file
@ -0,0 +1,45 @@
|
||||
const Discord = require('discord.js');
|
||||
const Hyperswarm = require('hyperswarm');
|
||||
const b4a = require('b4a');
|
||||
const crypto = require('hypercore-crypto');
|
||||
|
||||
client = new Discord.Client({intents: 32767})
|
||||
const swarm = new Hyperswarm();
|
||||
let channel
|
||||
|
||||
let topic;
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
})
|
||||
|
||||
topic = b4a.from("64ae5b405f523f45c7ee68287ff89c281c5d297fe2fce622d51650fad7975178", 'hex') // Generate a random topic
|
||||
|
||||
// Join the swarm network with the topic
|
||||
swarm.join(topic, {
|
||||
lookup: true, // Enable peer discovery
|
||||
announce: true // Enable peer announcement
|
||||
});
|
||||
|
||||
swarm.on('connection', (conn, info) => {
|
||||
console.log(`Connected to a peer for topic ${topic.toString('hex')}`);
|
||||
|
||||
conn.on('data', data => {
|
||||
// Send the message from the topic to the Discord channel
|
||||
client.channels.cache.get("818514972610134069").send(b4a.toString(data));
|
||||
});
|
||||
});
|
||||
|
||||
client.on('message', msg => {
|
||||
if (msg.channel.id === '818514972610134069') {
|
||||
// Send the message from the Discord channel to the topic
|
||||
swarm.peers(topic, (err, peers) => {
|
||||
peers.forEach(peer => {
|
||||
const conn = swarm.connection(peer);
|
||||
conn.write(b4a.fromString(msg.content));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
client.login("MTA2MjM4NjI4MjM1MDc3NjQzMA.GxffCt.RWpwcdgSS7zl4aivcXSL3vRL06lcfnmDIx_1Q0");
|
20
sshChat.mjs
20
sshChat.mjs
@ -18,7 +18,7 @@ goodbye(() => swarm.destroy())
|
||||
const conns = []
|
||||
let USERPWD = "/"
|
||||
let DAPI_KEY = {}
|
||||
let USERNAME = "annon" + rand
|
||||
let USERNAME = "anon" + rand
|
||||
let LOGGEDIN = false
|
||||
|
||||
async function clearCursor() {
|
||||
@ -105,6 +105,10 @@ swarm.on('connection', conn => {
|
||||
})
|
||||
})
|
||||
|
||||
swarm.on('error', (err) => {
|
||||
console.log('Error connecting to peer:', err);
|
||||
});
|
||||
|
||||
// Use readline to accept input from the user
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
@ -145,6 +149,8 @@ rl.on('line', input => {
|
||||
}
|
||||
|
||||
const execute = input.startsWith(">")
|
||||
if (input.startsWith("/") || input.startsWith("!")) return
|
||||
|
||||
if (execute) {
|
||||
let inputdata = input.split(2)
|
||||
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">", "")
|
||||
@ -169,7 +175,6 @@ rl.on('line', input => {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const start = input.startsWith("/start")
|
||||
if (start) {
|
||||
startContainer(DAPI_KEY.key).then((data) => {
|
||||
@ -224,7 +229,13 @@ rl.on('line', input => {
|
||||
|
||||
// Join a common topic
|
||||
const topic = process.argv[2] ? b4a.from(process.argv[2], 'hex') : crypto.randomBytes(32)
|
||||
const discovery = swarm.join(topic, { client: true, server: true })
|
||||
|
||||
setTimeout(() => {
|
||||
const discovery = swarm.join(topic, {
|
||||
lookup: true,
|
||||
announce: true
|
||||
|
||||
});
|
||||
|
||||
// The flushed promise will resolve when the topic has been fully announced to the DHT
|
||||
discovery.flushed().then(() => {
|
||||
@ -232,3 +243,6 @@ discovery.flushed().then(() => {
|
||||
console.log('You are now in a chatroom for your topic, feel free to chat.\n')
|
||||
console.log('Want to login to the SSH.SURF API? Type "/login [APIKEY]" to login.\n\n')
|
||||
})
|
||||
}, 3000);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user