Skip to content

Commit

Permalink
Merge pull request #27 from vugi99/custombotjoinleavetoggle
Browse files Browse the repository at this point in the history
Add bot join leave messages toggle
  • Loading branch information
StyledStrike authored Jul 31, 2024
2 parents f8ec2f8 + b1c74a7 commit e19b1d9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lua/custom_chat/client/join_leave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ local JoinLeave = CustomChat.JoinLeave or {

leaveColor = { 244, 144, 12 },
leavePrefix = ":small_orange_diamond:",
leaveSuffix = "left!"
leaveSuffix = "left!",

botConnectDisconnect = false,
}

CustomChat.JoinLeave = JoinLeave
Expand All @@ -24,6 +26,8 @@ hook.Add( "player_connect_client", "CustomChat.ShowConnectMessages", function( d
local steamId = data.networkid
local isBot = data.bot == 1

if (isBot and (not JoinLeave.botConnectDisconnect)) then return end

Check warning on line 29 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space after parenthesis"

Style: Please add a space after the parenthesis

Check warning on line 29 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space after parenthesis"

Style: Please add a space after the parenthesis

Check warning on line 29 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space before parenthesis"

Style: Please add a space before the parenthesis

-- Only use a player block if Custom Chat is enabled
if CustomChat.IsEnabled() then
name = {
Expand Down Expand Up @@ -53,6 +57,8 @@ hook.Add( "player_disconnect", "CustomChat.ShowDisconnectMessages", function( da
local steamId = data.networkid
local isBot = data.bot == 1

if (isBot and (not JoinLeave.botConnectDisconnect)) then return end

Check warning on line 60 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space after parenthesis"

Style: Please add a space after the parenthesis

Check warning on line 60 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space after parenthesis"

Style: Please add a space after the parenthesis

Check warning on line 60 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space before parenthesis"

Style: Please add a space before the parenthesis

-- Only use a player block if Custom Chat is enabled
if CustomChat.IsEnabled() then
name = {
Expand All @@ -76,6 +82,8 @@ hook.Add( "player_disconnect", "CustomChat.ShowDisconnectMessages", function( da
end, HOOK_LOW )

local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
if (ply:IsBot() and (not JoinLeave.botConnectDisconnect)) then return end

Check warning on line 85 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space after parenthesis"

Style: Please add a space after the parenthesis

Check warning on line 85 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space after parenthesis"

Style: Please add a space after the parenthesis

Check warning on line 85 in lua/custom_chat/client/join_leave.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space before parenthesis"

Style: Please add a space before the parenthesis

-- Only use a player block if Custom Chat is enabled
if CustomChat.IsEnabled() then
name = {
Expand Down
4 changes: 3 additions & 1 deletion lua/custom_chat/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ end
local function CustomChat_OnChatText( _, _, text, textType )
if textType == "chat" then return end

local canShowJoinLeave = not ( CustomChat.JoinLeave.showConnect or CustomChat.JoinLeave.showDisconnect )
local canShowJoinLeave = not ( CustomChat.JoinLeave.showConnect or CustomChat.JoinLeave.showDisconnect)

Check warning on line 479 in lua/custom_chat/client/main.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Space before parenthesis"

Style: Please add a space before the parenthesis
if not canShowJoinLeave and textType == "joinleave" then return end

CustomChat:AddMessage( { Color( 0, 128, 255 ), text } )
Expand Down Expand Up @@ -657,6 +657,8 @@ hook.Add( "NetPrefs_OnChange", "CustomChat.OnServerConfigChange", function( key,
JoinLeave.leaveColor = data.connection.leaveColor
JoinLeave.leavePrefix = data.connection.leavePrefix
JoinLeave.leaveSuffix = data.connection.leaveSuffix

JoinLeave.botConnectDisconnect = data.connection.botConnectDisconnect
end
end )

Expand Down
12 changes: 12 additions & 0 deletions lua/custom_chat/client/tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,18 @@ function Tags:OpenEditor()
panelConnectionTags:SetPaintBackground( false )
sheet:AddSheet( L"tab.conn_disconn", panelConnectionTags, "icon16/group_go.png" )

local checkBotJoinLeave = vgui.Create( "DCheckBoxLabel", panelConnectionTags )
checkBotJoinLeave:SetText( L"tags.show_bot_joinleave_messages" )
checkBotJoinLeave:SetTextColor( Color( 255, 255, 255 ) )
checkBotJoinLeave:SetValue( byConnection.botConnectDisconnect )
checkBotJoinLeave:SizeToContents()
checkBotJoinLeave:Dock( TOP )
checkBotJoinLeave:DockPadding( 6, 6, 6, 6 )

checkBotJoinLeave.OnChange = function( _, val )
byConnection.botConnectDisconnect = val
end

-- Connect messages
local panelConnect = vgui.Create( "DPanel", panelConnectionTags )
panelConnect:Dock( LEFT )
Expand Down
1 change: 1 addition & 0 deletions resource/localization/en/custom_chat.properties
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ custom_chat.tags.leave_suffix=Leave suffix
custom_chat.tags.leave_color=Disconnected player color
custom_chat.tags.apply=Apply all changes
custom_chat.tags.apply_query=This action will apply the chat tags and join/leave messages to this server. Are you sure?
custom_chat.tags.show_bot_joinleave_messages=Show Bots Join/Leave messages
custom_chat.emojis.title=Server Emojis
custom_chat.emojis.invalid=Invalid Emoji
custom_chat.emojis.invalid_reason=Invalid emoji (%d): %s
Expand Down

0 comments on commit e19b1d9

Please sign in to comment.