mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Added logic for detecting a @mention in chat
This commit is contained in:
parent
ebc5b58320
commit
560cf2575c
@ -3,6 +3,10 @@
|
||||
local Game = require 'utils.game'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local prefix = '## - '
|
||||
|
||||
global.mention_enabled = true
|
||||
|
||||
local hodor_messages = {
|
||||
{'Hodor.', 16},
|
||||
{'Hodor?', 16},
|
||||
@ -72,6 +76,7 @@ end
|
||||
|
||||
local function hodor(event)
|
||||
local message = event.message:lower()
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
if message:match('hodor') then
|
||||
local index = math.random(1, message_weight_sum)
|
||||
local message_weight_sum = 0
|
||||
@ -91,7 +96,6 @@ local function hodor(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -115,6 +119,34 @@ local function hodor(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Gives a sound notification to a mentioned player using @[player-name]
|
||||
if global.mention_enabled then
|
||||
local missing_player_string
|
||||
for word in event.message:gmatch('@%S+') do
|
||||
local cannot_mention = {}
|
||||
for _, p in ipairs(game.connected_players) do
|
||||
if '@'..p.name == word then
|
||||
if p.name == player.name then
|
||||
player.print(prefix..'Can\'t mention yourself!', {r = 1, g = 0, b = 0, a = 1})
|
||||
break;
|
||||
end
|
||||
p.print('## - '..Game.get_player_by_index(event.player_index).name..' mentioned you!', {r = 1, g = 1, b = 0, a = 1})
|
||||
p.play_sound{path='utility/new_objective', volume_modifier = 1}
|
||||
player.print(prefix..'Successful mentioned '..p.name, {r = 0, g = 1, b = 0, a = 1})
|
||||
else
|
||||
table.insert(cannot_mention, string.sub((word .. ', '), 2))
|
||||
end
|
||||
end
|
||||
for _, pname in ipairs(cannot_mention) do
|
||||
missing_player_string = missing_player_string~=nil and missing_player_string .. pname or pname
|
||||
end
|
||||
end
|
||||
if missing_player_string ~= nil then
|
||||
missing_player_string = string.sub(missing_player_string, 1, (string.len(missing_player_string)-2))
|
||||
player.print(prefix..'Failed to mention: ' .. missing_player_string, {r = 1, g = 1, b = 0, a = 1})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_console_chat, hodor)
|
||||
|
Loading…
Reference in New Issue
Block a user