added todos

This commit is contained in:
James Alexander 2024-08-03 00:51:32 -04:00
parent 9a3ae15b04
commit 212bfe0c1e
5 changed files with 8 additions and 155 deletions

View File

@ -70,11 +70,11 @@ windower.register_event("incoming text", function(_, text, mode, modemod, blocke
elseif mode == 205 then --lsmes update
linkCloud.onLSMesUpdate(1, text:strip_format())
elseif (mode == 6 or mode == 14) then --ls1 chat
linkCloud.onLSMessageReceived(1, text:strip_format())
linkCloud.onLSMessageReceived(1, text:strip_format()) --TODO: Move to chat message event
elseif (mode == 213 or mode == 214) then --ls2 chat
linkCloud.onLSMessageReceived(2, text:strip_format())
linkCloud.onLSMessageReceived(2, text:strip_format()) --TODO: Move to chat message event
elseif mode == 11 then --bot spa...i mean shouts
linkCloud.onShoutReceived(text:strip_format())
linkCloud.onShoutReceived(text:strip_format()) --TODO: remove?
end;
end);
@ -89,7 +89,7 @@ windower.register_event("addon command", function(command, ...)
elseif command == "status" or command == "s" then
linkCloud.showstatus();
elseif command == "test" then
print(windower.ffxi.get_player().linkshell_slot)
print(windower.ffxi.get_player().linkshell_slot) --TODO: Remove left over from dev.
elseif command == "addlinkshell" then
linkCloud.sendLinkshellAddRequest(args[1]);
elseif command == "autoconnect" then

View File

@ -18,7 +18,7 @@ linkShells[2] = {}
local lsBuffers = {}
lsBuffers[1] = {}
lsBuffers[2] = {}
local tcp = assert(socket.tcp());
local tcp = assert(socket.tcp()); --TODO: Make it do SSL things
local framework = nil
function hook (params)
@ -256,7 +256,7 @@ function handleResponse()
end;
elseif packet.type == "LS_ECHO" then
if packet.payload.linkshell == linkShells[1].name then
windower.chat.input("/l [" .. packet.payload.from .. "] " .. packet.payload.message:gsub("[\n\r]", " "));
windower.chat.input("/l [" .. packet.payload.from .. "] " .. packet.payload.message:gsub("[\n\r]", " ")); -- TODO: Look into sanitization solutions.
elseif packet.payload.linkshell == linkShells[2].name then
windower.chat.input("/l2 [" .. packet.payload.from .. "] " .. packet.payload.message:gsub("[\n\r]", " "));
end;

View File

@ -1,4 +1,5 @@
TCP_LISTEN_PORT=5050
BIND_ADDRESS=0.0.0.0
MAX_CLOCK_SYNC_MISMATCH_SECONDS=2
JWT_SECRET=
JWT_SECRET=
BOT_TOKEN=

View File

@ -1,5 +1,4 @@
{
"token": "xxx",
"clientId": "xxx",
"guildId": "xxx",
"db": {

View File

@ -1,147 +0,0 @@
const Net = require('net');
const port = 6033;
const { Webhook } = require('discord-webhook-node');
const hook = new Webhook("https://discord.com/api/webhooks/1157030453807698040/K80q5yE4qvKeAi7W4arGyP5YH82dTiGDALw2ESU7uzQ3b_Nv5ylgKno80sLsOTVnVQV5");
const server = new Net.Server();
const botToken = 'xxxxxx'
server.listen(port, function() {
console.log(`Server listening for connection requests on socket localhost:${port}`);
});
messageQueue = []
const CryptoJS = require("crypto-js");
const Discord = require("discord.js");
const { Client, GatewayIntentBits, SlashCommandBuilder } = require('discord.js');
const { MessageMentions: { USERS_PATTERN } } = require('discord.js');
const { v4: uuidv4 } = require('uuid');
var hasleader = false
var ignoreBuffer = []
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
})
const commands = {}
client.on("messageCreate", function(message) {
nickname = false
if (message.author.bot) return;
if (message.channelId != "1128902878166269962") return;
guild = client.guilds.cache.get(message.guildId)
guild.members.cache.forEach((member) => {
if (member.user.id == message.author.id) {
nickname = member.nickname
}
})
if (nickname == false || nickname === null) {
nickname = message.author.globalName
}
ignoreBuffer.push("[" + nickname + "] " + message.content.replace(/[\n\r]/g, ''))
messageQueue.push("[" + nickname + "] " + message.content.replace(/[\n\r]/g, ''))
if(ignoreBuffer.length > 1000) {
ignoreBuffer.shift()
}
});
client.login(botToken);
messageBuffer = []
sentMessages = []
var checkDuplicate = (message_hash, time) => {
for (let msg of sentMessages) {
if (msg.hash == message_hash) {
let differential = Math.abs(time - msg.time)
if (differential <= 1) {
return true
}
}
}
return false
}
var processBuffer = () => {
if(messageBuffer.length) {
msg = messageBuffer.shift()
duplicate = true
rawInventoryString = String(msg.metaData.server) + String(msg.payload.name) + String(msg.payload.message.replace(/[\n\r]/g, ''));
msgTime = String(msg.metaData.time)
hashedIS = CryptoJS.MD5(rawInventoryString).toString()
if(!checkDuplicate(hashedIS, msgTime) && !ignoreBuffer.includes(msg.payload.message.replace(/[\n\r]/g, ''))) {
let msgStore = {
"hash": hashedIS,
"time": msgTime
}
sentMessages.push(msgStore)
if (sentMessages.length > 100) {
sentMessages.shift()
}
hook.setUsername(msg.payload.name);
hook.setAvatar("https://ui-avatars.com/api/?background=random&name=" + msg.payload.name)
hook.send(msg.payload.message.replace(/[\n\r]/g, ''));
if(msg.payload.message.toLowerCase().includes("discord info") || msg.payload.message.toLowerCase().includes("discord invite") || msg.payload.message.toLowerCase().includes("invite to discord")) {
msg.metaData.server = 255
msg.payload.message = 'https://discord.gg/9ydGN8AHUu'
messageQueue.push(msg.payload.message)
}
} else {
console.log("Duplicate Detected.")
}
}
setTimeout(processBuffer, 250)
}
var processSocketResponse = (socket) => {
if(messageQueue.length) {
socket.write(messageQueue.shift() + '\n')
} else {
socket.write('PONG\n');
}
socket.lastPingTime = new Date();
}
var removeSocketAsLeader = (socket) => {
if (socket.isLeader) { hasleader = false }
}
setTimeout(processBuffer, 5000)
ffxiClient = {
}
server.on('connection', function(socket) {
socket.uid = uuidv4();
console.log('A new connection has been established.');
socket.write('CONNECTION_ACCEPTED\n');
socket.on('data', function(chunk) {
payload = JSON.parse(chunk.toString())
if(payload['type'] == "MESSAGE") {
messageBuffer.push(payload)
socket.linkshell = payload.payload.linkshellname
socket.write('RECEIVEDOK\n');
console.log(payload);
} else if (payload['type'] == "PING") {
processSocketResponse(socket)
} else if (payload['type'] == "OTHER") {
socket.write('RECEIVEDOK\n');
} else if (payload['type'] == "HANDSHAKE") {
socket.write('WELCOME\n');
}
});
socket.on('end', function() {
removeSocketAsLeader(socket)
console.log('Closing connection with the client');
});
socket.on('error', function(err) {
removeSocketAsLeader(socket)
console.log(`Error: ${err}`);
});
});
//