aboutsummaryrefslogtreecommitdiff
path: root/clientmods/chat/init.lua
blob: 45d61e06b0ed974b9358bee801e0d873560d3f1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
chat = {}

chat.rainbow = dofile(minetest.get_modpath("chat") .. "/rainbow.lua")

function chat.send(message)
	local starts_with = message:sub(1, 1)
	
	if starts_with == "/" or starts_with == "." then return end

	local reverse = minetest.settings:get_bool("chat_reverse")
	
	if reverse then
		local msg = ""
		for i = 1, #message do
			msg = message:sub(i, i) .. msg
		end
		message = msg
	end
	
	local color = minetest.settings:get("chat_color")

	if color then
		local msg
		if color == "rainbow" then
			msg = chat.rainbow(message)
		else
			msg = minetest.colorize(color, message)
		end
		message = msg
	end
	
	minetest.send_chat_message(message)
	return true
end

minetest.register_on_sending_chat_message(chat.send)

local etime = 0

minetest.register_globalstep(function(dtime)
	etime = etime + dtime
	if etime < 10/8 then return end
	etime = 0
	local spam = minetest.settings:get("chat_spam")
	local enable_spam = minetest.settings:get("chat_enable_spam")
	if enable_spam and spam then
		local _ = chat.send(spam) or minetest.send_chat_message(spam)
	end
end)