<commit_before>--------------------------------------------------------
-- This file is part of the JX3 Mingyi Plugin.
-- @link     : https://jx3.derzh.com/
-- @desc     : Ƶл
-- @author   :  @˫ @׷Ӱ
-- @modifier : <NAME> (<EMAIL>)
-- @copyright: Copyright (c) 2013 EMZ Kingsoft Co., Ltd.
--------------------------------------------------------
local _L = MY.LoadLangPack(MY.GetAddonInfo().szRoot .. 'MY_Chat/lang/')
local INI_PATH = MY.GetAddonInfo().szRoot .. 'MY_Chat/ui/MY_ChatSwitch.ini'
local CD_REFRESH_OFFSET = 7 * 60 * 60 -- 7CD
MY_ChatSwitch = {}
MY_ChatSwitch.aWhisper = {}
MY_ChatSwitch.szAway = nil
MY_ChatSwitch.szBusy = nil
RegisterCustomData('MY_ChatSwitch.szAway')
RegisterCustomData('MY_ChatSwitch.szBusy')

local function UpdateChannelDailyLimit(hRadio, bPlus)
	local me = GetClientPlayer()
	local shaCount = hRadio and hRadio.shaCount
	if not (me and shaCount) then
		return
	end

	local dwPercent = 1
	local info = hRadio.info
	local nChannel = info.channel
	if nChannel then
		local szDate = MY.FormatTime('yyyyMMdd', GetCurrentTime() - CD_REFRESH_OFFSET)
		if MY_ChatSwitch.tChannelCount.szDate ~= szDate then
			MY_ChatSwitch.tChannelCount = {szDate = szDate}
		end
		MY_ChatSwitch.tChannelCount[nChannel] = (MY_ChatSwitch.tChannelCount[nChannel] or 0) + (bPlus and 1 or 0)

		local nDailyCount = MY_ChatSwitch.tChannelCount[nChannel]
		local nDailyLimit = MY.GetChannelDailyLimit(me.nLevel, nChannel)
		if nDailyLimit then
			if nDailyLimit > 0 then
				dwPercent = (nDailyLimit - nDailyCount) / nDailyLimit
				hRadio.szTip = GetFormatText(_L('Today: %d\nDaily limit: %d', nDailyCount, nDailyLimit), nil, 255, 255, 0)
			else
				hRadio.szTip = GetFormatText(_L('Today: %d\nDaily limit: no limitation', nDailyCount), nil, 255, 255, 0)
			end
		end
	end
	XGUI(shaCount):drawCircle(nil, nil, nil, info.color[1], info.color[2], info.color[3], 100, math.pi / 2, math.pi * 2 * dwPercent)
end

local function OnClsCheck()
	local function Cls(bAll)
		for i = 1, 10 do
			local h = Station.Lookup('Lowest2/ChatPanel' .. i .. '/Wnd_Message', 'Handle_Message')
			local hCheck = Station.Lookup('Lowest2/ChatPanel' .. i .. '/CheckBox_Title')
			if h and (bAll or (hCheck and hCheck:IsCheckBoxChecked())) then
				h:Clear()
				h:FormatAllItemPos()
			end
		end
	end
	if IsCtrlKeyDown() then
		Cls()
	elseif IsAltKeyDown() then
		MessageBox({
			szName = 'CLS_CHATPANEL_ALL',
			szMessage = _L['Are you sure you want to clear all message panel?'], {
				szOption = g_tStrings.STR_HOTKEY_SURE, fnAction = function()
					Cls(true)
				end
			}, { szOption = g_tStrings.STR_HOTKEY_CANCEL },
		})
	else
		MessageBox({
			szName = 'CLS_CHATPANEL',
			szMessage = _L['Are you sure you want to clear current message panel?\nPress CTRL when click can clear without alert.\nPress ALT when click can clear all window.'], {
				szOption = g_tStrings.STR_HOTKEY_SURE, fnAction = function()
					Cls()
				end
			}, { szOption = g_tStrings.STR_HOTKEY_CANCEL },
		})
	end
	MY.UI(this):check(false)
end

local function OnAwayCheck()
	MY.SwitchChat('/afk')
	Station.Lookup('Lowest2/EditBox'):Show()
	if Station.Lookup('Lowest2/EditBox/Edit_Input'):GetText() == '' then
		Station.Lookup('Lowest2/EditBox/Edit_Input'):InsertText(MY_ChatSwitch.szAway or g_tStrings.STR_AUTO_REPLAY_LEAVE)
		Station.Lookup('Lowest2/EditBox/Edit_Input'):SelectAll()
	end
	Station.SetFocusWindow('Lowest2/EditBox/Edit_Input')
end

local function OnAwayUncheck()
	MY.SwitchChat('/cafk')
end

local function OnAwayTip() return MY_ChatSwitch.szAway or g_tStrings.STR_AUTO_REPLAY_LEAVE end

