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 msgprefix
|
||||
local localplayer = '[you]'
|
||||
local show_main_channel = true
|
||||
|
||||
if storage:get_string('channels') then
|
||||
channels = loadstring(storage:get_string('channels'))()
|
||||
|
@ -59,12 +60,14 @@ local get_channel_users = function(c)
|
|||
if u then
|
||||
channels[name] = false
|
||||
end
|
||||
show_main_channel = true
|
||||
channel = main_channel
|
||||
return false
|
||||
end
|
||||
elseif prefix == '@' then
|
||||
return {name}
|
||||
else
|
||||
show_main_channel = true
|
||||
channel = main_channel
|
||||
return false
|
||||
end
|
||||
|
@ -84,6 +87,9 @@ minetest.register_on_sending_chat_messages(function(msg)
|
|||
if cmdprefix == '@' or channels[msg:sub(2)] or msg == main_channel
|
||||
then
|
||||
channel = msg
|
||||
if channel == main_channel then
|
||||
show_main_channel = true
|
||||
end
|
||||
minetest.display_chat_message('You have changed chat channels to '
|
||||
.. channel)
|
||||
return true
|
||||
|
@ -92,6 +98,7 @@ minetest.register_on_sending_chat_messages(function(msg)
|
|||
msg = ''
|
||||
end
|
||||
if c == main_channel then
|
||||
show_main_channel = true
|
||||
minetest.send_chat_message(msg)
|
||||
return true
|
||||
elseif cmdprefix == '#' and not channels[c:sub(2)] then
|
||||
|
@ -124,6 +131,7 @@ minetest.register_on_receiving_chat_messages(function(msg)
|
|||
return true
|
||||
end
|
||||
elseif m:sub(1, 1) == '<' then
|
||||
if not show_main_channel then return true end
|
||||
local hijack = false
|
||||
if channel == main_channel then
|
||||
for _ in pairs(channels) do
|
||||
|
@ -254,6 +262,26 @@ minetest.register_chatcommand('delete_channel', {
|
|||
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', {
|
||||
params = "[channel]",
|
||||
description = "List players in the current chat channel.",
|
||||
|
|
Loading…
Reference in New Issue