From ab58b640bce10904794d5b5c9dda8cd5543b5477 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 4 Jan 2018 14:09:07 +0000 Subject: [PATCH] Added Discord Logging --- Addons/Admin/admin.lua | 31 ++++++++++++++++++----- Addons/Admin/discord.lua | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 Addons/Admin/discord.lua diff --git a/Addons/Admin/admin.lua b/Addons/Admin/admin.lua index 4f7a4bf3..2d270034 100644 --- a/Addons/Admin/admin.lua +++ b/Addons/Admin/admin.lua @@ -71,8 +71,14 @@ function Admin.ban(player,by_player,reason) local player = Game.get_player(player) local _player = Game.get_player(by_player) local reason = append_name(reason,_player) - local color = Color.to_hex(defines.text_color.crit) - discord_emit{title='Player Ban',color=color,description='There was a player banned.',['Player:']='<>'..player.name,['By:']='<>'.._player.name,['Reason:']=reason} + discord_emit{ + title='Player Ban', + color=Color.to_hex(defines.text_color.crit), + description='There was a player banned.', + ['Player:']='<>'..player.name, + ['By:']='<>'.._player.name, + ['Reason:']=reason + } game.ban_player(player,reason) end @@ -90,8 +96,14 @@ function Admin.kick(player,by_player,reason) local player = Game.get_player(player) local _player = Game.get_player(by_player) local reason = append_name(reason,_player) - local color = Color.to_hex(defines.text_color.high) - discord_emit{title='Player Kick',color=color,description='There was a player kicked.',['Player:']='<>'..player.name,['By:']='<>'.._player.name,['Reason:']=reason} + discord_emit{ + title='Player Kick', + color=Color.to_hex(defines.text_color.high), + description='There was a player kicked.', + ['Player:']='<>'..player.name, + ['By:']='<>'.._player.name, + ['Reason:']=reason + } game.kick_player(player,reason) end @@ -109,8 +121,15 @@ function Admin.jail(player,by_player,reason) local player = Game.get_player(player) local _player = Game.get_player(by_player) local reason = append_name(reason,_player) - local color = Color.to_hex(defines.text_color.med) - discord_emit{title='Player Jail',color=color,description='There was a player jailed.',['Player:']=player.name,['By:']='<>'.._player.name,['Reason:']=reason} + discord_emit{ + title='Player Jail', + color=Color.to_hex(defines.text_color.med), + description='There was a player jailed.', + ['Player:']=player.name, + ['By:']='<>'.._player.name, + ['Reason:']=reason + } + Ranking._presets().last_jail = player.name Ranking.give_rank(player,'Jail',_player) end diff --git a/Addons/Admin/discord.lua b/Addons/Admin/discord.lua new file mode 100644 index 00000000..3b3fb063 --- /dev/null +++ b/Addons/Admin/discord.lua @@ -0,0 +1,53 @@ +--[[ +Explosive Gaming + +This file can be used with permission but this and the credit below must remain in the file. +Contact a member of management on our discord to seek permission to use our code. +Any changes that you may make to the code are yours but that does not make the script yours. +Discord: https://discord.gg/r6dC2uK +]] +--Please Only Edit Below This Line----------------------------------------------------------- + +Event.register(defines.events.on_console_command,function(event) + local command = event.command + local args = {} + if event.parameters then for word in event.parameters:gmatch('%S+') do table.insert(args,word) end end + local data = {} + data.title = string.gsub(command,'^%l',string.upper) + data.by = event.player_index and game.players[event.player_index].name or '' + if command == 'config' or command == 'banlist' then + discord_emit{ + title='Edit To '..data.title, + color=Color.to_hex(defines.text_color.bg), + description='A player edited the '..command..'.', + ['By:']=data.by, + ['Edit:']=table.concat(args,' ',1) + } + else + if command == 'ban' then + data.colour = Color.to_hex(defines.text_color.crit) + data.reason = table.concat(args,' ',2) + elseif command == 'kick' then + data.colour = Color.to_hex(defines.text_color.med) + data.reason = table.concat(args,' ',2) + elseif command == 'unban' then data.colour = Color.to_hex(defines.text_color.low) + elseif command == 'mute' then data.colour = Color.to_hex(defines.text_color.med) + elseif command == 'unmute' then data.colour = Color.to_hex(defines.text_color.low) + elseif command == 'promote' then data.colour = Color.to_hex(defines.text_color.info) + elseif command == 'demote' then data.colour = Color.to_hex(defines.text_color.info) + elseif command == 'purge' then data.colour = Color.to_hex(defines.text_color.med) + else return end + data.username = args[1] + if not Game.get_player(data.username) then return end + if string.sub(command,-1) == 'e' then data.command = command..'d' else data.command = command..'ed' end + data.reason = data.reason or 'No Reason Required' + discord_emit{ + title='Player '..data.title, + color=data.colour, + description='There was a player '..data.command..'.', + ['Player:']='<>'..data.username, + ['By:']='<>'..data.by, + ['Reason:']=data.reason + } + end +end) \ No newline at end of file