PtokaX forum

Stuff => Offtopic => Topic started by: Event_Horizon on 21 June, 2004, 12:07:02

Title: Show TXT files with a CMD
Post by: Event_Horizon on 21 June, 2004, 12:07:02
is it possible to show a txt file in mainchat with a selfcreated CMD like /show try.txt & in mainchat will be show the filecontent.

^^ this is just an example - if there is a way to do this with a regular client (oDC / DC++)tell me how plz

THX ahead
Title:
Post by: Corayzon on 21 June, 2004, 12:57:49
what do u mean exactly?

do you want to files to been shown from the server directory to all users? or just to your user?

or you mean for your own program directory for bcdc?
Title:
Post by: Event_Horizon on 21 June, 2004, 13:08:48
well i'll try to explain it:

I use a MP9 plug-in for showing title & artist on websites - this plug-in creates a TXT called NP_info.txt -> contents looks like this :

The Track  - Cloudskipper - Back To The Drawing Board - CD1

Blows through Event_Horizon's ears

& I wanna get this showed in the mainchat by a command ( in my Hub & in other Hubs if possible) without changing to BCDC or any other kind of client ( using oDC)

hope u get my point
Title:
Post by: NightLitch on 21 June, 2004, 13:33:57
will hopefully works not tested

-- Simple Load-Text Command Bot By: NightLitch 2004/06/21

BotName = "-DEViL-"
command = "+show"

function DataArrival(curUser,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind( data, "%b<>%s+(%S+)" )
if cmd==command then
local _,_,file = strfind(data, "%b<>%s+%S+%s+(%S+)" )
if file==nil then
curUser:SendData(BotName, "Syntax: "..command.." filename.txt")
return 1
end
curUser:SendData(BotName, TextFile(file))
return 1
end
end
end

function TextFile(file)
readfrom(file, "r")
local message = ""
while 1 do
local line = read()
if line == nil then break return "File not found"
else
message = message..line.."\r\n"
end
end
readfrom()
return message
end

/NL
Title:
Post by: Event_Horizon on 21 June, 2004, 16:25:33
NL i think u misunderstood me - I wanna do this with the client & not with a script

& thx for the script - maybe there is another use 4 it ;)
Title:
Post by: NightLitch on 21 June, 2004, 16:45:03
QuoteOriginally posted by Event_Horizon
NL i think u misunderstood me - I wanna do this with the client & not with a script

& thx for the script - maybe there is another use 4 it ;)

Ah you want a BCDC++ script of it ?
Title:
Post by: NightLitch on 21 June, 2004, 16:53:42
Only way is with a script for either PtokaX of BCDC++ or Phantom DC++ or any other Lua Client... Can't be done as far as I now with regular DC++ or oDC....
Title:
Post by: Event_Horizon on 21 June, 2004, 16:58:03
k THX

if u can give me a script 4 BCDC I'll try it
Title:
Post by: NightLitch on 21 June, 2004, 17:26:55
Here you go hope it does what you want...

*** UPDATED ***

fixed a bug in the file opening...

---------------------------------------------------
---------------------------------------------------
-- Text-Bot by: NightLitch 2004/06/21
-- Load Diff. Text Files from a folder
-- BCDC++ Script
-- Command must be sent to Client/Hub
---------------------------------------------------
---------------------------------------------------
-- Command
Command = "+show"

-- Folder where the files being stored
Folder = "TextFiles/"
---------------------------------------------------
---------------------------------------------------
dcpp:setListener( "pm", "GetPM",
function( hub, user, text )
local s,e,cmd,file = string.find(text, "(%S+)%s*(%S*)")
if cmd==Command then
if file==nil or file=="" then
SendPM(hub, user, "Syntax: "..Command.." filename.txt")
return 1
end
SendPM(hub, user, LoadText(Folder..file))
return 1
end
end)
---------------------------------------------------
function SendPM(hub, user, txt)
DC():SendHubMessage( hub:getId(), "$To: "..user:getNick().." From: "..hub:getOwnNick().." $<"..hub:getOwnNick().."> "..txt.."|" )
end
---------------------------------------------------
function LoadText(file)
local msg = ""
str = io.open( file )
if str==nil then
return file.." not found"
else
str:close()
str = io.input ( file )
for line in str:lines() do
msg = msg..line.."\r\n"
end
str:close()
return msg
end
end
---------------------------------------------------

/NL
Title:
Post by: Event_Horizon on 21 June, 2004, 18:04:11
THX alot - will try it intermedialy :D

*edit:

sorry M8 but it shows nothing ( using BCDC 401b ) & no MSGes in the debug window  ?(  ?(  ?(
Title:
Post by: NightLitch on 21 June, 2004, 18:31:08
QuoteOriginally posted by Event_Horizon
THX alot - will try it intermedialy :D

*edit:

sorry M8 but it shows nothing ( using BCDC 401b ) & no MSGes in the debug window  ?(  ?(  ?(

huh that was strange... works really good on my client 0.401a
Title:
Post by: NightLitch on 21 June, 2004, 18:40:29
Update:

---------------------------------------------------
---------------------------------------------------
-- Text-Bot by: NightLitch 2004/06/21
-- Can be used in Main & PM
-- Load Diff. Text Files from a folder
-- BCDC++ Script
---------------------------------------------------
---------------------------------------------------
-- Command
Command = "#show"

-- Folder where the files being stored
Folder = "TextFiles/"
---------------------------------------------------
---------------------------------------------------
dcpp:setListener( "pm", "GetPM",
function( hub, user, text )
if Execute(hub, user, text)==1 then return 1 end
end)
---------------------------------------------------
dcpp:setListener( "chat", "GetCHAT",
function( hub, user, text )
if Execute(hub, user, text)==1 then return 1 end
end)
---------------------------------------------------
function Execute(hub, user, text)
local s,e,cmd,file = string.find(text, "(%S+)%s*(%S*)")
if cmd==Command then
if file==nil or file=="" then
SendPM(hub, user, "Syntax: "..Command.." file   NOTE: without .txt")
return 1
end
SendPM(hub, user, LoadText(Folder..file..".txt"))
return 1
end
end
---------------------------------------------------
function SendPM(hub, user, txt)
DC():SendHubMessage( hub:getId(), "$To: "..user:getNick().." From: "..hub:getOwnNick().." $<"..hub:getOwnNick().."> "..txt.."|" )
end
---------------------------------------------------
function LoadText(file)
local msg = ""
str = io.open( file )
if str==nil then
return file.." not found"
else
str:close()
str = io.input ( file )
for line in str:lines() do
msg = msg..line.."\r\n"
end
str:close()
return msg
end
end
---------------------------------------------------
Title:
Post by: Event_Horizon on 21 June, 2004, 19:35:41
1st on works now

sorry was my mistake - didn't send the command as PM

& how can I get the file shown in mainchat not in PM ?
Title:
Post by: NightLitch on 21 June, 2004, 23:11:59
QuoteOriginally posted by Event_Horizon
1st on works now

sorry was my mistake - didn't send the command as PM

& how can I get the file shown in mainchat not in PM ?

gonna give you that version tomorrow... night night for now... /NL
Title:
Post by: Event_Horizon on 22 June, 2004, 18:13:37
don't forget me NL :D

wanna have some fun with it ;)
Title:
Post by: Event_Horizon on 24 June, 2004, 14:29:03
can someone modifi the first BCDC script to show the responce in mainchat

*** plz move this to BCDC scripting PLZ

THX