2018-11-11 06:00:28 +02:00
-- This feature auto-responds to key words or phrases. We use the name/actor Hodor because it is Redmew's beloved discord bot.
local Game = require ' utils.game '
local Event = require ' utils.event '
2018-11-17 13:56:03 +02:00
require ' utils.list_utils '
local Hodor = require ' resources.hodor_messages '
2018-11-11 06:00:28 +02:00
2018-11-17 15:22:51 +02:00
local prefix = ' ## - '
global.mention_enabled = true
2018-11-11 19:12:38 +02:00
local auto_replies = {
[ ' discord ' ] = { ' Did you ask about our discord server? ' , ' You can find it here: redmew.com/discord ' } ,
[ ' patreon ' ] = { ' Did you ask about our patreon? ' , ' You can find it here: patreon.com/redmew ' } ,
[ ' donate ' ] = { ' Did you ask about donating to the server? ' , ' You can find our patreon here: patreon.com/redmew ' } ,
[ ' grief ' ] = { ' To report grief please use the /report function. ' , ' If no admins are online use #moderation-requests on the discord and make sure the @mention the appropriate role. ' }
2018-11-11 06:00:28 +02:00
}
global.naughty_words_enabled = false
global.naughty_words = {
[ ' ass ' ] = true ,
[ ' bugger ' ] = true ,
[ ' butt ' ] = true ,
[ ' bum ' ] = true ,
[ ' bummer ' ] = true ,
[ ' christ ' ] = true ,
[ ' crikey ' ] = true ,
[ ' darn ' ] = true ,
[ ' dam ' ] = true ,
[ ' damn ' ] = true ,
[ ' dang ' ] = true ,
[ ' dagnabit ' ] = true ,
[ ' dagnabbit ' ] = true ,
[ ' drat ' ] = true ,
[ ' fart ' ] = true ,
[ ' feck ' ] = true ,
[ ' frack ' ] = true ,
[ ' freaking ' ] = true ,
[ ' frick ' ] = true ,
[ ' gay ' ] = true ,
[ ' gee ' ] = true ,
[ ' geez ' ] = true ,
[ ' git ' ] = true ,
[ ' god ' ] = true ,
[ ' golly ' ] = true ,
[ ' gosh ' ] = true ,
[ ' heavens ' ] = true ,
[ ' heck ' ] = true ,
[ ' hell ' ] = true ,
[ ' holy ' ] = true ,
[ ' jerk ' ] = true ,
[ ' jesus ' ] = true ,
[ ' petes ' ] = true ,
[ " pete's " ] = true ,
[ ' poo ' ] = true ,
[ ' satan ' ] = true ,
[ ' willy ' ] = true ,
[ ' wee ' ] = true ,
[ ' yikes ' ] = true
}
local function hodor ( event )
local message = event.message : lower ( )
2018-11-15 17:03:46 +02:00
2018-11-11 06:00:28 +02:00
if message : match ( ' hodor ' ) then
2018-11-17 13:56:03 +02:00
game.print ( ' Hodor: ' .. table.get_random_weighted ( Hodor , 1 , 2 ) )
2018-11-11 06:00:28 +02:00
end
-- player_index is nil if the message came from the server,
-- and indexing Game.players with nil is apparently an error.
local player_index = event.player_index
if not player_index then
return
end
2018-11-22 14:17:07 +02:00
local player = Game.get_player_by_index ( event.player_index )
2018-11-11 06:00:28 +02:00
if not player or not player.valid then
return
end
2018-11-17 13:56:03 +02:00
2018-11-11 06:00:28 +02:00
if not player.admin then
2018-11-11 19:12:38 +02:00
for trigger , replies in pairs ( auto_replies ) do
if message : match ( trigger ) then
for _ , reply in pairs ( replies ) do
player.print ( reply )
2018-11-11 06:00:28 +02:00
end
end
end
end
if global.naughty_words_enabled then
local naughty_words = global.naughty_words
for word in message : gmatch ( ' %S+ ' ) do
if naughty_words [ word ] then
game.print ( player.name .. ' this is a Christian Factorio server, no swearing please! ' )
break
end
end
end
2018-11-15 16:06:03 +02:00
2018-11-18 14:26:15 +02:00
-- Gives a sound notification to a mentioned player using #[player-name], [player-name]#, @[player-name], [player-name]@ or to admins with moderator or admin without prefix or postfix
2018-11-15 16:06:03 +02:00
if global.mention_enabled then
local missing_player_string
2018-11-15 17:03:46 +02:00
local not_found = 0
2018-11-16 22:32:38 +02:00
local cannot_mention = { }
2018-11-20 12:46:19 +02:00
for w in event.message : gmatch ( ' %S+ ' ) do
local word = w : lower ( )
2018-11-17 12:10:11 +02:00
local trimmed_word = string.sub ( word , 0 , string.len ( word ) - 1 )
2018-11-18 14:26:15 +02:00
local first_char = string.sub ( word , 0 , 1 )
local last_char = string.sub ( word , string.len ( word ) )
2018-11-16 22:32:38 +02:00
local success = false
local admin_call = false
2018-11-18 23:41:24 +02:00
if word == ' admin ' or word == ' moderator ' or trimmed_word == ' admin ' or trimmed_word == ' moderator ' then
2018-11-15 17:46:04 +02:00
admin_call = true
2018-11-18 14:26:15 +02:00
elseif ( first_char ~= ' # ' and last_char ~= ' # ' ) and ( first_char ~= ' @ ' and last_char ~= ' @ ' ) then
success = true
2018-11-15 17:46:04 +02:00
end
2018-11-18 14:26:15 +02:00
if not success then
for _ , p in ipairs ( game.connected_players ) do
local word_front_trim = string.sub ( word , 2 , string.len ( word ) )
local word_back_trim = trimmed_word
local word_front_back_trim = string.sub ( word_front_trim , 0 , string.len ( word_front_trim ) - 1 )
local word_back_double_trim = string.sub ( word_back_trim , 0 , string.len ( word_back_trim ) - 1 )
2018-11-18 23:41:24 +02:00
word = ( trimmed_word == ' admin ' or trimmed_word == ' moderator ' ) and trimmed_word or word
2018-11-18 14:26:15 +02:00
if admin_call and p.admin then
p.print ( prefix .. Game.get_player_by_index ( event.player_index ) . name .. ' mentioned ' .. word .. ' ! ' , { r = 1 , g = 1 , b = 0 , a = 1 } )
p.play_sound { path = ' utility/new_objective ' , volume_modifier = 1 }
success = true
end
2018-11-18 23:41:24 +02:00
if not admin_call and ( p.name : lower ( ) == word_front_trim or p.name : lower ( ) == word_back_trim or p.name : lower ( ) == word_back_double_trim or p.name : lower ( ) == word_front_back_trim ) then
2018-11-18 14:26:15 +02:00
if p.name == player.name then
if _DEBUG then
player.print ( prefix .. ' Can \' t mention yourself! ' , { r = 1 , g = 0 , b = 0 , a = 1 } )
end
success = true
break ;
2018-11-17 14:46:23 +02:00
end
2018-11-18 14:26:15 +02:00
p.print ( prefix .. 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 }
2018-11-16 22:32:38 +02:00
success = true
2018-11-18 14:26:15 +02:00
if _DEBUG then
player.print ( prefix .. ' Successful mentioned ' .. p.name , { r = 0 , g = 1 , b = 0 , a = 1 } )
end
2018-11-15 16:06:03 +02:00
break ;
end
end
end
2018-11-17 15:22:51 +02:00
if not success then
if admin_call then
word = ' no ' .. word .. ' s online! '
end
2018-11-16 22:32:38 +02:00
not_found = not_found + 1
table.insert ( cannot_mention , ( word .. ' , ' ) )
2018-11-17 15:22:51 +02:00
end
2018-11-16 22:32:38 +02:00
end
2018-11-17 15:22:51 +02:00
for _ , pname in ipairs ( cannot_mention ) do
2018-11-16 22:32:38 +02:00
missing_player_string = missing_player_string ~= nil and missing_player_string .. pname or pname
2018-11-17 15:22:51 +02:00
end
if missing_player_string ~= nil then
2018-11-15 16:06:03 +02:00
missing_player_string = string.sub ( missing_player_string , 1 , ( string.len ( missing_player_string ) - 2 ) )
2018-11-15 17:03:46 +02:00
if not_found > 1 then
player.print ( prefix .. ' Players not found: ' .. missing_player_string , { r = 1 , g = 1 , b = 0 , a = 1 } )
else
player.print ( prefix .. ' Player not found: ' .. missing_player_string , { r = 1 , g = 1 , b = 0 , a = 1 } )
end
2018-11-17 15:22:51 +02:00
end
2018-11-15 16:06:03 +02:00
end
2018-11-11 06:00:28 +02:00
end
2018-11-18 14:26:15 +02:00
2018-11-11 18:08:05 +02:00
Event.add ( defines.events . on_console_chat , hodor )