1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-02-09 13:37:05 +02:00

Break chat_trigger functions apart

This commit is contained in:
Matthew Heguy 2018-11-26 01:49:18 -05:00
parent 12d779b46f
commit de87998299
5 changed files with 173 additions and 128 deletions

View File

@ -7,8 +7,6 @@ local Hodor = require 'resources.hodor_messages'
local prefix = '## - '
global.mention_enabled = true
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'},
@ -16,69 +14,37 @@ local auto_replies = {
['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.'}
}
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()
if message:match('hodor') then
game.print('Hodor: ' .. table.get_random_weighted(Hodor, 1, 2))
end
--- Check for player and get player
local function get_player(event)
-- 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
return false
end
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
return false
end
return player
end
if not player.admin then
--- Emulates the discord bot hodor's reaction to his name
local function hodor(event)
-- first check for a match, since 99% of messages aren't a match for 'hodor'
local message = event.message:lower()
if message:match('hodor') then
game.print('Hodor: ' .. table.get_random_weighted(Hodor, 1, 2))
end
end
--- Automatically responds to preset trigger words
local function auto_respond(event)
local message = event.message:lower()
local player = get_player(event)
if player and not player.admin then
for trigger, replies in pairs(auto_replies) do
if message:match(trigger) then
for _, reply in pairs(replies) do
@ -87,85 +53,93 @@ local function hodor(event)
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
--- Create notifications when a player's name is mentioned
local function mentions(event)
-- 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
local missing_player_string
local not_found = 0
local cannot_mention = {}
local player = get_player(event)
if not player or not player.valid then
return
end
-- 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
if global.mention_enabled then
local missing_player_string
local not_found = 0
local cannot_mention = {}
for w in event.message:gmatch('%S+') do
local word = w:lower()
local trimmed_word = string.sub(word, 0, string.len(word)-1)
local first_char = string.sub(word, 0, 1)
local last_char = string.sub(word, string.len(word))
local success = false
local admin_call = false
if word == 'admin' or word == 'moderator' or trimmed_word == 'admin' or trimmed_word == 'moderator' then
admin_call = true
elseif (first_char ~= '#' and last_char ~= '#') and (first_char ~= '@' and last_char ~= '@') then
success = true
end
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)
word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word
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
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
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;
end
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 }
success = true
for w in event.message:gmatch('%S+') do
local word = w:lower()
local trimmed_word = string.sub(word, 0, string.len(word) - 1)
local first_char = string.sub(word, 0, 1)
local last_char = string.sub(word, string.len(word))
local success = false
local admin_call = false
if word == 'admin' or word == 'moderator' or trimmed_word == 'admin' or trimmed_word == 'moderator' then
admin_call = true
elseif (first_char ~= '#' and last_char ~= '#') and (first_char ~= '@' and last_char ~= '@') then
success = true
end
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)
word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word
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
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
if p.name == player.name then
if _DEBUG then
player.print(prefix..'Successful mentioned '..p.name, {r = 0, g = 1, b = 0, a = 1})
player.print(prefix .. "Can't mention yourself!", {r = 1, g = 0, b = 0, a = 1})
end
break;
success = true
break
end
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}
success = true
if _DEBUG then
player.print(prefix .. 'Successful mentioned ' .. p.name, {r = 0, g = 1, b = 0, a = 1})
end
break
end
end
if not success then
if admin_call then
word = 'no '.. word .. 's online!'
end
not_found = not_found + 1
table.insert(cannot_mention, (word .. ', '))
end
end
for _, pname in ipairs(cannot_mention) do
missing_player_string = missing_player_string~=nil and missing_player_string .. pname or pname
end
if missing_player_string ~= nil then
missing_player_string = string.sub(missing_player_string, 1, (string.len(missing_player_string)-2))
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})
if not success then
if admin_call then
word = 'no ' .. word .. 's online!'
end
not_found = not_found + 1
table.insert(cannot_mention, (word .. ', '))
end
end
for _, pname in ipairs(cannot_mention) do
missing_player_string = missing_player_string ~= nil and missing_player_string .. pname or pname
end
if missing_player_string ~= nil then
missing_player_string = string.sub(missing_player_string, 1, (string.len(missing_player_string) - 2))
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
end
end
local function on_console_chat(event)
if global.config.hodor then
hodor(event)
end
if global.config.auto_respond then
auto_respond(event)
end
if global.config.mentions then
mentions(event)
end
end
Event.add(defines.events.on_console_chat, hodor)
Event.add(defines.events.on_console_chat, on_console_chat)

View File

@ -0,0 +1,27 @@
local Game = require 'utils.game'
local Event = require 'utils.event'
global.naughty_words = require('resources.naughty_words')
local function admonish_blasphemy(event)
-- player_index is nil if the message came from the server,
-- and indexing Game.players with nil is apparently an error.
if not event.player_index then
return
end
local message = event.message:lower()
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
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
Event.add(defines.events.on_console_chat, admonish_blasphemy)

View File

@ -6,6 +6,8 @@ local Utils = require('utils.utils')
global.actual_name = {}
global.silly_names = {}
global.silly_names.count = 0
global.config.players_assigned_names = true -- assigns players random names when they first join
global.config.players_roll_names = true -- allows players to roll random names
local name_combinations = #naming_words.adverbs * #naming_words.adjectives * #naming_words.nouns
@ -144,15 +146,15 @@ local function get_player_id(cmd)
Game.player_print(target_name .. ' -- ' .. target_index)
end
if global.scenario.config.players_assigned_names == true then
if global.config.players_assigned_names == true then
Event.add(defines.events.on_player_created, name_player_event)
end
if global.scenario.config.players_roll_names == true then
if global.config.players_roll_names == true then
commands.add_command('name-roll', 'Assigns you a random, silly name', name_player_command)
end
if global.scenario.config.players_roll_names == true or global.scenario.config.players_assigned_names == true then
if global.config.players_roll_names == true or global.config.players_assigned_names == true then
commands.add_command('name-restore', 'Removes your fun name and gives you back your actual name', restore_name)
commands.add_command('name-check', '<player> Check the original name of a player', check_name)
commands.add_command('get-player-id', 'Gets the ID of a player (Admin only)', get_player_id)

View File

@ -136,10 +136,11 @@ local terrain_modules = {
--require ('map_gen.misc.danger_ore_banned_entities')
--require ('map_gen.misc.restrict_landfill_tile')({['water'] = true})
--require "map_gen.ores.rso.rso_control"
--require 'map_gen.misc.nightfall'
--require 'map_gen.misc.nightfall' -- forces idle biters to attack at night
--require 'map_gen.misc.creep_spread'
--require 'map_gen.misc.car_body'
--require 'features.silly_player_names'
--require 'map_gen.misc.car_body' -- gives players cars instead of characters
--require 'features.silly_player_names' -- assigns players random names when they first join
--require 'map_gen.misc.naughty_words' -- admonishes players for cursing
if #entity_modules > 0 then
shape = shape or b.full_shape

View File

@ -0,0 +1,41 @@
return {
['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
}