Adding to the discord emit

This commit is contained in:
Cooldude2606
2017-11-29 22:13:56 +00:00
parent 64a3af8e8b
commit cf8697adff

View File

@@ -13,13 +13,13 @@ Discord: https://discord.gg/r6dC2uK
local ExpLib = { local ExpLib = {
text_hex = { text_hex = {
['']='#0', ['']='0x0',
info='#36F2FF', info='0x36F2FF',
alert='#000000', alert='0x000000',
low='#2dc42d', low='0x2dc42d',
med='#ffe242', med='0xffe242',
high='#ff5400', high='0xff5400',
crit='#FF0000' crit='0xFF0000'
}, },
text_rgb = { text_rgb = {
['']={0,0,0}, ['']={0,0,0},
@@ -37,7 +37,7 @@ local ExpLib = {
-- _load_to_G(a) -- _load_to_G(a)
-- @tparam table tbl table to add to the global lua table -- @tparam table tbl table to add to the global lua table
function ExpLib._load_to_G(tbl) function ExpLib._load_to_G(tbl)
if not is_type(tbl,'table') then return end if not is_type(tbl,'table') or game then return end
for name,value in pairs(tbl) do for name,value in pairs(tbl) do
if not _G[name] then _G[name] = value end if not _G[name] then _G[name] = value end
end end
@@ -73,26 +73,33 @@ function ExpLib.player_return(rtn)
end end
end end
--- Logs data to the json file, we use this for discord --- Logs an embed to the json.data we use a js script to add things we cant here
-- @usage a = 'some data' -- @usage a = 'some data'
-- json_emit('data','info',a) -- json_emit('data','info',a)
-- @tparam string type the type of emit your programe will look for -- @tparam string type the type of emit your programe will look for
-- @tparam string colour the colour based on the the text_hex use '' for no colour -- @tparam string colour the colour based on the the text_hex use '' for no colour
-- @param data any data which you want to include this will also be conevert to json -- @param data any data which you want to include this will also be conevert to json
function ExpLib.json_emit(type,colour,data) function ExpLib.discord_emit(title,colour,description,fields,add_to_server_detail)
if not is_type(type,'string') or if not is_type(title,'string') or
not is_type(colour,'string') or not is_type(fields,'table') then return end
not text_hex[colour] or local add_to_server_detail = add_to_server_detail or ''
not data then return end local colour = colour or ''
local description or ''
local log_data = { local log_data = {
type=string.upper(type) title=title
tick=game.tick, description=description
online=#game.connected_players, color=text_hex[colour],
colour=text_hex[colour], fields={
data=data {
name='Server Details',
value='Server Name: {{ serverName }} Online Players: '..#game.connected_players..' Server Time: '..tick_to_display_format(game.tick)..' '..add_to_server_detail
},
unpack(fields)
}
} }
game.write_file('json.data',table.json(log_data),true,0) game.write_file('json.data',table.json(log_data),true,0)
end end
--- Convert ticks to hours --- Convert ticks to hours
-- @usage a = 216001 -- @usage a = 216001
-- tick_to_hour(a) -- return 1 -- tick_to_hour(a) -- return 1