PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: jsjen on 16 January, 2004, 22:23:23

Title: show chat history to new user who logs in
Post by: jsjen on 16 January, 2004, 22:23:23
Hi I was looking for a script that shows some of the chat history when a person logs back into the hub, ive been looking through this site and cant seem to find anything . does it exist?
Title:
Post by: Intel on 16 January, 2004, 22:40:32
just enable webserver ..-.....-... inbuildt function
Title:
Post by: jsjen on 16 January, 2004, 22:54:34
will I have to open a port for this???

thanks
Title:
Post by: tezlo on 16 January, 2004, 23:25:11
..
maxhistory = 40

function Main()
chathistory = dofile("chathistory.dat") or {}
end

function NewUserConnected(user)
local n = getn(chathistory)
local str = ">> last "..n.." chat messages.."
for i = 1, n do str = str.."\n"..chathistory[i] end
user:SendData(str)
end

OpConnected = NewUserConnected

function DataArrival(user, data)
if strsub(data, 1, 1) ~= "<" then return end
tinsert(chathistory, date("[%H:%M] ")..strsub(data, 1, -2))
if getn(chathistory) > maxhistory then tremove(chathistory, 1) end
savehistory()
end

function savehistory()
local f = openfile("chathistory.dat", "w+")
assert(f, "chathistory.dat")
write(f, "return {\n")
for i = 1, getn(chathistory) do
write(f, "\t"..format("%q", chathistory[i])..",\n")
end write(f, "}") closefile(f)
end
Title:
Post by: jsjen on 16 January, 2004, 23:49:24
I guess, I want it so when someone logs in they know what has been hapening so i think the last 40 messages would be all they would need.

Im not sure of the script you just put up.

the second post says its already on there but it doesnt seem to work
Title:
Post by: tezlo on 17 January, 2004, 00:08:35
ok now it gets saved.. and loaded whenever you restart scripts
Title:
Post by: tezlo on 16 April, 2004, 22:31:33
yeah commands.. good point :)
but yours will ignore mesages with +!? anywhere in it, you only need to check the first character.. try replace DataArrival() with this one
function DataArrival(user, data)
if strsub(data, 1, 1) ~= "<" then return end
local s, e, pre = strfind(data, "^%b<> (.)")
if pre == "!" or pre == "+" or pre == "?" then return end
tinsert(chathistory, date("[%H:%M] ")..strsub(data, 1, -2))
if getn(chathistory) > maxhistory then tremove(chathistory, 1) end
savehistory()
end

also, if you want the PMs to popup you'll need to frmHub:RegBot(botname) in Main() or use an already registered botname
Title:
Post by: nErBoS on 19 April, 2004, 12:41:58
Hi,

If you want to the private popup come up you have to register the Bot.

Best regards, nErBoS
Title:
Post by: pHaTTy on 19 April, 2004, 13:57:52
standard settings on dc++ wont allow the pm to pop up in pm, because standard dont allow pop up pm's from offline users, if the bot is in the userlist, then it will work fine, it will also work with nmdc, but for dc++ uwill usually need the bot registered.....


function Main()
        chathistory = dofile("chathistory.dat") or {}
        frmHub:RegBot(botname)
end

Title:
Post by: jiten on 20 April, 2004, 09:21:05
i've tried the chat history, but the PM's don't pop up in a new window. they come like this in main:
[09:13] Private message from ?bot?: You have not reached the minimum share ammount of 1 GB.
what do i need to change in this code i got so that they come in pm?:

--code:---------------------------------------------------------------

--Chat History On Entry 1.01
--By Mutor The Ugly 4/14/04
--
--Based entirely on a script by Tezlo 1/17/04

-----------------------------------------------------------
--Changes
--
--Send chat history to PM on entry
--Omits chat with command prefixes.
-----------------------------------------------------------

maxhistory = 20 -- maximum lines of chat to cache
botname = "?bot?"

function Main()
frmHub:RegBot(botname)
chathistory = dofile("chathistory.dat") or {}
end

function NewUserConnected(user)
local n = getn(chathistory)
local str = "<----------------------------------------------------------------------[ Last ( "..n.." ) chat messages ]----------->\r\n"
for i = 1, n do str = str.."\r\n"..chathistory end
user:SendPM(botname,str.."\r\n")
user:SendPM(botname,"<--------------------------------------------------------------------------[ End of chat history ]--------------->")
end

OpConnected = NewUserConnected

function DataArrival(user, data)
   if strsub(data, 1, 1) ~= "<" then return end
   local s, e, pre = strfind(data, "^%b<> (.)")
   if pre == "!" or pre == "+" or pre == "?" then return end
   tinsert(chathistory, date("[%H:%M] ")..strsub(data, 1, -2))
   if getn(chathistory) > maxhistory then tremove(chathistory, 1) end
   savehistory()
end

function savehistory()
local f = openfile("chathistory.dat", "w+")
assert(f, "chathistory.dat")
write(f, "return {\n")
for i = 1, getn(chathistory) do
write(f, "\t"..format("%q", chathistory)..",\n")
end write(f, "}") closefile(f)
end
--end code:---------------------------------------------------------
Title:
Post by: nErBoS on 20 April, 2004, 09:49:04
Hi,

This bot already come up with pm, probably you forgot to restart script, try that.

Best regards, nErBoS
Title:
Post by: jiten on 20 April, 2004, 11:14:37
it doesn't work with me. well, i've updated the script with the one u posted. but, i still get the chat history in main, and not in a new window (PM):

[11:08:29] Private message from ?bot?: <----------------------------------------------------------------------[ Last ( 6 ) chat messages ]----------->

- [21:50] hum...
- [21:50] com o carlos abre
- [21:50] xii
- [21:50] afinal
- [21:50] mng
- [21:51] aki nao

[11:08:29] Private message from ?bot?: <--------------------------------------------------------------------------[ End of chat history ]--------------->
[11:08:29] // Type !help in main for your available commands!
Title:
Post by: pHaTTy on 20 April, 2004, 11:23:48
probby got pop up pms from bots in client disabled
Title:
Post by: jsjen on 20 April, 2004, 11:34:05
just here to say this script works perfectly for me.

Is there a way to add like rules and stuff to the popup?
a txt fil ewould be good so I dont screw another script up

great work guys
Title:
Post by: jiten on 20 April, 2004, 16:32:23
isn't there any other way for the PM to popup in a new window, without enabling the pop up pms from bots in client, just by editing the script?