-----------------------------------------------------------------------------
-- ?2005 Double MM Connection?
-- for ### AMICI ITALIANO ###
----------------------------------------------------------------------------
--rev 2.1 - 06 / 04 / 2005
-- Load & save messages
------------------------------------------------------
--rev 2.0 - 12 / 03 / 2005
-- Changed to Lua 5.0
--Changed top/bottom message
-----------------------------------------------------------------------------
--Bot Name
sBot=frmHub:GetHubBotName()
History="Chat History.dat"
MultiChatName="AMICI ITALIANO"
lMcn=7
MultiChatNickSeparator="?"
sMsg={}
iMin=0
iMax=0
nMsg=10
Top={}
Top[1] ="----------------------------------------------------------------------------------------------------------------"
Top[2] =" --- AMICI ITALIANO --- "
Top[3] =" Libera associazione di Hub Direct Connect"
Top[4] ="----------------------------------------------------------------------------------------------------------------"
Top[5] ="? AMICI ITALIANO (xxxxxxxxxxxxx)"
Top[6] ="? xxxxxxxxxxxx (dchub://xxxxxxxxxxxxxxxxxx )"
Top[7] ="? xxxxxxxxxxxx (dchub://xxxxxxxxxxxxxxxxxx )"
Top[8] =" ULTIMI MESSAGGI DIGITATI IN MAIN CHAT"
Top[9]="----------------------------------------------------------------------------------------------------------------"
nTop=9
Bottom={}
Bottom[1]="----------------------------------------------------------------------------------------------------------------"
nBottom=1
---------------------------------------------------------------
-- Carica in avvio e salva in uscita
---------------------------------------------------------------
function Main()
sMsg={}
loadMessages()
end
function OnExit()
saveMessages()
end
---------------------------------------------------------------
-- Registra Chat
---------------------------------------------------------------
function ChatArrival(User, Data)
Data = string.sub(Data,1,string.len(Data)-1) --toglie l'a-capo finale
local _,_,str = string.find(Data, "%b<>%s+(.+)")
if string.sub(Data,1,1) == "<" then --main message
if string.sub(Data,1,7) == "<"..MultiChatName..">" then -- ripulisce il nick dal tag della multi
local _,_,n = string.find(str, "{.+?<(.+)}.+")
local _,_,s = string.find(str, ".+>}(.+)")
str="<"..n..s
else
local _,_,command = string.find(Data, ".+(> !).+")
if command then
str=nil --do not store any message
else
str=Data
end
end
if str then
sMsg[iMax]="["..os.date("%T").."] "..str
iMax=iMax+1
if iMax-nMsg>iMin then
iMin=iMax-nMsg
end
end
end
end
---------------------------------------------------------------
-- Ultima chat
---------------------------------------------------------------
function NewUserConnected(curUser)
if curUser.sName~=MultiChatName then --curUser.iProfile>=0 and
local i=1
-- Top Header
while i<=nTop-1 do
curUser:SendData(sBot, Top)
i=i+1
end
----
local s=Top[nTop] --- for graphical meanings
--Chat messages
local i=iMin
while i<=iMax do
if sMsg then
s=s.."\n\t"..sMsg
end
i=i+1
end
curUser:SendData(sBot, s)
-- Bottom
i=1
while i<=nBottom do
curUser:SendData(sBot, Bottom)
i=i+1
end
end
end
----------------------------------------------------------
--The same for any user
OpConnected = NewUserConnected
----------------------------------------------------------
-- Load from & Save to file
----------------------------------------------------------
function loadMessages()
iMin=0
iMax=0
local f=io.open(History,"a")
f:close()
for line in
io.lines(History) do
iMax=iMax+1
sMsg[iMax]=line
end
end
function saveMessages()
local f=io.open(History,"w")
local i=iMin
while i<=iMax do
if sMsg then
f:write(sMsg.."\n")
end
i=i+1
end
f:close()
end
please request reset Chat History with zright clicker
thanks bye
Search the forum for "chat history" or give this a try:
--/--------------------------------------------------------
--Optimized and debugged by jiten (5/20/2005)
--/--------------------------------------------------------
--Chat History On Entry 1.02 LUA 5
--By Mutor The Ugly 4/14/04
--Based on a script by Tezlo 1/17/04
--Send chat history to PM on entry
--
-- +Converted to LUA 5 2/22/05
--/--------------------------------------------------------
cFile = "cHistory.dat"
mHistory = 20 -- maximum lines of chat to cache
sBot = "[Historian]"
BadChars = {".","?","!","+","-",} --disallow command prefixes
cHistory = {}
Main = function ()
if loadfile(cFile) then dofile(cFile) end frmHub:RegBot(sBot)
end
OnExit = function()
if next(cHistory) then local hFile = io.open(cFile,"w+") Serialize(cHistory,"cHistory",hFile); hFile:close() end
end
NewUserConnected = function(user)
local str = "\r\n\t<----------------------------------------------------------------------[ Last ( "..table.getn(cHistory).." ) chat messages ]----------->"
for i = 1, table.getn(cHistory) do str = str.."\r\n\t"..cHistory[i] end
str = str.."\r\n\t<--------------------------------------------------------------------------[ End of chat history ]--------------->"
user:SendPM(sBot,str)
end
OpConnected = NewUserConnected
ChatArrival = function(user, data)
local s,e,pre = string.find(data, "^%b<> (.)") local when = os.date("[%H:%M] ") local chat = string.sub(data, 1, -2)
for k,v in BadChars do if pre == v then return end end -- disallow command input to cached chat
table.insert(cHistory,when..chat) if table.getn(cHistory) > mHistory then table.remove(cHistory, 1) end OnExit()
end
Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in tTable do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
end
hFile:write(sTab.."}");
end
Best regards,
jiten