sync chat + websocket

This commit is contained in:
Linventif 2024-01-15 04:40:41 +01:00
parent 5f76915d7c
commit fc5117b63e
4 changed files with 10 additions and 35 deletions

View File

@ -5,7 +5,7 @@ if game.SinglePlayer() then return end
//
gmInte = {}
gmInte.version = "0.2.0"
gmInte.version = "0.2.1"
gmInte.config = {
["redownloadMaterials"] = false,
}

View File

@ -2,12 +2,16 @@
// WebSocket
//
if (!gmInte.config.websocket) then return end
require("gwsockets")
// TODO made a proper system to detect if the server need to be connected to the websocket
if (!gmInte.config.syncChat && !gmInte.config.websocket) then
gmInte.log("WebSocket is disabled", true)
return
end
if (!GWSockets) then return gmInte.logError("GWSockets is not installed! Please install it from https://github.com/FredyH/GWSockets") end
require("gwsockets")
local socket = GWSockets.createWebSocket("wss://ws.gmod-integration.com")
// Authentication
@ -47,7 +51,7 @@ function gmInte.websocketWrite(data)
socket:write(util.TableToJSON(data || {}))
end
timer.Create("gmInte:WebSocket:CheckConnection", 60, 0, function()
timer.Create("gmInte:WebSocket:CheckConnection", 4, 0, function()
if (!socket:isConnected()) then
socket:open()
end

View File

@ -67,13 +67,11 @@ end
function gmInte.playerSay(ply, text, team)
if (!gmInte.config.syncChat) then return end
local triggerInfo = getTriggerInfo(text)
if (!triggerInfo && !gmInte.config.chatTriggerAll) then return end
gmInte.post("/server/user/say",
{
["steamID64"] = ply:SteamID64(),
["message"] = string.sub(text, string.len(triggerInfo.trigger) + 1),
["message"] = text,
["name"] = ply:Nick(),
["usergroup"] = ply:GetUserGroup(),
["message_info"] = triggerInfo

View File

@ -34,33 +34,6 @@ gmInte.config.token = "" // Server Token
*/
gmInte.config.websocket = false // If true, the addon will use the websocket instead of the http requests
// Chat
gmInte.config.chatTriggerAll = false // If true, the addon will sync all the messages in the chat
gmInte.config.chatTrigger = {
/* Example:
["/example "] = {
["prefix"] = "[Example] ", // The prefix of the message
["show_rank"] = false, // If true, the addon will show the rank of the player in the prefix
["anonymous"] = false, // If true, the addon will not show the name and the avatar of the player in the message
["channel"] = "admin_sync_chat" // If set, the addon will use a custom channel to sync the message (use in multi chat syncronization)
},
["/admin_chat "] = {
["prefix"] = "[Admin Chat]",
["show_rank"] = true,
["channel"] = "discord_channel_id_admin_chat"
},
*/
["// "] = {
["prefix"] = "",
["show_rank"] = false,
["anonymous"] = false,
["custom_id"] = "admin_sync_chat"
},
["/ano "] = {
["anonymous"] = true,
},
} // Trigger to sync the messages in a discord channel (the key is the trigger and the value is the replacement)
// Other
gmInte.config.forcePlayerLink = false // If true, the addon will force the players to link their discord account to their steam account before playing
gmInte.config.supportLink = "" // The link of your support (shown when a player do not have the requiments to join the server)