local function OnBusyCheck()
	MY.SwitchChat('/atr')
	Station.Lookup('Lowest2/EditBox'):Show()
	if Station.Lookup('Lowest2/EditBox/Edit_Input'):GetText() == '' then
		Station.Lookup('Lowest2/EditBox/Edit_Input'):InsertText(MY_ChatSwitch.szBusy or g_tStrings.STR_AUTO_REPLAY_LEAVE)
		Station.Lookup('Lowest2/EditBox/Edit_Input'):SelectAll()
	end
	Station.SetFocusWindow('Lowest2/EditBox/Edit_Input')
end

local function OnBusyUncheck()
	MY.SwitchChat('/catr')
end

local function OnBusyTip() return MY_ChatSwitch.szBusy end

local function OnMosaicsCheck()
	MY_ChatMosaics.bEnabled = true
	MY_ChatMosaics.ResetMosaics()
end

local function OnMosaicsUncheck()
	MY_ChatMosaics.bEnabled = false
	MY_ChatMosaics.ResetMosaics()
end

local function OnWhisperCheck()
	local t = {}
	for i, whisper in ipairs(MY_ChatSwitch.aWhisper) do
		local info = MY_Farbnamen.Get(whisper[1])
		table.insert(t, {
			szOption = whisper[1],
			rgb = info and info.rgb or {202, 126, 255},
			fnAction = function()
				MY.SwitchChat(whisper[1])
				MY.DelayCall(MY.FocusChatBox)
			end,
			szIcon = 'ui/Image/UICommon/CommonPanel2.UITex',
			nFrame = 49,
			nMouseOverFrame = 51,
			nIconWidth = 17,
			nIconHeight = 17,
			szLayer = 'ICON_RIGHTMOST',
			fnClickIcon = function()
				for i = #MY_ChatSwitch.aWhisper, 1, -1 do
					if MY_ChatSwitch.aWhisper[i][1] == whisper[1] then
						table.remove(MY_ChatSwitch.aWhisper, i)
						Wnd.CloseWindow('PopupMenuPanel')
					end
				end
			end,
			fnMouseEnter = function()
				local t = {}
				local today = MY.FormatTime('yyyyMMdd')
				local r, g, b = GetMsgFontColor('MSG_WHISPER')
				for _, v in ipairs(whisper[2]) do
					if type(v) == 'string' then
						table.insert(t, v)
					elseif type(v) == 'table' then
						if today == MY.FormatTime('yyyyMMdd', v[2]) then<commit_msg>修复聊天切换密聊按钮有可能挂掉的问题<commit_after>--------------------------------------------------------
-- This file is part of the JX3 Mingyi Plugin.
-- @link     : https://jx3.derzh.com/
-- @desc     : Ƶл
-- @author   :  @˫ @׷Ӱ
-- @modifier : <NAME> (<EMAIL>)
-- @copyright: Copyright (c) 2013 EMZ Kingsoft Co., Ltd.
--------------------------------------------------------
local _L = MY.LoadLangPack(MY.GetAddonInfo().szRoot .. 'MY_Chat/lang/')
local INI_PATH = MY.GetAddonInfo().szRoot .. 'MY_Chat/ui/MY_ChatSwitch.ini'
local CD_REFRESH_OFFSET = 7 * 60 * 60 -- 7CD
MY_ChatSwitch = {}
MY_ChatSwitch.aWhisper = {}
MY_ChatSwitch.szAway = nil
MY_ChatSwitch.szBusy = nil
RegisterCustomData('MY_ChatSwitch.szAway')
RegisterCustomData('MY_ChatSwitch.szBusy')

local function UpdateChannelDailyLimit(hRadio, bPlus)
	local me = GetClientPlayer()
	local shaCount = hRadio and hRadio.shaCount
	if not (me and shaCount) then
		return
	end

	local dwPercent = 1
	local info = hRadio.info
	local nChannel = info.channel
	if nChannel then
		local szDate = MY.FormatTime('yyyyMMdd', GetCurrentTime() - CD_REFRESH_OFFSET)
		if MY_ChatSwitch.tChannelCount.szDate ~= szDate then
			MY_ChatSwitch.tChannelCount = {szDate = szDate}
		end
		MY_ChatSwitch.tChannelCount[nChannel] = (MY_ChatSwitch.tChannelCount[nChannel] or 0) + (bPlus and 1 or 0)

		local nDailyCount = MY_ChatSwitch.tChannelCount[nChannel]
		local nDailyLimit = MY.GetChannelDailyLimit(me.nLevel, nChannel)
		if nDailyLimit then
			if nDailyLimit > 0 then
				dwPercent = (nDailyLimit - nDailyCount) / nDailyLimit
				hRadio.szTip = GetFormatText(_L('Today: %d\nDaily limit: %d', nDailyCount, nDailyLimit), nil, 255, 255, 0)
			else
				hRadio.szTip = GetFormatText(_L('Today: %d\nDaily limit: no limitation', nDailyCount), nil, 255, 255, 0)
			end
		end
	end
	XGUI(shaCount):drawCircle(nil, nil, nil, info.color[1], info.color[2], info.color[3], 100, math.pi / 2, math.pi * 2 * dwPercent)
end

local function OnClsCheck()
	local function Cls(bAll)
		for i = 1, 10 do
			local h = Station.Lookup('Lowest2/ChatPanel' .. i .. '/Wnd_Message', 'Handle_Message')
			local hCheck = Station.Lookup('Lowest2/ChatPanel' .. i .. '/CheckBox_Title')
			if h and (bAll or (hCheck and hCheck:IsCheckBoxChecked())) then
				h:Clear()
				h:FormatAllItemPos()
			end
		end
	end
	if IsCtrlKeyDown() then
		Cls()
	elseif IsAltKeyDown() then
		MessageBox({
			szName = 'CLS_CHATPANEL_ALL',
			szMessage = _L['Are you sure you want to clear all message panel?'], {
				szOption = g_tStrings.STR_HOTKEY_SURE, fnAction = function()
					Cls(true)
				end
			}, { szOption = g_tStrings.STR_HOTKEY_CANCEL },
		})
	else
		MessageBox({
			szName = 'CLS_CHATPANEL',
			szMessage = _L['Are you sure you want to clear current message panel?\nPress CTRL when click can clear without alert.\nPress ALT when click can clear all window.'], {
				szOption = g_tStrings.STR_HOTKEY_SURE, fnAction = function()
					Cls()
				end
			}, { szOption = g_tStrings.STR_HOTKEY_CANCEL },
		})
	end
	MY.UI(this):check(false)
end

local function OnAwayCheck()
	MY.SwitchChat('/afk')
	Station.Lookup('Lowest2/EditBox'):Show()
	if Station.Lookup('Lowest2/EditBox/Edit_Input'):GetText() == '' then
		Station.Lookup('Lowest2/EditBox/Edit_Input'):InsertText(MY_ChatSwitch.szAway or g_tStrings.STR_AUTO_REPLAY_LEAVE)
		Station.Lookup('Lowest2/EditBox/Edit_Input'):SelectAll()
	end
	Station.SetFocusWindow('Lowest2/EditBox/Edit_Input')
end

local function OnAwayUncheck()
	MY.SwitchChat('/cafk')
end

local function OnAwayTip() return MY_ChatSwitch.szAway or g_tStrings.STR_AUTO_REPLAY_LEAVE end

local function OnBusyCheck()
	MY.SwitchChat('/atr')
	Station.Lookup('Lowest2/EditBox'):Show()
	if Station.Lookup('Lowest2/EditBox/Edit_Input'):GetText() == '' then
		Station.Lookup('Lowest2/EditBox/Edit_Input'):InsertText(MY_ChatSwitch.szBusy or g_tStrings.STR_AUTO_REPLAY_LEAVE)
		Station.Lookup('Lowest2/EditBox/Edit_Input'):SelectAll()
	end
	Station.SetFocusWindow('Lowest2/EditBox/Edit_Input')
end

local function OnBusyUncheck()
	MY.SwitchChat('/catr')
end

local function OnBusyTip() return MY_ChatSwitch.szBusy end

local function OnMosaicsCheck()
	MY_ChatMosaics.bEnabled = true
	MY_ChatMosaics.ResetMosaics()
end

local function OnMosaicsUncheck()
	MY_ChatMosaics.bEnabled = false
	MY_ChatMosaics.ResetMosaics()
end

local function OnWhisperCheck()
	local t = {}
	for i, whisper in ipairs(MY_ChatSwitch.aWhisper) do
		local info = MY_Farbnamen and MY_Farbnamen.Get(whisper[1])
		table.insert(t, {
			szOption = whisper[1],
			rgb = info and info.rgb or {202, 126, 255},
			fnAction = function()
				MY.SwitchChat(whisper[1])
				MY.DelayCall(MY.FocusChatBox)
			end,
			szIcon = 'ui/Image/UICommon/CommonPanel2.UITex',
			nFrame = 49,
			nMouseOverFrame = 51,
			nIconWidth = 17,
			nIconHeight = 17,
			szLayer = 'ICON_RIGHTMOST',
			fnClickIcon = function()
				for i = #MY_ChatSwitch.aWhisper, 1, -1 do
					if MY_ChatSwitch.aWhisper[i][1] == whisper[1] then
						table.remove(MY_ChatSwitch.aWhisper, i)
						Wnd.CloseWindow('PopupMenuPanel')
					end
				end
			end,
			fnMouseEnter = function()
				local t = {}
				local today = MY.FormatTime('yyyyMMdd')
				local r, g, b = GetMsgFontColor('MSG_WHISPER')
				for _, v in ipairs(whisper[2]) do
					if type(v) == 'string' then
						table.insert(t, v)
					elseif type(v) == 'table' then
						if today == MY.FormatTime('yyyyMMdd', v[2]) then
{'fraction_non_alphanumeric': 0.14190068811604983, 'fraction_numerical': 0.01506416217221499, 'mean_word_length': 3.859918662449164, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '943287', 'n_tokens_mistral': 4391, 'n_tokens_neox': 3902, 'n_words': 853}