From eca229645a625028b946961c1902a23ba48fbbb6 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Sat, 7 Apr 2018 15:12:39 +1200 Subject: [PATCH] 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. --- README.md | 33 ++++++++++++++++++++++++++++++++- init.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19bd2cf..8bf8264 100644 --- a/README.md +++ b/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 [channel]`: Adds `` to the channel. If + `[channel]` is not specified, the current channel will be used instead. + - `.delete_channel `: Deletes a channel. + - `.list_channels`: Displays a list of channels. + - `.toggle_main`: Toggles between showing and hiding messages from #main. + - `.remove_from_channel [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. diff --git a/init.lua b/init.lua index 9da273a..05caf7d 100644 --- a/init.lua +++ b/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.",