Fixed Chat Reply

This commit is contained in:
Cooldude2606
2020-08-14 02:17:51 +01:00
parent e0eba193a4
commit 97f2d9b967
7 changed files with 81 additions and 86 deletions

View File

@@ -4,115 +4,117 @@
local Async = require 'expcore.async' local Async = require 'expcore.async'
local format_time = _C.format_time --- @dep expcore.common local format_time = _C.format_time --- @dep expcore.common
-- eg Async(async_message, is_command or player, message)
local async_message = Async.register(function(player, message) local async_message = Async.register(function(player, message)
player.print(message) if player == true then game.print(message) else player.print(message) end
end) end)
-- luacheck:ignore 212/player 212/is_command
return { return {
allow_command_prefix_for_messages = true, --- @setting allow_command_prefix_for_messages when true any message trigger will print to all player when prefixed allow_command_prefix_for_messages = true, --- @setting allow_command_prefix_for_messages when true any message trigger will print to all player when prefixed
messages = { --- @setting messages will trigger when ever the word is said messages = { --- @setting messages will trigger when ever the word is said
['discord']={'info.discord'}, ['discord'] = {'info.discord'},
['expgaming']={'info.website'}, ['expgaming'] = {'info.website'},
['website']={'info.website'}, ['website'] = {'info.website'},
['wiki']={'info.wiki'}, ['wiki'] = {'info.wiki'},
['status']={'info.status'}, ['status'] = {'info.status'},
['github']={'info.github'}, ['github'] = {'info.github'},
['patreon']={'info.patreon'}, ['patreon'] = {'info.patreon'},
['donate']={'info.patreon'}, ['donate'] = {'info.patreon'},
['command']={'info.custom-commands'}, ['command'] = {'info.custom-commands'},
['commands']={'info.custom-commands'}, ['commands'] = {'info.custom-commands'},
['softmod']={'info.softmod'}, ['softmod'] = {'info.softmod'},
['script']={'info.softmod'}, ['script'] = {'info.softmod'},
['loop']={'chat-bot.loops'}, ['loop'] = {'chat-bot.loops'},
['rhd']={'info.lhd'}, ['rhd'] = {'info.lhd'},
['lhd']={'info.lhd'}, ['lhd'] = {'info.lhd'},
['roundabout']={'chat-bot.loops'}, ['roundabout'] = {'chat-bot.loops'},
['roundabouts']={'chat-bot.loops'}, ['roundabouts'] = {'chat-bot.loops'},
['redmew']={'info.redmew'}, ['redmew'] = {'info.redmew'},
['afk']=function(player) ['afk'] = function(player)
local max=player local max = player
for _,next_player in pairs(game.connected_players) do for _, next_player in pairs(game.connected_players) do
if max.afk_time < next_player.afk_time then if max.afk_time < next_player.afk_time then
max=next_player max = next_player
end end
end end
return {'chat-bot.afk',max.name,format_time(max.afk_time,{minutes=true,seconds=true,long=true})} return {'chat-bot.afk', max.name, format_time(max.afk_time, {minutes = true, seconds = true, long = true})}
end, end,
['players']=function() ['players'] = function()
return {'chat-bot.players',#game.players} return {'chat-bot.players', #game.players}
end, end,
['online']=function() ['online'] = function()
return {'chat-bot.players-online',#game.connected_players} return {'chat-bot.players-online', #game.connected_players}
end, end,
['r!verify']=function(player) ['r!verify'] = function(player)
return {'chat-bot.verify',player.name} return {'chat-bot.verify', player.name}
end, end,
}, },
command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins
command_permission = 'command/chat-bot', --- @setting command_permission the permission used to allow command prefixes command_permission = 'command/chat-bot', --- @setting command_permission the permission used to allow command prefixes
command_prefix = '!', --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above) command_prefix = '!', --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above)
commands = { --- @setting commands will trigger only when command prefix is given commands = { --- @setting commands will trigger only when command prefix is given
['dev']={'chat-bot.not-real-dev'}, ['dev'] = {'chat-bot.not-real-dev'},
['blame']=function(player) ['blame'] = function(player)
local names = {'Cooldude2606','arty714','badgamernl', 'mark9064', 'aldldl', 'Drahc_pro',player.name} local names = {'Cooldude2606', 'arty714', 'badgamernl', 'mark9064', 'aldldl', 'Drahc_pro', player.name}
for _,next_player in pairs(game.connected_players) do for _, next_player in pairs(game.connected_players) do
names[#names + 1] = next_player.name names[#names + 1] = next_player.name
end end
return {'chat-bot.blame',table.get_random_dictionary_entry(names)} return {'chat-bot.blame', table.get_random_dictionary_entry(names)}
end, end,
['magic']={'chat-bot.magic'}, ['magic'] = {'chat-bot.magic'},
['aids']={'chat-bot.aids'}, ['aids'] = {'chat-bot.aids'},
['riot']={'chat-bot.riot'}, ['riot'] = {'chat-bot.riot'},
['lenny']={'chat-bot.lenny'}, ['lenny'] = {'chat-bot.lenny'},
['hodor']=function() ['hodor'] = function()
local options = {'?','.','!','!!!'} local options = {'?', '.', '!', '!!!'}
return {'chat-bot.hodor',table.get_random_dictionary_entry(options)} return {'chat-bot.hodor', table.get_random_dictionary_entry(options)}
end, end,
['evolution']=function() ['evolution'] = function()
return {'chat-bot.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)} return {'chat-bot.current-evolution', string.format('%.2f', game.forces['enemy'].evolution_factor)}
end, end,
['makepopcorn']=function(player) ['makepopcorn'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-popcorn-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-popcorn-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-popcorn-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-popcorn-2', player.name}})
end, end,
['passsomesnaps']=function(player) ['passsomesnaps'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-snaps-1'}}) Async(async_message, player, {'chat-bot.reply', {'chat-bot.get-snaps-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-snaps-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-snaps-2', player.name}})
Async.wait(timeout*(math.random()+0.5),async_message,player,{'chat-bot.reply',{'chat-bot.get-snaps-3',player.name}}) Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.get-snaps-3', player.name}})
end, end,
['makecocktail']=function(player) ['makecocktail'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-cocktail-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-cocktail-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-2', player.name}})
Async.wait(timeout*(math.random()+0.5),async_message,player,{'chat-bot.reply',{'chat-bot.get-cocktail-3',player.name}}) Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-3', player.name}})
end, end,
['makecoffee']=function(player) ['makecoffee'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.make-coffee-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.make-coffee-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.make-coffee-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.make-coffee-2', player.name}})
end, end,
['orderpizza']=function(player) ['orderpizza'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.order-pizza-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.order-pizza-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-2', player.name}})
Async.wait(timeout*(math.random()+0.5),async_message,player,{'chat-bot.reply',{'chat-bot.order-pizza-3',player.name}}) Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-3', player.name}})
end, end,
['maketea']=function(player) ['maketea'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.make-tea-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.make-tea-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.make-tea-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.make-tea-2', player.name}})
end, end,
['meadplease']=function(player) ['meadplease'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-mead-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-mead-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-mead-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-mead-2', player.name}})
end, end,
['passabeer']=function(player) ['passabeer'] = function(player)
local timeout = math.floor(180*(math.random()+0.5)) local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-beer-1'}}) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-beer-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-beer-2',player.name}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-beer-2', player.name}})
end end
} }
} }

View File

@@ -5,7 +5,6 @@
-- @config Permission-Groups -- @config Permission-Groups
--local Event = require 'utils.event' -- @dep utils.event --local Event = require 'utils.event' -- @dep utils.event
--local Game = require 'utils.game' -- @dep utils.game
local Permission_Groups = require 'expcore.permission_groups' --- @dep expcore.permission_groups local Permission_Groups = require 'expcore.permission_groups' --- @dep expcore.permission_groups
Permission_Groups.new_group('Admin') Permission_Groups.new_group('Admin')

View File

@@ -1,8 +1,7 @@
--- Adds auto replies to chat messages; aswell as chat commands --- Adds auto replies to chat messages; as well as chat commands
-- @addon Chat-Reply -- @addon Chat-Reply
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Roles = require 'expcore.roles' --- @dep expcore.roles local Roles = require 'expcore.roles' --- @dep expcore.roles
local config = require 'config.chat_reply' --- @dep config.chat_reply local config = require 'config.chat_reply' --- @dep config.chat_reply
@@ -18,16 +17,15 @@ Event.add(defines.events.on_console_chat, function(event)
local prefix = config.command_prefix local prefix = config.command_prefix
for key_word, reply in pairs(config.messages) do for key_word, reply in pairs(config.messages) do
if message:find(key_word) then if message:find(key_word) then
local is_command = message:find(prefix..key_word)
if type(reply) == 'function' then if type(reply) == 'function' then
reply = reply(player) reply = reply(player, is_command)
end end
if message:find(prefix..key_word) then if is_command and allowed then
if allowed then game.print{'chat-bot.reply', reply}
game.print{'chat-bot.reply', reply} elseif is_command then
else player.print{'chat-bot.disallow'}
player.print{'chat-bot.disallow'}
end
elseif not allowed then elseif not allowed then
player.print{'chat-bot.reply', reply} player.print{'chat-bot.reply', reply}
end end
@@ -39,7 +37,7 @@ Event.add(defines.events.on_console_chat, function(event)
for key_word, reply in pairs(config.commands) do for key_word, reply in pairs(config.commands) do
if message:find(prefix..key_word) then if message:find(prefix..key_word) then
if type(reply) == 'function' then if type(reply) == 'function' then
reply = reply(player) reply = reply(player, true)
if reply then if reply then
game.print{'chat-bot.reply', reply} game.print{'chat-bot.reply', reply}

View File

@@ -3,7 +3,6 @@
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local Global = require 'utils.global' --- @dep utils.global local Global = require 'utils.global' --- @dep utils.global
local Game = require 'utils.game' --- @dep utils.game
local Task = require 'utils.task' --- @dep utils.task local Task = require 'utils.task' --- @dep utils.task
local Token = require 'utils.token' --- @dep utils.token local Token = require 'utils.token' --- @dep utils.token
local config = require 'config.compilatron' --- @dep config.compilatron local config = require 'config.compilatron' --- @dep config.compilatron

View File

@@ -2,7 +2,6 @@
-- @addon Discord-Alerts -- @addon Discord-Alerts
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Colors = require 'utils.color_presets' --- @dep utils.color_presets local Colors = require 'utils.color_presets' --- @dep utils.color_presets
local write_json, format_time = _C.write_json, _C.format_time --- @dep expcore.common local write_json, format_time = _C.write_json, _C.format_time --- @dep expcore.common
local config = require 'config.discord_alerts' --- @dep config.discord_alerts local config = require 'config.discord_alerts' --- @dep config.discord_alerts

View File

@@ -3,7 +3,6 @@
local Global = require 'utils.global' --- @dep utils.global local Global = require 'utils.global' --- @dep utils.global
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local config = require 'config.spawn_area' --- @dep config.spawn_area local config = require 'config.spawn_area' --- @dep config.spawn_area
local tiles = config.tiles local tiles = config.tiles
local entities = config.entities local entities = config.entities

View File

@@ -2,7 +2,6 @@
-- @addon Tree-Decon -- @addon Tree-Decon
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Global = require 'utils.global' --- @dep utils.global local Global = require 'utils.global' --- @dep utils.global
local Roles = require 'expcore.roles' --- @dep expcore.roles local Roles = require 'expcore.roles' --- @dep expcore.roles