Replace IFDEFS with local constant ifs
parent
f66c4cc5ec
commit
25e5bd17c7
|
@ -1,14 +1,16 @@
|
||||||
|
local const_discord = bridges.discord
|
||||||
-- Converts "#XXXXXX" color codes to colors
|
-- Converts "#XXXXXX" color codes to colors
|
||||||
function colorize_message(message)
|
function colorize_message(message)
|
||||||
local rope={}
|
local rope={}
|
||||||
--IFNDEF discord
|
local otherrope
|
||||||
local otherrope={}
|
if const_discord then
|
||||||
--ENDIF
|
otherrope={}
|
||||||
|
end
|
||||||
local function append_character(c)
|
local function append_character(c)
|
||||||
table.insert(rope, c)
|
table.insert(rope, c)
|
||||||
--IFNDEF discord
|
if const_discord then
|
||||||
table.insert(otherrope, c)
|
table.insert(otherrope, c)
|
||||||
--ENDIF
|
end
|
||||||
end
|
end
|
||||||
local i=1
|
local i=1
|
||||||
while i <= message:len() do
|
while i <= message:len() do
|
||||||
|
@ -36,10 +38,10 @@ function colorize_message(message)
|
||||||
end
|
end
|
||||||
i=i+1
|
i=i+1
|
||||||
end
|
end
|
||||||
|
if const_discord then
|
||||||
|
return table.concat(rope), table.concat(otherrope)
|
||||||
|
end
|
||||||
return table.concat(rope)
|
return table.concat(rope)
|
||||||
--IFNDEF discord
|
|
||||||
, table.concat(otherrope)
|
|
||||||
--ENDIF
|
|
||||||
end
|
end
|
||||||
|
|
||||||
load_schemes()
|
load_schemes()
|
13
init.lua
13
init.lua
|
@ -2,16 +2,9 @@ local mod = modlib.mod
|
||||||
mod.create_namespace()
|
mod.create_namespace()
|
||||||
mod.extend("conf")
|
mod.extend("conf")
|
||||||
|
|
||||||
-- Some IFNDEFS
|
mod.extend_string("colorize_message.lua")
|
||||||
local bridge_ifndefs={
|
|
||||||
bridge=adv_chat.bridges.discord or adv_chat.bridges.irc,
|
|
||||||
discord=adv_chat.bridges.discord,
|
|
||||||
irc=adv_chat.bridges.irc
|
|
||||||
}
|
|
||||||
|
|
||||||
mod.extend_string(modlib.text.handle_ifndefs(modlib.file.read(mod.get_resource("colorize_message.lua")), bridge_ifndefs))
|
mod.extend("main")
|
||||||
|
|
||||||
mod.extend_string(modlib.text.handle_ifndefs(modlib.file.read(mod.get_resource("main.lua")), bridge_ifndefs))
|
|
||||||
|
|
||||||
-- Basic API stuff
|
-- Basic API stuff
|
||||||
mod.extend("unicode")
|
mod.extend("unicode")
|
||||||
|
@ -26,7 +19,7 @@ mod.extend("message")
|
||||||
mod.extend("hud_channels")
|
mod.extend("hud_channels")
|
||||||
|
|
||||||
-- Chat bridges
|
-- Chat bridges
|
||||||
if bridge_ifndefs.bridge then
|
if adv_chat.bridges.irc or adv_chat.bridges.discord then
|
||||||
mod.extend("chatcommands")
|
mod.extend("chatcommands")
|
||||||
mod.extend("process_bridges")
|
mod.extend("process_bridges")
|
||||||
local env = minetest.request_insecure_environment() or error("Error: adv_chat needs to be added to the trusted mods for chat bridges to work. See the Readme for more info.")
|
local env = minetest.request_insecure_environment() or error("Error: adv_chat needs to be added to the trusted mods for chat bridges to work. See the Readme for more info.")
|
||||||
|
|
161
main.lua
161
main.lua
|
@ -1,7 +1,8 @@
|
||||||
--- THIS FILE USES CUSTOM STUFF (IFNDEFS) IMPLEMENTED USING MODLIB - DON'T CHANGE THE WAY IT IS EXECUTED IN init.lua
|
local const_irc, const_discord = bridges.irc, bridges.discord
|
||||||
|
local const_bridge = const_irc or const_discord
|
||||||
|
|
||||||
modlib.log.create_channel("adv_chat") -- Create log channel
|
modlib.log.create_channel("adv_chat") -- Create log channel
|
||||||
modlib.data.create_mod_storage("adv_chat") --Create mod storage
|
modlib.data.create_mod_storage("adv_chat") -- Create mod storage
|
||||||
modlib.player.set_property_default("adv_chat.roles",{})
|
modlib.player.set_property_default("adv_chat.roles",{})
|
||||||
modlib.player.set_property_default("adv_chat.blocked",{chatters={}, roles={}})
|
modlib.player.set_property_default("adv_chat.blocked",{chatters={}, roles={}})
|
||||||
|
|
||||||
|
@ -92,16 +93,16 @@ function send_to_chatter(sendername, chattername, message)
|
||||||
if chatters[chattername].minetest then
|
if chatters[chattername].minetest then
|
||||||
minetest.chat_send_player(chattername, sendername)
|
minetest.chat_send_player(chattername, sendername)
|
||||||
else
|
else
|
||||||
--IFNDEF discord
|
if const_discord then
|
||||||
if chatters[chattername].discord then
|
if chatters[chattername].discord then
|
||||||
discord_bridge.write("[PMS]"..get_color(chattername).." "..chattername.." "..message)
|
discord_bridge.write("[PMS]"..get_color(chattername).." "..chattername.." "..message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
if const_irc then
|
||||||
--IFNDEF irc
|
if chatters[chattername].irc then
|
||||||
if chatters[chattername].irc then
|
irc_bridge.write("[PMS]"..chattername.." "..message)
|
||||||
irc_bridge.write("[PMS]"..chattername.." "..message)
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -113,9 +114,13 @@ function send_to_targets(msg)
|
||||||
if message.handle_on_chat_messages(msg) then
|
if message.handle_on_chat_messages(msg) then
|
||||||
return msg.handled_by_on_chat_messages
|
return msg.handled_by_on_chat_messages
|
||||||
end
|
end
|
||||||
--IFNDEF bridge
|
local irc_mentioned, discord_mentioned
|
||||||
local discord_mentioned, irc_mentioned=msg.targets.discord, msg.targets.irc
|
if const_irc then
|
||||||
--ENDIF
|
irc_mentioned = msg.targets.irc
|
||||||
|
end
|
||||||
|
if const_discord then
|
||||||
|
discord_mentioned = msg.targets.discord
|
||||||
|
end
|
||||||
for target, _ in pairs(msg.targets) do
|
for target, _ in pairs(msg.targets) do
|
||||||
if not chatters[target] then
|
if not chatters[target] then
|
||||||
if roles[target] then
|
if roles[target] then
|
||||||
|
@ -127,43 +132,43 @@ function send_to_targets(msg)
|
||||||
local discord_chatters={}
|
local discord_chatters={}
|
||||||
local irc_chatters={}
|
local irc_chatters={}
|
||||||
for chatter, _ in pairs(msg.targets) do
|
for chatter, _ in pairs(msg.targets) do
|
||||||
if not is_blocked(chatter, sendername) then
|
if not is_blocked(chatter, msg.chatter.name) then
|
||||||
if chatters[chatter].minetest then
|
if chatters[chatter].minetest then
|
||||||
minetest.chat_send_player(chatter, message.build(msg, "minetest"))
|
minetest.chat_send_player(chatter, message.build(msg, "minetest"))
|
||||||
else
|
else
|
||||||
--IFNDEF discord
|
if const_discord then
|
||||||
if chatters[chatter].discord then
|
if chatters[chatter].discord then
|
||||||
table.insert(discord_chatters, chatter:sub(1, chatter:len()-9))
|
table.insert(discord_chatters, chatter:sub(1, chatter:len()-9))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
if const_irc then
|
||||||
--IFNDEF irc
|
if chatters[chatter].irc then
|
||||||
if chatters[chatter].irc then
|
table.insert(irc_chatters, chatter:sub(1, chatter:len()-5))
|
||||||
table.insert(irc_chatters, chatter:sub(1, chatter:len()-5))
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--IFNDEF discord
|
if const_discord then
|
||||||
if msg.sent_to ~= "discord" then
|
if msg.sent_to ~= "discord" then
|
||||||
if discord_mentioned then
|
if discord_mentioned then
|
||||||
discord_bridge.write("[MSG]"..(msg.chatter.color).." "..message.build(msg, "discord"))
|
discord_bridge.write("[MSG]"..(msg.chatter.color).." "..message.build(msg, "discord"))
|
||||||
elseif #discord_chatters > 0 then
|
elseif #discord_chatters > 0 then
|
||||||
discord_bridge.write("[PMS]"..(msg.chatter.color).." "..table.concat(discord_chatters, ",").." "..message.build(msg, "discord"))
|
discord_bridge.write("[PMS]"..(msg.chatter.color).." "..table.concat(discord_chatters, ",").." "..message.build(msg, "discord"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
|
||||||
|
|
||||||
--IFNDEF irc
|
if const_irc then
|
||||||
if msg.sent_to ~= "irc" then
|
if msg.sent_to ~= "irc" then
|
||||||
if irc_mentioned then
|
if irc_mentioned then
|
||||||
irc_bridge.write("[MSG]"..message.build(msg, "irc"))
|
irc_bridge.write("[MSG]"..message.build(msg, "irc"))
|
||||||
elseif #irc_chatters > 0 then
|
elseif #irc_chatters > 0 then
|
||||||
irc_bridge.write("[PMS]"..table.concat(irc_chatters, ",").." "..message.build(msg, "irc"))
|
irc_bridge.write("[PMS]"..table.concat(irc_chatters, ",").." "..message.build(msg, "irc"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function join(name, def)
|
function join(name, def)
|
||||||
|
@ -243,44 +248,38 @@ function register_role(rolename, roledef)
|
||||||
modlib.player.register_forbidden_name(rolename)
|
modlib.player.register_forbidden_name(rolename)
|
||||||
end
|
end
|
||||||
|
|
||||||
--IFNDEF bridge
|
if const_bridge then
|
||||||
minetest.original_chat_send_all=minetest.chat_send_all
|
minetest.original_chat_send_all=minetest.chat_send_all
|
||||||
minetest.chat_send_all=function(msg)
|
minetest.chat_send_all=function(msg)
|
||||||
local adv_message=message.new(nil, nil, msg)
|
local adv_message=message.new(nil, nil, msg)
|
||||||
adv_message.internal=true
|
adv_message.internal=true
|
||||||
send_to_all(adv_message)
|
send_to_all(adv_message)
|
||||||
|
end
|
||||||
|
minetest.original_chat_send_player=minetest.chat_send_player
|
||||||
|
minetest.chat_send_player=function(name, msg)
|
||||||
|
local chatter=chatters[name]
|
||||||
|
if not chatter then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if chatter.minetest then
|
||||||
|
return minetest.original_chat_send_player(name, msg)
|
||||||
|
end
|
||||||
|
local adv_message=message.new(nil, nil, msg)
|
||||||
|
adv_message.internal=true
|
||||||
|
local to_be_sent=message.build(adv_message, chatter.service)
|
||||||
|
|
||||||
|
if const_irc then
|
||||||
|
if chatter.irc then
|
||||||
|
irc_bridge.write("[PMS]"..chatter.name.." "..to_be_sent)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if const_discord then
|
||||||
|
if chatter.discord then
|
||||||
|
discord_bridge.write("[PMS]#FFFFFF "..chatter.name.." "..to_be_sent)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
|
||||||
|
|
||||||
--IFNDEF bridge
|
|
||||||
minetest.original_chat_send_player=minetest.chat_send_player
|
|
||||||
minetest.chat_send_player=function(name, msg)
|
|
||||||
local chatter=chatters[name]
|
|
||||||
if not chatter then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if chatter.minetest then
|
|
||||||
return minetest.original_chat_send_player(name, msg)
|
|
||||||
end
|
|
||||||
local adv_message=message.new(nil, nil, msg)
|
|
||||||
adv_message.internal=true
|
|
||||||
local to_be_sent=message.build(adv_message, chatter.service)
|
|
||||||
--ENDIF
|
|
||||||
|
|
||||||
--IFNDEF irc
|
|
||||||
if chatter.irc then
|
|
||||||
irc_bridge.write("[PMS]"..chatter.name.." "..to_be_sent)
|
|
||||||
end
|
|
||||||
--ENDIF
|
|
||||||
--IFNDEF discord
|
|
||||||
if chatter.discord then
|
|
||||||
discord_bridge.write("[PMS]#FFFFFF "..chatter.name.." "..to_be_sent)
|
|
||||||
end
|
|
||||||
--ENDIF
|
|
||||||
|
|
||||||
--IFNDEF bridge
|
|
||||||
end
|
|
||||||
--ENDIF
|
|
||||||
|
|
||||||
register_role("minetest",{color="#66FF66"})
|
register_role("minetest",{color="#66FF66"})
|
||||||
|
|
||||||
|
@ -336,16 +335,16 @@ function send_to_all(msg)
|
||||||
if message.handle_on_chat_messages(msg) then
|
if message.handle_on_chat_messages(msg) then
|
||||||
return msg.handled_by_on_chat_messages
|
return msg.handled_by_on_chat_messages
|
||||||
end
|
end
|
||||||
--IFNDEF irc
|
if const_irc then
|
||||||
if msg.sent_to ~= "irc" then
|
if msg.sent_to ~= "irc" then
|
||||||
irc_bridge.write("[MSG]"..message.build(msg, "irc"))
|
irc_bridge.write("[MSG]"..message.build(msg, "irc"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
if const_discord then
|
||||||
--IFNDEF discord
|
if msg.sent_to ~= "discord" then
|
||||||
if msg.sent_to ~= "discord" then
|
discord_bridge.write("[MSG]"..((msg.chatter and msg.chatter.color) or "#FFFFFF").." "..message.build(msg, "discord"))
|
||||||
discord_bridge.write("[MSG]"..((msg.chatter and msg.chatter.color) or "#FFFFFF").." "..message.build(msg, "discord"))
|
end
|
||||||
end
|
end
|
||||||
--ENDIF
|
|
||||||
if msg.sent_to ~= "minetest" then
|
if msg.sent_to ~= "minetest" then
|
||||||
local mt_msg
|
local mt_msg
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
Loading…
Reference in New Issue