1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-03 14:53:01 +02:00

Split chat triggers from control

This commit is contained in:
plague006 2018-11-10 23:00:28 -05:00
parent bac8b0bc87
commit d45a486cde
2 changed files with 122 additions and 106 deletions

View File

@ -31,6 +31,7 @@ require 'blueprint_helper'
require 'paint'
require 'score'
require 'popup'
require 'features.chat_triggers'
local Event = require 'utils.event'
local Donators = require 'resources.donators'
@ -56,111 +57,6 @@ local function player_created(event)
gui.left.style = 'slot_table_spacing_vertical_flow'
end
local hodor_messages = {
{'Hodor.', 16},
{'Hodor?', 16},
{'Hodor!', 16},
{'Hodor! Hodor! Hodor! Hodor!', 4},
{'Hodor :(', 4},
{'Hodor :)', 4},
{'HOOOODOOOR!', 4},
{'( ͡° ͜ʖ ͡°)', 1},
{'☉ ‿ ⚆', 1}
}
local message_weight_sum = 0
for _, w in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + w[2]
end
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
local index = math.random(1, message_weight_sum)
local message_weight_sum = 0
for _, m in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + m[2]
if message_weight_sum >= index then
game.print('Hodor: ' .. m[1])
break
end
end
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
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
if message:match('discord') then
player.print('Did you ask about our discord server?')
player.print('You can find it here: redmew.com/discord')
end
if message:match('patreon') then
player.print('Did you ask about our patreon?')
player.print('You can find it here: patreon.com/redmew')
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
end
local function player_joined(event)
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
@ -177,7 +73,6 @@ end
Event.add(defines.events.on_player_created, player_created)
Event.add(defines.events.on_player_joined_game, player_joined)
Event.add(defines.events.on_console_chat, hodor)
Event.add(
defines.events.on_console_command,

121
features/chat_triggers.lua Normal file
View File

@ -0,0 +1,121 @@
-- 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'
local hodor_messages = {
{'Hodor.', 16},
{'Hodor?', 16},
{'Hodor!', 16},
{'Hodor! Hodor! Hodor! Hodor!', 4},
{'Hodor :(', 4},
{'Hodor :)', 4},
{'HOOOODOOOR!', 4},
{'( ͡° ͜ʖ ͡°)', 1},
{'☉ ‿ ⚆', 1}
}
local auto_responses = {
{trigger = 'discord', response1 = 'Did you ask about our discord server?', response2 = 'You can find it here: redmew.com/discord'},
{trigger = 'patreon', response1 = 'Did you ask about our patreon?', response2 = 'You can find it here: patreon.com/redmew'},
{trigger = 'donate', response1 = 'Did you ask about donating to the server?', response2 = 'You can find our patreon here: patreon.com/redmew'},
{trigger = 'grief', response1 = 'To report a griefer please use the /report function.', response2 = '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 message_weight_sum = 0
for _, w in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + w[2]
end
local function hodor(event)
local message = event.message:lower()
if message:match('hodor') then
local index = math.random(1, message_weight_sum)
local message_weight_sum = 0
for _, m in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + m[2]
if message_weight_sum >= index then
game.print('Hodor: ' .. m[1])
break
end
end
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
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
if not player.admin then
for _, r in pairs(auto_responses) do
if message:match(r.trigger) then
player.print(r.response1)
if r.response2 then
player.print(r.response2)
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
end
Event.add(defines.events.on_console_chat, hodor)