Modify README and add .toggle_main
Add docs into README.md and add `.toggle_main` to hide messages from #main. if #main has been renamed, `.toggle_main` will reflect those changes.
This commit is contained in:
parent
22ef5669e5
commit
eca229645a
33
README.md
33
README.md
|
@ -1 +1,32 @@
|
||||||
chat-channels
|
# chat_channels
|
||||||
|
|
||||||
|
A client-side mod for Minetest that adds chat channels, inspired by
|
||||||
|
[beerchat](https://github.com/evrooije/beerchat).
|
||||||
|
|
||||||
|
## Chat channels
|
||||||
|
|
||||||
|
Channels are sent via PMs to users.
|
||||||
|
Anyone can add you to a channel without your permission, and channels are not
|
||||||
|
synced between users.
|
||||||
|
Chat channels are created automatically when adding the first user and deleted
|
||||||
|
when removing the last user.
|
||||||
|
|
||||||
|
The following channel prefixes exist:
|
||||||
|
|
||||||
|
- `@`: A PM. This will PM the user after the `@`.
|
||||||
|
- `#`: A channel. This is just a group PM prefixed with the channel name. If
|
||||||
|
a user in the channel uses chat_channels and has you in a channel with the
|
||||||
|
same name, the message will display as a chat message in the channel.
|
||||||
|
Otherwise, it will display as a PM prefixed in `-#channel-`.
|
||||||
|
|
||||||
|
## Added commands
|
||||||
|
|
||||||
|
- `.add_to_channel <victim> [channel]`: Adds `<victim>` to the channel. If
|
||||||
|
`[channel]` is not specified, the current channel will be used instead.
|
||||||
|
- `.delete_channel <channel>`: Deletes a channel.
|
||||||
|
- `.list_channels`: Displays a list of channels.
|
||||||
|
- `.toggle_main`: Toggles between showing and hiding messages from #main.
|
||||||
|
- `.remove_from_channel <victim> [channel]`: The same as `.add_to_channel`,
|
||||||
|
except removes users instead.
|
||||||
|
- `.who [channel]`: Displays a list of users in the channel. If `[channel]` is
|
||||||
|
not specified, the current channel will be used.
|
||||||
|
|
28
init.lua
28
init.lua
|
@ -12,6 +12,7 @@ local messages_sent = 0
|
||||||
local buffer = {}
|
local buffer = {}
|
||||||
local msgprefix
|
local msgprefix
|
||||||
local localplayer = '[you]'
|
local localplayer = '[you]'
|
||||||
|
local show_main_channel = true
|
||||||
|
|
||||||
if storage:get_string('channels') then
|
if storage:get_string('channels') then
|
||||||
channels = loadstring(storage:get_string('channels'))()
|
channels = loadstring(storage:get_string('channels'))()
|
||||||
|
@ -59,12 +60,14 @@ local get_channel_users = function(c)
|
||||||
if u then
|
if u then
|
||||||
channels[name] = false
|
channels[name] = false
|
||||||
end
|
end
|
||||||
|
show_main_channel = true
|
||||||
channel = main_channel
|
channel = main_channel
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif prefix == '@' then
|
elseif prefix == '@' then
|
||||||
return {name}
|
return {name}
|
||||||
else
|
else
|
||||||
|
show_main_channel = true
|
||||||
channel = main_channel
|
channel = main_channel
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -84,6 +87,9 @@ minetest.register_on_sending_chat_messages(function(msg)
|
||||||
if cmdprefix == '@' or channels[msg:sub(2)] or msg == main_channel
|
if cmdprefix == '@' or channels[msg:sub(2)] or msg == main_channel
|
||||||
then
|
then
|
||||||
channel = msg
|
channel = msg
|
||||||
|
if channel == main_channel then
|
||||||
|
show_main_channel = true
|
||||||
|
end
|
||||||
minetest.display_chat_message('You have changed chat channels to '
|
minetest.display_chat_message('You have changed chat channels to '
|
||||||
.. channel)
|
.. channel)
|
||||||
return true
|
return true
|
||||||
|
@ -92,6 +98,7 @@ minetest.register_on_sending_chat_messages(function(msg)
|
||||||
msg = ''
|
msg = ''
|
||||||
end
|
end
|
||||||
if c == main_channel then
|
if c == main_channel then
|
||||||
|
show_main_channel = true
|
||||||
minetest.send_chat_message(msg)
|
minetest.send_chat_message(msg)
|
||||||
return true
|
return true
|
||||||
elseif cmdprefix == '#' and not channels[c:sub(2)] then
|
elseif cmdprefix == '#' and not channels[c:sub(2)] then
|
||||||
|
@ -124,6 +131,7 @@ minetest.register_on_receiving_chat_messages(function(msg)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif m:sub(1, 1) == '<' then
|
elseif m:sub(1, 1) == '<' then
|
||||||
|
if not show_main_channel then return true end
|
||||||
local hijack = false
|
local hijack = false
|
||||||
if channel == main_channel then
|
if channel == main_channel then
|
||||||
for _ in pairs(channels) do
|
for _ in pairs(channels) do
|
||||||
|
@ -254,6 +262,26 @@ minetest.register_chatcommand('delete_channel', {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_chatcommand('toggle_' .. main_channel:sub(2), {
|
||||||
|
params = "",
|
||||||
|
description = "Toggle between showing and hiding messages from "
|
||||||
|
.. main_channel .. ".",
|
||||||
|
func = function(c)
|
||||||
|
if not show_main_channel then
|
||||||
|
show_main_channel = true
|
||||||
|
return true, "You will now start to receive messages from "
|
||||||
|
.. main_channel .. "."
|
||||||
|
elseif channel == main_channel then
|
||||||
|
return false, "You are currently in " .. main_channel
|
||||||
|
.. "! Please change channels first."
|
||||||
|
else
|
||||||
|
show_main_channel = false
|
||||||
|
return true, "You will no longer receive messages from "
|
||||||
|
.. main_channel .. "."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand('who', {
|
minetest.register_chatcommand('who', {
|
||||||
params = "[channel]",
|
params = "[channel]",
|
||||||
description = "List players in the current chat channel.",
|
description = "List players in the current chat channel.",
|
||||||
|
|
Loading…
Reference in New Issue