PtokaX forum

Development Section => HOW-TO's => Topic started by: Stravides on 16 January, 2004, 02:59:24

Title: Letting ops ammend their own welcomes
Post by: Stravides on 16 January, 2004, 02:59:24
Ok I have as the majority of site a welcome and exit message for my ops n vips.

what I want is a facility to say !changelogin and it will read from the messages file and update that users message
the current message file is in the format

stravides1       = "The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides"
stravides2      = "And thus it had to come to an end, dont cry, for Stravides will return"
malevolence1       = "Bow down and Cower for Malevolence has arrived.."
malevolence2      = "Where's that mangy chufter Malevolence off to, no doubt he will return soon"

where username1 is a login username2 is a logout

I have also toyed with the idea of tables ie

-- OPLIST Variables
op1="Stravides"
op2="Malevolence"
op3="Reload3d"

LogoutTable = {
[1] = " logging Out",
[2] = " logging Out",
[3] = " logging Out"
};

LoginTable = {
[1] = " logging In",
[2] = " logging In",
[3] = " logging In"
};

any help would be appreciated as I keep on going in cirles here... code pointers full blown commented code would be ok too I suppose....  seriously Many thanks for your ideas in advance

Stravides
RPGBooks-Cymru.no-ip.org:411

Title:
Post by: plop on 16 January, 2004, 03:23:54
do i get it right that you know some or wanne learn lua???
if so i got that function in a.i., if you want i can give you the functions so you can put it 2gether yourself.
or grab tezlo's welcome bot and i'll help you add a cmd 2 that 2 let the op's change there welcome.

plop
Title:
Post by: pHaTTy on 16 January, 2004, 03:27:54
QuoteOriginally posted by plop
do i get it right that you know some or wanne learn lua???
if so i got that function in a.i., if you want i can give you the functions so you can put it 2gether yourself.
or grab tezlo's welcome bot and i'll help you add a cmd 2 that 2 let the op's change there welcome.

plop

GRRRR, has my new G6 got anything your's hasnt hmmm, grr damn i thought it was an original idea lol, well like they say, great minds think alike LOL he he he
Title:
Post by: Stravides on 16 January, 2004, 03:32:41
QuoteOriginally posted by plop
do i get it right that you know some or wanne learn lua???
if so i got that function in a.i., if you want i can give you the functions so you can put it 2gether yourself.
or grab tezlo's welcome bot and i'll help you add a cmd 2 that 2 let the op's change there welcome.

plop

Cheers for speedy reply, i can bodge not too badly, ie i can understand the majority of what you chaps write, i just cant do it myself yet..

I do not understand the
if strsub(data, 1, 1) == "<" then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")  bits

I have my bot taking the welcomes from a file and really would prefer that to be separate from the bot as I dont want users tinkerin with the bot :)

any help greatly appreciated

I have included smeagol here

-- Many thanks to Troubadour & [NL]-=DJ_Bert=- for the majoity of the code in here from
-- Guardian..  Just didnt do what I needed really...  So hence the mods


BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Stripped Version V6.99"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.3 Stravides $ $Black Light"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"


rules = "\r\n"..
"                                   Rules \r\n"..
"\r\n"..
"Failure to comply with these rules will mean perm bans from this hub.\r\n"..
"\r\n"..
"01. You must share at least 50MB of Applicable Files. (RPG, Video, MP3)\r\n"..
"02. Please speak English *only* in the main chat. We realize that not everyone is fluent in it, be hey, look at it as a learning experience !\r\n"..
"03. Zero Porn Toleration. This means your run-of-the-mill stuff Hentai, Disney toons, or anything similar. You will receive one warning. Then you will be banned. Sick porn, teen porn, and/or kiddie porn will all be banned without warning or absolution. \r\n"..
"04. Don't use excessive Caps in main chat, don't change your nick, do not flood or spam, and do not post ads for other hubs.\r\n"..
"05. Slotlocking or faksesharing will result in an immediate and permanent ban. No questions asked.\r\n"..
"06. Download speed limiters (shown as B: or L: in desc tags) are not allowed in this hub it will lead to a ban. \r\n"..
"07. 3 kicks will lead to automatic ban!\r\n"..
"08. No racist propaganda or music.\r\n"..
"09. Don't share installed Games/Programs files or incomplete files \r\n"..
"10. Don't share .VOB-files \r\n"..
"11. Don't share *.eml or *.pst-files (your e-mail files). Besides being stupid to share your private e-mail, they may contain viruses.\r\n"..
"12. Don't close other users from downloading. (If you must do it, then give them a good reason!)\r\n"..
"13. Don't flood or spam the chat.\r\n"..
"14. Don't attack other hub users in the main chat. Chat nice or don't chat at all!\r\n"..
"15. Don't ask for OP. we'll ask you :)\r\n"


ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

dofile("messages.cfg");  -- used for in n out strings

version = BOTName.." "..ScriptVersion
prefix = "?"

function Main()
frmHub:UnregBot(BOTName)
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
AddProfile("Moderator", 4269273088)
AddProfile("Guest", 2148028000)
end

function DoRead(user)
while 1 do
pline = read()
if pline == nil then break end
user:SendPM(BOTName, pline)
end
readfrom()
end

function MyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

--------- Op Connected ---------
function OpConnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
if (user.sName == "Stravides") then SendToAll(BOTName,""..stravides1.."")
elseif (user.sName == "Malevolence") then SendToAll(BOTName, ""..malevolence1.."")
elseif (user.sName == "Blumpy") then SendToAll(BOTName, ""..blumpy1.."")
elseif (user.sName == "Feuer_Frei") then SendToAll(BOTName, ""..feuer_frei1.."")
elseif (user.sName == "Tumnakitty") then SendToAll("Bast", ""..tumnakitty1.."")
elseif (user.sName == "Findor_Tallwillow") then SendToAll(BOTName, ""..findor_tallwillow1.."")
elseif (user.sName == "Sniffy") then SendToAll(BOTName, ""..sniffy1.."")
elseif (user.sName == "Reload3d") then SendToAll(BOTName, ""..reload3d1.."")
else    SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
end


-- Op Disconnected
function OpDisconnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)

if (user.sName == "Stravides") then SendToAll(BOTName,""..stravides2.."")
elseif (user.sName == "Malevolence") then SendToAll(BOTName, ""..malevolence2.."")
elseif (user.sName == "Blumpy") then SendToAll(BOTName, ""..blumpy2.."")
elseif (user.sName == "Feuer_Frei") then SendToAll(BOTName, ""..feuer_frei2.."")
elseif (user.sName == "Tumnakitty") then SendToAll("Bast", ""..tumnakitty2.."")
elseif (user.sName == "Findor_Tallwillow") then SendToAll(BOTName, ""..findor_tallwillow2.."")
elseif (user.sName == "Sniffy") then SendToAll(BOTName, ""..sniffy2.."")
elseif (user.sName == "Reload3d") then SendToAll(BOTName, ""..reload3d2.."")
elseif user.iProfile == 1 then SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

-- Vip Connected
function NewUserConnected(user)
if (user.sName == "Morgyn") then SendToAll(BOTName,""..morgyn1.."")
elseif (user.sName == "Kyoya") then SendToAll(BOTName, ""..kyoya1.."")
elseif (user.sName == "Warian") then SendToAll(BOTName, ""..warian1.."")
elseif (user.sName == "Spider") then SendToAll(BOTName, ""..spider1.."")
elseif (user.sName == "fortywinks") then SendToAll(BOTName, ""..fortywinks1.."")
elseif user.iProfile == 2 then SendToAll(BOTName, "[VIP] "..user.sName..", "..line.." ")  
elseif user.iProfile == nil then SendToNick(BOTName, ""..user.sName.." has Connected" )
end
end

-- Vip Disconnected
function UserDisconnected(user)

if (user.sName == "Morgyn") then SendToAll(BOTName,""..morgyn2.."")
elseif (user.sName == "Kyoya") then SendToAll(BOTName, ""..kyoya2.."")
elseif (user.sName == "Warian") then SendToAll(BOTName, ""..warian2.."")
elseif (user.sName == "Spider") then SendToAll(BOTName, ""..spider2.."")
elseif (user.sName == "fortywinks") then SendToAll(BOTName, ""..fortywinks2.."")
elseif user.iProfile == 2 then SendToAll(BOTName, "[VIP] "..user.sName..", "..line2.." ")  
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
user:SendPM(BOTName,"Your Login Message has been changed")
return 1

elseif cmd == prefix.."changelogout" then
user:SendPM(BOTName,"Your Logout Message has been changed")
return 1
elseif cmd == "!rules" then
user:SendPM(BOTName,rules)
return 1

elseif (cmd == "!myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == "!mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end end
end
end

Title:
Post by: plop on 16 January, 2004, 03:39:46
QuoteOriginally posted by (uk-kingdom)pH?tt?
QuoteOriginally posted by plop
do i get it right that you know some or wanne learn lua???
if so i got that function in a.i., if you want i can give you the functions so you can put it 2gether yourself.
or grab tezlo's welcome bot and i'll help you add a cmd 2 that 2 let the op's change there welcome.

plop

GRRRR, has my new G6 got anything your's hasnt hmmm, grr damn i thought it was an original idea lol, well like they say, great minds think alike LOL he he he
-- v0.9fP.a editkick/editleave/editwelcome - every op can edit his own kick/welcome/leave text if special anounce/kick is enabled
lol you could have known. lol
you have a.i. it's in the changelog, added it a long time back.
gues were both pretty crazy. lol

plop
Title:
Post by: pHaTTy on 16 January, 2004, 03:42:13
ye lol u guess, oh well might as well let u know that G6 has a user account for each op, they have all their own setup's so they can setup how they kick, setup there own commands etc ;)
Title:
Post by: plop on 16 January, 2004, 04:11:38
QuoteOriginally posted by Stravides
QuoteOriginally posted by plop
do i get it right that you know some or wanne learn lua???
if so i got that function in a.i., if you want i can give you the functions so you can put it 2gether yourself.
or grab tezlo's welcome bot and i'll help you add a cmd 2 that 2 let the op's change there welcome.

plop

Cheers for speedy reply, i can bodge not too badly, ie i can understand the majority of what you chaps write, i just cant do it myself yet..

I do not understand the
if strsub(data, 1, 1) == "<" then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")  bits

I have my bot taking the welcomes from a file and really would prefer that to be separate from the bot as I dont want users tinkerin with the bot :)

any help greatly appreciated

I have included smeagol here
well you have a nice start and as you wanne learn, lets take it step by step.
so in the end you whill have made it yourself.

1st some stuff about what you didn't understand as your gone need it.

if strsub(data, 1, 1) == "<" then    <--- this line checks if data is send in mainchat, this always starts with a <

data=strsub(data,1,strlen(data)-1)    <---- this line strips the last character from the send line of data, this is always a |

for more info about this i suggest you read this (http://board.univ-angers.fr/thread.php?threadid=764&boardid=4&styleid=1)


s,e,cmd = strfind(data,"%b<>%s+(%S+)")
this 1 is a bit more diffecult, looks like some funny stuff but it's the most used thing.
the s and e are mostly just dummy's, forget about them for now.
strfind is in full string find (yes i'm skipping something).
cmd is what we wanne find.
data is where we wanne search for it.
and finaly the "%b<>%s+(%S+)" is the pattern were searching for and between the ( ) marks is what we wanne find and hook 2 cmd.
more about these patterns can be found here (http://board.univ-angers.fr/thread.php?threadid=763&boardid=4&styleid=1)


now your 1st task after reading that tiny bit.
add the command !changelogin 2 dataarrival and if a user triggers that you need 2 do a little extended search for what he typed behind the command.
all were gone do with that is have the bot say that in mainchat.

thats all for now, good luck.

plop
Title:
Post by: plop on 16 January, 2004, 04:13:37
QuoteOriginally posted by (uk-kingdom)pH?tt?
ye lol u guess, oh well might as well let u know that G6 has a user account for each op, they have all their own setup's so they can setup how they kick, setup there own commands etc ;)
cool, but i rather not add those things, it can easely make it 2 heavy.
just as i never whill add language files.
but who knows, never say never. lol

plop
Title:
Post by: pHaTTy on 16 January, 2004, 04:15:45
QuoteOriginally posted by plop
QuoteOriginally posted by (uk-kingdom)pH?tt?
ye lol u guess, oh well might as well let u know that G6 has a user account for each op, they have all their own setup's so they can setup how they kick, setup there own commands etc ;)
cool, but i rather not add those things, it can easely make it 2 heavy.
just as i never whill add language files.
but who knows, never say never. lol

plop

as long as everything is based in memory who cars, 5k memory not a killer lol ;), a little extra bandwidth, but, its actually oretty lite and smooth, but it wont be released until i return ;)
Title:
Post by: plop on 16 January, 2004, 04:34:00
QuoteOriginally posted by (uk-kingdom)pH?tt?
QuoteOriginally posted by plop
QuoteOriginally posted by (uk-kingdom)pH?tt?
ye lol u guess, oh well might as well let u know that G6 has a user account for each op, they have all their own setup's so they can setup how they kick, setup there own commands etc ;)
cool, but i rather not add those things, it can easely make it 2 heavy.
just as i never whill add language files.
but who knows, never say never. lol

plop

as long as everything is based in memory who cars, 5k memory not a killer lol ;), a little extra bandwidth, but, its actually oretty lite and smooth, but it wont be released until i return ;)
memory isn't the problem indeed, bandwidth is more.
1 of our hub's is always on the limits of it's bandwidth.
we need 1 extra hub 2 take over some of it's users (any1 feeling interested feel free 2 contact me, but we rather not have any1 just starting, this as we have had several newbie's stopping after a couple weeks, we have a high standard for joining the network).
but hey hurry back you made me curious. lol

btw it's a real O.T. day for us 2 i believe.
but for me it's a bit over, need 2 dive in bed.
cya hopefully soon, otherwise later.

plop
Title:
Post by: Stravides on 16 January, 2004, 04:39:49
Quotenow your 1st task after reading that tiny bit.
add the command !changelogin 2 dataarrival and if a user triggers that you need 2 do a little extended search for what he typed behind the command.
all were gone do with that is have the bot say that in mainchat.

thats all for now, good luck.

plop

Ok the links didnt work for me, but i dug about in some of the code that I already have for other bits n bobs and came up with

function DataArrival(user,data)
   if strsub(data, 1, 1) == "<" then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")

      if cmd == prefix.."changelogin" then
         _,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
         SendToAll(BOTName, "New Login :> "..message)   

this gives output of

!changelogin Welcomes Stravides to the world of Hades
New Login :> Welcomes Stravides to the world of Hades

please continue ...  :)

regards
Title:
Post by: plop on 16 January, 2004, 04:52:32
oke Stravides, good job.
but gone write the next lesson 2morrow as i'm now really falling asleep here.
those links were pointing 2 the howto section of this board.
look for pattern matching and strsub there.

plop
Title:
Post by: Stravides on 16 January, 2004, 04:57:27
QuoteOriginally posted by plop
oke Stravides, good job.
but gone write the next lesson 2morrow as i'm now really falling asleep here.
those links were pointing 2 the howto section of this board.
look for pattern matching and strsub there.

plop

I await with glee :)
gnight
Title:
Post by: plop on 16 January, 2004, 12:45:05
ok next lesson. lol
on the site where you can download ptokax you can also find lua command line.
grab that and excute the next scipt with that.
table= {[1]=1, [5]=1, [2]=1, [9]=1, [4]=1, }

for i=1, 10 do
   if table[i] then
      print(i.." is in the table")
   else
      print(i.." isn't in the table")
   end
end
were gone use a table like that 2 store all the welcome msg's.
for now were not yet gone save it, just use memory 2 store them temperarly.

the table whill look like this.
Table = { ["username"]="welcome text here", ["username2"]="welcome text here from user 2"}

so we can grab the welcome text for the matching user by giving the name of the user as key 2 search with.
the "for i-1, 10 do isn't what we are gone need but the rest we are gone need.
Table[user.sName] is how we grab the welcome text.

i hope this is all your gone need so far, if not just ask.
next lesson were gone put this and the previous 2gether 2 change the text.

plop
Title:
Post by: Stravides on 16 January, 2004, 17:56:18
Sorry NEVER used lua command line, i type the script into the window and i get errors

for i=1, 10 do
error: 'end' expected;
  last token read: '' at line 1 in string "for i=1, 10 do "

I have no idea how to use command line where to put it or whether I should link it up or what

it lets the 1st line be typed in, but not the second

soryy for being so dim

awaiting tutorial for the lua command line muppet that I am

regards Strav
Title:
Post by: SaintSinner on 16 January, 2004, 18:25:20
QuoteOriginally posted by Stravides
Sorry NEVER used lua command line, i type the script into the window and i get errors



mind if i join in on this, im learning too,
but go to ptacez site here (http://develop.svamberk.net/ptokax/site/index.php)

there you can get the lua commandline and run that
code he gave you but dont copy and paste, it will
give you errors, you need to type it in from scratch.
and then hit enter when done, and the links do work,
you just need to remove the first part of the url, like this
it will come up as
http://board.univ-angers.fr/"http://board.univ-angers.fr/thread.php?threadid=764&boardid=4&styleid=1

remove the first http://board.univ-angers.fr/"
and you will have the actual link for the lessons.
Title:
Post by: Stravides on 16 January, 2004, 19:12:55
Thats the lua command line edit or I got,
i typed it in, not copied, an still get the same error..

I'm a muppet...  :rolleyes:  i see, all on one line, no returns :S

thats ok, I now have the output

Lua 4.0  Copyright (C) 1994-2000 TeCGraf, PUC-Rio
>
> table= {[1]=1, [5]=1, [2]=1, [9]=1, [4]=1, }
>
> for i=1, 10 do  if table[i] then print(i.."  is in the table") else print(i.."
 is not in the table") end end
1  is in the table
2  is in the table
3 is not in the table
4  is in the table
5  is in the table
6 is not in the table
7 is not in the table
8 is not in the table
9  is in the table
10 is not in the table
>

so would i then create a table in my external file or would it be in the actual lua ?  or am i leaping ahead of myself ?

:)

regards
Stravides
Title:
Post by: plop on 16 January, 2004, 19:30:06
hi hi saint, your very welcome 2 join.

the links are fixed, used some html things by accident.

you can copy/paste the example script in2 notepad and save it as .lua
then you can launch it with the lua command line.
lua

if you start the lua command line without arguments you enter a so called realtime scripting eviroment.
you can type pieces of code there and everytime you press the enter button it execute's the code.

i reguarly use the lua command line for giving examples, as it's very handy 2 test if things actualy work and how they work.
you can emulate everything which can happen in the hub's.

ok go and study you 2 (and everybody not posting but also trying). lol
when i see some scripts here with the table in it i'll continue.

plop
Title:
Post by: Stravides on 17 January, 2004, 19:01:38
Ok so the table is the entrances at the moment, the exits will be same procedure exept diff table passed to function I take it

anyway the table is set up, and there is a func to display the table !displaytable which when runs dispays the entrance message :)  getting this so far I think hehe



-- Many thanks to Troubadour & [NL]-=DJ_Bert=- for the majoity of the code in here from
-- Guardian..  Just didnt do what I needed really...  So hence the mods

--    Variables  
BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Stripped Version V6.99"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.3 Stravides $ $Black Light"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"
version = BOTName.." "..ScriptVersion
prefix = "!"

ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

dofile("messages.cfg");  -- used for in n out strings

UserTable = { ["Stravides"]="The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Malevolence"]="Bow down and Cower for Malevolence has arrived..",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Findor_Tallwillow"]="Beware, fakers, slot-lockers and other lamers... Findor_Tallwillow is here to give you a quick trip to the Abyss... If you aren't one of the above, then smile, and have a good day! :)",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived..",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Warian"]="Warian - The one who is all that which stands for that which is the epitome` of that which is The World of [Darkness enters!",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Kyoya"]="RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org",
["Spider"]="Spider has entered the Hub, put all small mammals away!!!",
["fortywinks"]="The slumbering tones of Fortywinks graces the hub",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty"
};


rules = "\r\n"..
"                                   Rules \r\n"..
"\r\n"..
"Failure to comply with these rules will mean perm bans from this hub.\r\n"..
"\r\n"..
"01. You must share at least 50MB of Applicable Files. (RPG, Video, MP3)\r\n"..
"02. Please speak English *only* in the main chat. We realize that not everyone is fluent in it, be hey, look at it as a learning experience !\r\n"..
"03. Zero Porn Toleration. This means your run-of-the-mill stuff Hentai, Disney toons, or anything similar. You will receive one warning. Then you will be banned. Sick porn, teen porn, and/or kiddie porn will all be banned without warning or absolution. \r\n"..
"04. Don't use excessive Caps in main chat, don't change your nick, do not flood or spam, and do not post ads for other hubs.\r\n"..
"05. Slotlocking or faksesharing will result in an immediate and permanent ban. No questions asked.\r\n"..
"06. Download speed limiters (shown as B: or L: in desc tags) are not allowed in this hub it will lead to a ban. \r\n"..
"07. 3 kicks will lead to automatic ban!\r\n"..
"08. No racist propaganda or music.\r\n"..
"09. Don't share installed Games/Programs files or incomplete files \r\n"..
"10. Don't share .VOB-files \r\n"..
"11. Don't share *.eml or *.pst-files (your e-mail files). Besides being stupid to share your private e-mail, they may contain viruses.\r\n"..
"12. Don't close other users from downloading. (If you must do it, then give them a good reason!)\r\n"..
"13. Don't flood or spam the chat.\r\n"..
"14. Don't attack other hub users in the main chat. Chat nice or don't chat at all!\r\n"..
"15. Don't ask for OP. we'll ask you :)\r\n"

function Main()
frmHub:UnregBot(BOTName)
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
AddProfile("Moderator", 4269273088)
AddProfile("Guest", 2148028000)
end

function DoRead(user)
while 1 do
pline = read()
if pline == nil then break end
user:SendPM(BOTName, pline)
end
readfrom()
end

function MyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

--------- Op Connected ---------
function OpConnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
if (user.sName == "Stravides") then SendToAll(BOTName,""..stravides1.."")
elseif (user.sName == "Malevolence") then SendToAll(BOTName, ""..malevolence1.."")
elseif (user.sName == "Blumpy") then SendToAll(BOTName, ""..blumpy1.."")
elseif (user.sName == "Feuer_Frei") then SendToAll(BOTName, ""..feuer_frei1.."")
elseif (user.sName == "Tumnakitty") then SendToAll("Bast", ""..tumnakitty1.."")
elseif (user.sName == "Findor_Tallwillow") then SendToAll(BOTName, ""..findor_tallwillow1.."")
elseif (user.sName == "Sniffy") then SendToAll(BOTName, ""..sniffy1.."")
elseif (user.sName == "Reload3d") then SendToAll(BOTName, ""..reload3d1.."")
else    SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
end


-- Op Disconnected
function OpDisconnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)

if (user.sName == "Stravides") then SendToAll(BOTName,""..stravides2.."")
elseif (user.sName == "Malevolence") then SendToAll(BOTName, ""..malevolence2.."")
elseif (user.sName == "Blumpy") then SendToAll(BOTName, ""..blumpy2.."")
elseif (user.sName == "Feuer_Frei") then SendToAll(BOTName, ""..feuer_frei2.."")
elseif (user.sName == "Tumnakitty") then SendToAll("Bast", ""..tumnakitty2.."")
elseif (user.sName == "Findor_Tallwillow") then SendToAll(BOTName, ""..findor_tallwillow2.."")
elseif (user.sName == "Sniffy") then SendToAll(BOTName, ""..sniffy2.."")
elseif (user.sName == "Reload3d") then SendToAll(BOTName, ""..reload3d2.."")
elseif user.iProfile == 1 then SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

-- Vip Connected
function NewUserConnected(user)
if (user.sName == "Morgyn") then SendToAll(BOTName,""..morgyn1.."")
elseif (user.sName == "Kyoya") then SendToAll(BOTName, ""..kyoya1.."")
elseif (user.sName == "Warian") then SendToAll(BOTName, ""..warian1.."")
elseif (user.sName == "Spider") then SendToAll(BOTName, ""..spider1.."")
elseif (user.sName == "fortywinks") then SendToAll(BOTName, ""..fortywinks1.."")
elseif user.iProfile == 2 then SendToAll(BOTName, "[VIP] "..user.sName..", "..line.." ")  
elseif user.iProfile == nil then SendToNick(BOTName, ""..user.sName.." has Connected" )
end
end

-- Vip Disconnected
function UserDisconnected(user)

if (user.sName == "Morgyn") then SendToAll(BOTName,""..morgyn2.."")
elseif (user.sName == "Kyoya") then SendToAll(BOTName, ""..kyoya2.."")
elseif (user.sName == "Warian") then SendToAll(BOTName, ""..warian2.."")
elseif (user.sName == "Spider") then SendToAll(BOTName, ""..spider2.."")
elseif (user.sName == "fortywinks") then SendToAll(BOTName, ""..fortywinks2.."")
elseif user.iProfile == 2 then SendToAll(BOTName, "[VIP] "..user.sName..", "..line2.." ")  
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
SendToAll(BOTName, "New Login :> "..message)

elseif cmd == prefix.."changelogout" then
user:SendPM(BOTName,"Your Logout Message has been changed")
return 1
elseif cmd == "!rules" then
user:SendPM(BOTName,rules)
return 1
elseif (cmd == prefix.."displaytable" ) then
SendToAll(BOTName,UserTable[user.sName])
return 1

elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end end
end
end

Getting there slowly
Title:
Post by: Stravides on 19 January, 2004, 09:44:49
Just looking for the next installment of this tutorial :)

many thanks

Stravides
Title:
Post by: plop on 19 January, 2004, 15:32:47
ok next 1.
what you now have is an asosiative table, complex word for something simple.
in that example script the letter i was a counter, used 2 check if a number was in the table.
the numbers in the table were the so called key's, the 1 was there vallue.
there is was just a dummy vallue, but in your script were gone use real vallue's, the welcome text.
like you allready made.
what were gone do is place a check if the username is in the table and if yes were gone extract and use the vallue.
the way 2 check if something is in the table you allready know and using it goes the same way.
SendToAll(Bot, table)
if the user isn't in the table were gone need the standard welcome text.
good luck

plop
Title:
Post by: Stravides on 19 January, 2004, 21:26:55
Ok heres the file that does that, spose we could put that into the messages.cfg file now, but i've left it in main code for you to see...

but we can look at that once we look at the users modifyin their own scripts I suppose..  keep it in the one script for now :)



--    Variables  
BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Stripped Version V6.99"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.3 Stravides $ $Black Light"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"
version = BOTName.." "..ScriptVersion
prefix = "!"

ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

-- dofile("messages.cfg");  -- this will hold the tables below

OPLoginTable = {
["Stravides"]="TBL - The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Malevolence"]="Bow down and Cower for Malevolence has arrived..",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Findor_Tallwillow"]="Beware, fakers, slot-lockers and other lamers... Findor_Tallwillow is here to give you a quick trip to the Abyss... If you aren't one of the above, then smile, and have a good day! :)",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived..",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty",
};

OPLogoutTable = {
["Stravides"]="And thus it had to come to an end, dont cry, for Stravides will return",
["Malevolence"]="Where's that mangy chufter Malevolence off to, no doubt he will return soon",
["Blumpy"]="Blumpy flushes himself back to the kingdom of the Brown River",
["Findor_Tallwillow"]="Necromancer heaves a sigh of relief as Findor leaves and invites the rule-breakers back into the hub. If they Dare...",
["Sniffy"]="Phew now that the wife, Sniffy has left I can relax in my slippers",
["Reload3d"]="The taint of Reload3d is no more...",
["Feuer_Frei"]="Feuer_Frei hath departed!!",
["Tumnakitty"]="Alas, I call to me Tumnakitty,the firecat that follows my lead...",
};

VIPLogInTable = {
["Warian"]="Warian - The one who is all that which stands for that which is the epitome` of that which is The World of [Darkness enters!",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Kyoya"]="RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org",
["Spider"]="Spider has entered the Hub, put all small mammals away!!!",
["fortywinks"]="The slumbering tones of Fortywinks graces the hub",
};

VIPLogOutTable = {
["Warian"]="Warian - The World of Darkness Guru has left, and taken his Weremidgets with him!",
["Morgyn"]="Bid Farewell to the VIP Morgyn from RPGmadhouse.no-ip.org",
["Kyoya"]="Bid Farewell to the VIP Kyoya from RPGmadhouse.no-ip.org",
["Spider"]="As the Sun goes down, the reflections cease from Spider as he logs off..",
["fortywinks"]="As Fortywinks leaves, he casts a farewell wave..",
};

rules = "\r\n"..
"                                   Rules \r\n"..
"\r\n"..
"Failure to comply with these rules will mean perm bans from this hub.\r\n"..
"\r\n"..
"01. You must share at least 50MB of Applicable Files. (RPG, Video, MP3)\r\n"..
"02. Please speak English *only* in the main chat. We realize that not everyone is fluent in it, be hey, look at it as a learning experience !\r\n"..
"03. Zero Porn Toleration. This means your run-of-the-mill stuff Hentai, Disney toons, or anything similar. You will receive one warning. Then you will be banned. Sick porn, teen porn, and/or kiddie porn will all be banned without warning or absolution. \r\n"..
"04. Don't use excessive Caps in main chat, don't change your nick, do not flood or spam, and do not post ads for other hubs.\r\n"..
"05. Slotlocking or faksesharing will result in an immediate and permanent ban. No questions asked.\r\n"..
"06. Download speed limiters (shown as B: or L: in desc tags) are not allowed in this hub it will lead to a ban. \r\n"..
"07. 3 kicks will lead to automatic ban!\r\n"..
"08. No racist propaganda or music.\r\n"..
"09. Don't share installed Games/Programs files or incomplete files \r\n"..
"10. Don't share .VOB-files \r\n"..
"11. Don't share *.eml or *.pst-files (your e-mail files). Besides being stupid to share your private e-mail, they may contain viruses.\r\n"..
"12. Don't close other users from downloading. (If you must do it, then give them a good reason!)\r\n"..
"13. Don't flood or spam the chat.\r\n"..
"14. Don't attack other hub users in the main chat. Chat nice or don't chat at all!\r\n"..
"15. Don't ask for OP. we'll ask you :)\r\n"

function Main()
frmHub:UnregBot(BOTName)
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
AddProfile("Moderator", 4269273088)
AddProfile("Guest", 2148028000)
end

function DoRead(user)
while 1 do
pline = read()
if pline == nil then break end
user:SendPM(BOTName, pline)
end
readfrom()
end

function MyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

--------- Begin Connection Functions ---------

function OpConnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
if OPLoginTable[user.sName] then SendToAll(BOTName,OPLoginTable[user.sName])
else    SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
end

function OpDisconnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
if OPLogoutTable[user.sName] then SendToAll(BOTName,OPLogoutTable[user.sName])
elseif user.iProfile == 1 then SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

function NewUserConnected(user)
if VIPLogInTable[user.sName] then SendToAll(BOTName,VIPLogInTable[user.sName])
elseif user.iProfile == 2 then SendToAll(BOTName, "[VIP] "..user.sName..", has Connected")  
elseif user.iProfile == nil then SendToNick(BOTName, ""..user.sName..", has Connected" )
end
end

function UserDisconnected(user)
if VIPLogOutTable[user.sName] then SendToAll(BOTName,VIPLogOutTable[user.sName])
elseif (user.sName == "fortywinks") then SendToAll(BOTName, ""..fortywinks2.."")
elseif user.iProfile == 2 then SendToAll(BOTName, "[VIP] "..user.sName..", has Disconnected")  
end
end

--------- End Connection Functions ---------

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
SendToAll(BOTName, "New Login :> "..message)

elseif cmd == prefix.."changelogout" then
user:SendPM(BOTName,"Your Logout Message has been changed")
return 1
elseif cmd == "!rules" then
user:SendPM(BOTName,rules)
return 1
elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end end
end
end


many thanks - eagerly awaiting next chapter :)
Title:
Post by: plop on 19 January, 2004, 22:55:37
oki your doing great, got just 1 small hint.
try tabbing a bit better.
function OpConnected(user)
   description,speed,email,share=MyInfoString(user.sMyInfoString)
   local share2 = share / (1024*1024*1024)
   if OPLoginTable[user.sName] then
      SendToAll(BOTName,OPLoginTable[user.sName])
   else
      SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
   end
end
this is much easyer 2 read.

now were gone make it posible for the op's 2 change there welcome.
this is again really simple.
OPLoginTable[user.sName]="New welcome text"
can't make it more complex then this. lol
after that were gone save it 2 a file (in the most simple way so you also learn some more pattern matching on loading it again).

plop
Title:
Post by: Stravides on 19 January, 2004, 23:10:18
Sorry I dont understand what you mean,

please can you explain as I'm not sure what you require me to do next..  the rest was fairly easy, but I'm not too clear on the next steps.

i assume that the user will type something like !changelogin this is my new text

and the DataArrival needs to check for the string after that somehow

that I think I can do, but the file manipulation I'm not sure about at all.  Might help if you can gimme a quick write and read help, after all I only wanna ammend the line that is equal to the current user dont i ?

regards in stupidity :)

Stravides
Title:
Post by: Stravides on 19 January, 2004, 23:24:32
General gist of the code will be in dataarrival


function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if OPLoginTable[user.sName] then  
OPLogoutTable[user.sName] = message
  SendToAll(BOTName,"Login changed to: "..OPLogoutTable[user.sName])
end
elseif cmd == prefix.."changelogout" then


I know the    OPLogoutTable[user.sName] = message will only change it for there and then, but I do not know how to change the table perm. can you assist in this but ;)

regards
Stravides
Title:
Post by: plop on 20 January, 2004, 02:05:05
QuoteOriginally posted by Stravides
General gist of the code will be in dataarrival


function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if OPLoginTable[user.sName] then  
OPLogoutTable[user.sName] = message
  SendToAll(BOTName,"Login changed to: "..OPLogoutTable[user.sName])
end
elseif cmd == prefix.."changelogout" then


I know the    OPLogoutTable[user.sName] = message will only change it for there and then, but I do not know how to change the table perm. can you assist in this but ;)

regards
Stravides
you got it, just a tiny mix up.
your changing the logout on the login command.
and yes this only works aslong as the bot isn't restarted, for this 2 be a permanent change we need 2 save it.
now we could save it as table so on loading we only need 2 do a dofile(filename) but were gone save it as plain txt file.
this so you learn some more pattern matching on loading the file again.
2 save this were gone need a loop 2 proces all the entry's in the table and think of a handy way 2 store the things in the file.
if you look @ the dat files from ptokax you can see that they use the | between things, so were gone do the same.
so our file is gone look like this.
name1|text1
name2|text2
name3|text3
2 save we 1st need 2 open the file.
we can do that in 2 way's.
filename = "welcome.txt"
writeto(filename)
or we can put those 2 steps 2gether.
writeto("welcome.txt")
the 1st 1 is easyer for other ppl 2 change the filename 2 save 2 as you can place it seperatly in a config part of the bot or even a special config file.

now we have opend the file we can start writing 2 it.
so were gone start the loop.
for key,vallue in table do
   write("for_you_2_find_out\n")
end
now you see i left something for you 2 find out.
the \n i'll explain, that tells the bot make a new line after writing the stuff we want.

when that is done we only have 2 close the file, this is done by calling writeto again but now without giving a filename.

now we should have a nice file with all the welcome lines.

good luck.

plop
Title:
Post by: plop on 24 January, 2004, 02:17:55
how's it going Stravides, been so quiet here???

plop
Title:
Post by: Stravides on 24 January, 2004, 08:59:59
not too good :(

dunno table structure and objects :(

still trying tho, might help if I knew how to call the value or keys from the table
Title:
Post by: plop on 24 January, 2004, 15:31:59
QuoteOriginally posted by Stravides
not too good :(

dunno table structure and objects :(

still trying tho, might help if I knew how to call the value or keys from the table
ok.
2 insert something in the table you use.
tablename[key]=vallue

and 2 call something from the table you use.
tablename[key]

the key in your case if the users nick.
tablename[user.sName]

plop
Title:
Post by: Stravides on 24 January, 2004, 21:55:18
AAAAAAAAAARRRRRRRGGGGGGGGGGHHHHHHHHHHH

to put it mildly...

for a generic table of

table(key=details)  

Ok I can get the details to a file thats not an issue at all
but how do i record the actual key..

ie I have a few tables, but lets just take 1

OPLoginTable = {
["Stravides"]="The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Malevolence"]="Bow down and Cower for Malevolence has arrived..",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Kyoya"]="RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived..",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty",
};

I then call in a test environment the code

elseif cmd == prefix.."changelogout" then
     for key,value in OPLoginTable do
  SendToAll(BOTName,OPLoginTable[key])
     end
     return 1
elseif....

this outputs the "The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides" and all the other messages.
Once I get this into a sendall I can worry about putting it to file as thats fairly easy.

Thanks for your assistance, sorry I seem a little dim

regards
Stravides
Title:
Post by: Stravides on 24 January, 2004, 23:25:11
Ok things not quite right here, the Send to all works but the save to file does not

The table in question is
OPLoginTable = {
["Stravides"]="The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Malevolence"]="Bow down and Cower for Malevolence has arrived..",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Kyoya"]="RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived..",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty",
};

The dataarrival command is !changelogout
that does 2 things, 1 calls the savetables function and 2 runs the same code to SendToAll.

SaveTable Function  is
function SaveTables(user)
-- openfile("welcomeop.txt", "a")
writeto("welcomeop.txt")
for key,value in OPLoginTable do
  write(OPLoginTable[key].."|\n")
end
writeto("")
-- closefile("welcomeop.txt")
end

The DataArrival Code is  
function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if OPLoginTable[user.sName] then  
OPLoginTable[user.sName] = message
  SendToAll(BOTName,"Login changed to: "..OPLoginTable[user.sName])
end
[B]elseif cmd == prefix.."changelogout" then
SaveTables(user)
for key,value in OPLoginTable do
  SendToAll(BOTName,OPLoginTable[key])
end
return 1[/B] elseif cmd == "!rules" then
user:SendPM(BOTName,rules)
return 1
elseif cmd == "!reghelp" then
user:SendPM(BOTName,reghelp)
return 1
elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end end
end
end

The output from SendToAll is  
The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides
Best be on yer best behaviour as Mrs Sniffy has arrived..
A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew
RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org
Misfits & Miscreants beware! Feuer_Frei is here to check your share!!
From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.
RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org
Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty
Bow down and Cower for Malevolence has arrived..

The File contents of welcomeop.txt is
The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides|
Best be on yer best behaviour as Mrs Sniffy has arrived..|
A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew|
RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org|
Misfits & Miscreants beware! Feuer_Frei is here to check your share!!|
From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.|
Title:
Post by: plop on 25 January, 2004, 22:40:22
ok i'll explain the saving loop a bit more.

for key, vallue in OPLoginTable do

this means it has 2 proces all entry's in the table, key and vallue are here literaly.
most ppl use for a, b in tablename do.
this simply means the key gets called by a and the matching vallue by b.

try the next script with the lua command line.
OPLoginTable = {
["Stravides"]="The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Malevolence"]="Bow down and Cower for Malevolence has arrived..",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Kyoya"]="RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived..",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty",
};

for key, vallue in OPLoginTable do
   print("key = "..key.." and has the vallue: "..vallue)
end
now you should be able 2 see how the line 2 write the stuff 2 the file should be made.

plop
Title:
Post by: Stravides on 26 January, 2004, 01:44:52
Many thanks,

ok now just one last error in that bittie :)

ok using the 2 tables for the moment as below, 9 logins, 9 logouts.

OPLoginTable = {
["Stravides"]="The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Findor_Tallwillow"]="Beware, fakers, slot-lockers and other lamers.  Findor_Tallwillow is here to give you a quick trip to the Abyss... If you aren't one of the above, then smile, and have a good day! ",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Malevolence"]="Bow down and Cower for Malevolence has arrived",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty",
};

OPLogoutTable = {
["Stravides"]="Stravides farts and ignites the gasses that propel him unto infinity. . .",
["Malevolence"]="Where's that mangy chufter Malevolence off to, no doubt he will return soon",
["Blumpy"]="Blumpy flushes himself back to the kingdom of the Brown River",
["Morgyn"]="Bid Farewell to Guest OP Morgyn from RPGmadhouse.no-ip.org",
["Findor_Tallwillow"]="Necromancer heaves a sigh of relief as Findor leaves and invites the rule-breakers back into the hub. If they Dare.",
["Sniffy"]="Phew now that the wife, Sniffy has left I can relax in my slippers",
["Reload3d"]="The taint of Reload3d is no more...",
["Feuer_Frei"]="Feuer_Frei hath departed!!",
["Tumnakitty"]="Alas, I call to me Tumnakitty,the firecat that follows my lead...",
};

for the Byeop.txt I get 4  
key = Stravides and has the vallue: Stravides farts and ignites the gasses that propel him unto infinity. . .
key = Sniffy and has the vallue: Phew now that the wife, Sniffy has left I can relax in my slippers
key = Findor_Tallwillow and has the vallue: Necromancer heaves a sigh of relief as Findor leaves and invites the rule-breakers back into the hub. If they Dare.
key = Reload3d and has the vallue: The taint of Reload3d is no more.

for the welcomeop.txt I get 7
key = Stravides and has the vallue: The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides
key = Sniffy and has the vallue: Best be on yer best behaviour as Mrs Sniffy has arrived
key = Findor_Tallwillow and has the vallue: Beware, fakers, slot-lockers and other lamers.  Findor_Tallwillow is here to give you a quick trip to the Abyss... If you aren't one of the above, then smile, and have a good day!
key = Reload3d and has the vallue: A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew
key = Morgyn and has the vallue: RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org
key = Feuer_Frei and has the vallue: Misfits & Miscreants beware! Feuer_Frei is here to check your share!!
key = Blumpy and has the vallue: From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.


I used as you say, not the print but write and it put it to file not all lines are written any suggestions ?

regards
Stravides
Title:
Post by: plop on 26 January, 2004, 01:59:58
QuoteOriginally posted by Stravides
Many thanks,

ok now just one last error in that bittie :)

ok using the 2 tables for the moment as below, 9 logins, 9 logouts.



for the Byeop.txt I get 4  
key = Stravides and has the vallue: Stravides farts and ignites the gasses that propel him unto infinity. . .
key = Sniffy and has the vallue: Phew now that the wife, Sniffy has left I can relax in my slippers
key = Findor_Tallwillow and has the vallue: Necromancer heaves a sigh of relief as Findor leaves and invites the rule-breakers back into the hub. If they Dare.
key = Reload3d and has the vallue: The taint of Reload3d is no more.

for the welcomeop.txt I get 7
key = Stravides and has the vallue: The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides
key = Sniffy and has the vallue: Best be on yer best behaviour as Mrs Sniffy has arrived
key = Findor_Tallwillow and has the vallue: Beware, fakers, slot-lockers and other lamers.  Findor_Tallwillow is here to give you a quick trip to the Abyss... If you aren't one of the above, then smile, and have a good day!
key = Reload3d and has the vallue: A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew
key = Morgyn and has the vallue: RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org
key = Feuer_Frei and has the vallue: Misfits & Miscreants beware! Feuer_Frei is here to check your share!!
key = Blumpy and has the vallue: From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.


I used as you say, not the print but write and it put it to file not all lines are written any suggestions ?

regards
Stravides
i guess key is here just a dummy, as you can only use the same key 1x.

can you post the function which writes the file??
that makes it a bit easyer 2 see what is going wrong.

plop
Title:
Post by: Stravides on 26 January, 2004, 02:01:53
heres the lot :)

--    Variables  
BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Stripped Version V6.99"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.3 Stravides $ $Black Light"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"
version = BOTName.." "..ScriptVersion
prefix = "!"

ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

-- dofile("messages.cfg");  -- this will hold the tables below

UserBotTable = {
["Stravides"]="Thanatos",
["Blumpy"]="King Dung",
["Morgyn"]="Guest OP",
["Kyoya"]="Guest OP",
["Reload3d"]="Pug",
["Tumnakitty"]="Bast",
};

OPLoginTable = {
["Stravides"]="The Heavens hathed opened and thus vomitted forth the hapless figure of Stravides",
["Blumpy"]="From the festering brown froth of the sewers, the Overlord of Faeces, Blumpy, emerges.",
["Morgyn"]="RPGBooks Cymru Welcomes a Guest OP - Morgyn from RPGmadhouse.no-ip.org",
["Sniffy"]="Best be on yer best behaviour as Mrs Sniffy has arrived",
["Reload3d"]="A large dog looms over, twitches, moans and chuffs up the steaming body of Reload3d - eeeeew",
["Malevolence"]="Bow down and Cower for Malevolence has arrived",
["Feuer_Frei"]="Misfits & Miscreants beware! Feuer_Frei is here to check your share!!",
["Tumnakitty"]="Welcome, my daughter and servant... soft be your feline footfalls, Tumnakitty",
["Findor_Tallwillow"]="Beware, fakers, slot-lockers and other lamers.  Findor_Tallwillow is here to give you a quick trip to the Abyss... If you aren't one of the above, then smile, and have a good day! ",
};

OPLogoutTable = {
["Stravides"]="Stravides farts and ignites the gasses that propel him unto infinity. . .",
["Malevolence"]="Where's that mangy chufter Malevolence off to, no doubt he will return soon",
["Blumpy"]="Blumpy flushes himself back to the kingdom of the Brown River",
["Morgyn"]="Bid Farewell to Guest OP Morgyn from RPGmadhouse.no-ip.org",
["Sniffy"]="Phew now that the wife, Sniffy has left I can relax in my slippers",
["Reload3d"]="The taint of Reload3d is no more.",
["Feuer_Frei"]="Feuer_Frei hath departed!",
["Tumnakitty"]="Alas, I call to me Tumnakitty,the firecat that follows my lead.",
["Findor_Tallwillow"]="Necromancer heaves a sigh of relief as Findor leaves and invites the rule-breakers back into the hub. If they Dare.",
};

VIPLogInTable = {
["Warian"]="Warian - The one who is all that which stands for that which is the epitome` of that which is The World of [Darkness enters!",
["Kyoya"]="RPGBooks Cymru Welcomes a Guest OP - Kyoya from RPGmadhouse.no-ip.org",
["Spider"]="Spider has entered the Hub, put all small mammals away!!!",
["fortywinks"]="The slumbering tones of Fortywinks graces the hub",
};

VIPLogOutTable = {
["Warian"]="Warian - The World of Darkness Guru has left, and taken his Weremidgets with him!",
["Kyoya"]="Bid Farewell to the Guest OP from RPGmadhouse.no-ip.org",
["Spider"]="As the Sun goes down, the reflections cease from Spider as he logs off..",
["fortywinks"]="As Fortywinks leaves, he casts a farewell wave..",
};


reghelp = "\r\n"..
"The command to register a new user is !addreguser \r\n"..
"Blah Blah\r\n"..
"Moderator Just lets em kick and gag \r\n"

rules = "\r\n"..
"                                   Rules \r\n"..
"\r\n"..
"Failure to comply with these rules will mean perm bans from this hub.\r\n"..
"\r\n"..
"01. You must share at least 50MB of Applicable Files. (RPG, Video, MP3)\r\n"..
"Blah Blah\r\n"..
"16. Don't ask for OP. we'll ask you :)\r\n"


function Main()
frmHub:UnregBot(BOTName)
frmHub:UnregBot("Necromancer")
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
AddProfile("Moderator", 4269273088)
AddProfile("Guest", 2148028000)
end

function DoRead(user)
while 1 do
pline = read()
if pline == nil then break end
user:SendPM(BOTName, pline)
end
readfrom()
end

function MyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

--------- Begin Connection Functions ---------

function OpConnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
local botin = ""

if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if OPLoginTable[user.sName] then
SendToAll(BotIn,OPLoginTable[user.sName])
else    
SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
end

function OpDisconnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if OPLogoutTable[user.sName] then
SendToAll(BotIn,OPLogoutTable[user.sName])
elseif user.iProfile == 1 then
SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

function NewUserConnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if VIPLogInTable[user.sName] then
SendToAll(BotIn,VIPLogInTable[user.sName])
elseif user.iProfile == 2 then
SendToAll(BotIn, "[VIP] "..user.sName..", has Connected")  
elseif user.iProfile == nil then
SendToNick(BOTName, ""..user.sName..", has Connected" )
end
end

function UserDisconnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if VIPLogOutTable[user.sName] then
SendToAll(BotIn,VIPLogOutTable[user.sName])
elseif (user.sName == "fortywinks") then
SendToAll(BotIn, ""..fortywinks2.."")
elseif user.iProfile == 2 then
SendToAll(BOTName, "[VIP] "..user.sName..", has Disconnected")  
end
end

--------- End Connection Functions ---------

function SaveTables(user)
writeto("welcomeop.txt")
for key, vallue in OPLoginTable do
write("key = "..key.." and has the vallue: "..vallue.."\n")
end
writeto("byeop.txt")
for key, vallue in OPLogoutTable do
write("key = "..key.." and has the vallue: "..vallue.."\n")
end
writeto("")
end

------ DataArrival Scripts

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if OPLoginTable[user.sName] then  
OPLoginTable[user.sName] = message
  SendToAll(BOTName,"Login changed to: "..OPLoginTable[user.sName])
end
elseif cmd == prefix.."changelogout" then
SaveTables(user)
SendToAll(BOTName,"Data Changed")
return 1
elseif cmd == "!rules" then
user:SendPM(BOTName,rules)
return 1
elseif cmd == "!reghelp" then
user:SendPM(BOTName,reghelp)
return 1
elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end end
end
end
Title:
Post by: plop on 26 January, 2004, 02:36:18
try it like this.
function SaveTables(user)
writeto("welcomeop.txt")
for key, vallue in OPLoginTable do
      OPLoginTable[key]=vallue
write("key = "..key.." and has the vallue: "..vallue.."\n")
end
   writeto()
writeto("byeop.txt")
for key, vallue in OPLogoutTable do
      OPLogoutTable[key]=vallue
write("key = "..key.." and has the vallue: "..vallue.."\n")
end
writeto()
end
you always have 2 close a open file before opening a new 1.
the other extra line i added is just a safety, shouldn't be necesary 2 add.

plop
Title:
Post by: Stravides on 27 January, 2004, 01:26:30
Ok done :D  CHEESY GRIN

ok now please can you assist me in reducing the number of repititions of the loads and saves as this is quite large and hard to read...  
one big thanks to all those that have helped, but now we need to tidy up the code...  suggestions are welcomed  

regards
     Stravides

Oops made a mistake, heres the correct code

--    Variables  
--    Developed By Stravides, tutored by Plop and the Lua boards
--    Many thanks to all that made this possible..
--    OriginalBOTName="Smeagol"
--    OriginalHubAdress = "RPGBooks-Cymru.no-ip.org"

BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Stripped Version V6.99"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.3 Stravides $ $Black Light"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"
version = BOTName.." "..ScriptVersion
prefix = "!"
strGSep = "|"

opin="welcomeop.txt"
vipin="welcomevip.txt"
opout ="byeop.txt"
vipout="byevip.txt"

ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

-- dofile("messages.cfg");  -- this will hold the tables below

UserBotTable = {
["Stravides"]="Thanatos",
["Blumpy"]="King Dung",
["Morgyn"]="Guest OP",
["Kyoya"]="Guest OP",
["Waylander"]="Scoobie",
["Tumnakitty"]="Bast",
};

OPLogInTable = {
 };

OPLogOutTable = {
};

VIPLogInTable = {
};

VIPLogOutTable = {
};

reghelp = "\r\n"..
"The command to register a new user is !addreguser \r\n"..
"ALL of these parameters are case sensitive\r\n"..
"\r\n"..
"name is thier username\r\n"..
"password is the pass they must use to get into system\r\n"..
"level is one of the below...\r\n"..
"\r\n"..
"Operator Only Stravides or Reload3d should set this user level\r\n"..
"VIP Only Stravides or Reload3d should set this user level\r\n"..
"Reg Std registered user - please use this \r\n"..
"Moderator Just lets em kick and gag \r\n"

rules = "\r\n"..
"                                   Rules \r\n"..
"\r\n"..
"Failure to comply with these rules will mean perm bans from this hub.\r\n"..
"\r\n"..
"01. You must share at least 50MB of Applicable Files. (RPG, Video, MP3)\r\n"..
"02. Please speak English *only* in the main chat. We realize that not everyone is fluent in it, be hey, look at it as a learning experience !\r\n"..
"03. Zero Porn Toleration. This means your run-of-the-mill stuff Hentai, Disney toons, or anything similar. You will receive one warning. Then you will be banned. Sick porn, teen porn, and/or kiddie porn will all be banned without warning or absolution. \r\n"..
"04. Don't use excessive Caps in main chat, don't change your nick, do not flood or spam, and do not post ads for other hubs.\r\n"..
"05. Slotlocking or faksesharing will result in an immediate and permanent ban. No questions asked.\r\n"..
"06. Download speed limiters (shown as B: or L: in desc tags) are not allowed in this hub it will lead to a ban. \r\n"..
"07. 3 kicks will lead to automatic ban!\r\n"..
"08. No racist propaganda or music.\r\n"..
"09. Don't share installed Games/Programs files or incomplete files \r\n"..
"10. Don't share .VOB-files \r\n"..
"11. Don't share *.eml or *.pst-files (your e-mail files). Besides being stupid to share your private e-mail, they may contain viruses.\r\n"..
"12. Don't close other users from downloading. (If you must do it, then give them a good reason!)\r\n"..
"13. Don't flood or spam the chat.\r\n"..
"14. Don't attack other hub users in the main chat. Chat nice or don't chat at all!\r\n"..
"15. 6 HUBS MAX, 1 SLOT PER HUB !!!!\r\n"..
"16. Don't ask for OP. we'll ask you :)\r\n"..
"17. 56k users and below please note MAX 2 HUBS MAX 2 Slots\r\n"


function Main()
frmHub:UnregBot(BOTName)
frmHub:UnregBot("Necromancer")
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
AddProfile("Moderator", 4269273088)
AddProfile("Guest", 2148028000)
LoadOPLogInTables(user)
LoadOPLogOutTables(user)
LoadVIPLogInTables(user)
LoadVIPLogOutTables(user)
end

function DoRead(user)
while 1 do
pline = read()
if pline == nil then break end
user:SendPM(BOTName, pline)
end
readfrom()
end

function MyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

--------- Begin Connection/Diconnection Functions ---------
function OpConnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
local botin = ""

if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if OPLogInTable[user.sName] then
SendToAll(BotIn,OPLogInTable[user.sName])
else    
SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
user:SendPM(BOTName,rules)
end

function OpDisconnected(user)
description,speed,email,share=MyInfoString(user.sMyInfoString)
local share2 = share / (1024*1024*1024)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if OPLogOutTable[user.sName] then
SendToAll(BotIn,OPLogOutTable[user.sName])
elseif user.iProfile == 1 then
SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

function NewUserConnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if VIPLogInTable[user.sName] then
SendToAll(BotIn,VIPLogInTable[user.sName])
elseif user.iProfile == 2 then
SendToAll(BotIn, "[VIP] "..user.sName..", has Connected")  
elseif user.iProfile == nil then
SendToNick(BOTName, ""..user.sName..", has Connected" )
end
user:SendPM(BOTName,rules)
end

function UserDisconnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if VIPLogOutTable[user.sName] then
SendToAll(BotIn,VIPLogOutTable[user.sName])
elseif (user.sName == "fortywinks") then
SendToAll(BotIn, ""..fortywinks2.."")
elseif user.iProfile == 2 then
SendToAll(BOTName, "[VIP] "..user.sName..", has Disconnected")  
end
end
--------- End Connection Functions ---------


function tokenize (inString,token)
_WORDS = {}
local matcher = "([^"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

--------- End Load Table Functions ---------
function LoadOPLogInTables(user)
local handle = openfile(opin, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
OPLogInTable[arrTmp[1]] = arrTmp[2]
end
line = read(handle)
end
closefile(handle)
end
end

function LoadOPLogOutTables(user)
local handle = openfile(opout, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
OPLogOutTable[arrTmp[1]] = arrTmp[2]
end
line = read(handle)
end
closefile(handle)
end
end

function LoadVIPLogInTables(user)
local handle = openfile(vipin, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
VIPLogInTable[arrTmp[1]] = arrTmp[2]
end
line = read(handle)
end
closefile(handle)
end
end

function LoadVIPLogOutTables(user)
local handle = openfile(vipout, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
VIPLogOutTable[arrTmp[1]] = arrTmp[2]
end
line = read(handle)
end
closefile(handle)
end
end
--------- End Load Table Functions ---------

--------- Start Save Table Functions ---------
function SaveOPLogInTables(user)
writeto(opin)
for key, value in OPLogInTable do
OPLogInTable[key]=value
write(key.."|"..value.."\n")
end
    writeto()
end

function SaveOPLogOutTables(user)
writeto(opout)
for key, value in OPLogOutTable do
OPLogOutTable[key]=value
write(key.."|"..value.."\n")
end
writeto()
end

function SaveVIPLogInTables(user)
writeto(vipin)
for key, value in VIPLogInTable do
VIPLogInTable[key]=value
write(key.."|"..value.."\n")
end
    writeto()
end

function SaveVIPLogOutTables(user)
writeto(vipout)
for key, value in VIPLogOutTable do
VIPLogOutTable[key]=value
write(key.."|"..value.."\n")
end
writeto()
end
--------- End Save Table Functions ---------

------ DataArrival Scripts

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new Login Message")
elseif user.iProfile == 1 or user.iProfile == 0 then
LoadOPLogInTables(user)
if OPLogInTable[user.sName] then  
OPLogInTable[user.sName] = message
  SaveOPLogInTables(user)
user:SendPM(BOTName,"Login Changed to: "..message)
end
return 1
elseif user.iProfile == 2 then
LoadVIPLogInTables(user)
if VIPLogInTable[user.sName] then  
VIPLogInTable[user.sName] = message
  SaveVIPLogInTables(user)
user:SendPM(BOTName,"Login Changed to: "..message)
end
return 1
end
elseif cmd == prefix.."changelogout" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new Logout Message")
elseif user.iProfile == 1 or user.iProfile == 0 then
LoadOPLogOutTables(user)
if OPLogOutTable[user.sName] then  
OPLogOutTable[user.sName] = message
  SaveOPLogOutTables(user)
user:SendPM(BOTName,"Logout Changed to: "..message)
end
return 1
elseif user.iProfile == 2 then
LoadVIPLogInTables(user)
if VIPLogInTable[user.sName] then  
VIPLogInTable[user.sName] = message
  SaveVIPLogInTables(user)
user:SendPM(BOTName,"Logout Changed to: "..message)
end
return 1
end
elseif cmd == "!rules" then
user:SendPM(BOTName,rules)
return 1
elseif cmd == "!reghelp" then
user:SendPM(BOTName,reghelp)
return 1
elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end
end
end
end

4 files are also needed
welcomeop.txt, welcomevip.txt, byeop.txt, byevip.txt

format
Username|message
ie
Stravides|Welcomes the OP Stravides

Hope to hear from ya soooon

Stravides
Title:
Post by: plop on 27 January, 2004, 03:18:33
ok couple hints:

lets start @ the top.

nothing wrong there. lol
but it would be handyer if you used txt files for reghelp and rules.

now function main confuses me a little bit, 1st you unreg 2 bots and next you reg 1 of them again.?????
adding of profiles is only needed 1x in your ptokax life, no need 2 do the same thing over and over again on every start of the script.

function DoRead misses a vital part but you don't seem 2 use it so no problem, but you can mod it 2 show the rules/reghelp.

function OpConnected i guess you wanne add or have stripped the share/slots/hub stuff here as it does nothing.
tiny spelling error below that, botin isn't the same as BotIn.
fun idea btw 2 have a botname per op.

function OpDisconnected, here you do the same desc/speed/email/share check, but why i don't know.

the functions for user/vip entering is perfect,nothing wrong there.

hope i don't sound 2 mean so far.

the loading of the tables, i think you should change that a bit.
a strfind can do it all a lot faster as you know 100% how the file looks.
i'll give you a hint on that:
username|text  ---->   "(.+)|(.+)"

now you allready say yourself it's getting big.
you now have 4 save and 4 load functions, why not half that number 2 start with by stuffing the ops and vips in the same table.?
l8er you can even half that again.
no need 2 transfer user 2 these functions as they aren't used anymore SaveVIPLogInTables() whill do fine.

oke finaly DataArrival.
not much 2 say here looks great, got just 2 small things 2 say here.
loading of the tables isn't needed as they are in memory allready, you only need 2 safe here after changing.
which you do.
the other things is even smaller, everywhere you use that nice prefix except on rules and reghelp.
just looks nicer if you use the prefix there 2.

just did a preview on my post and it looks like a lot of homework. lol
take it step for step and maby start with the loading of the files.
so this tread stays in 1 line 2 learn, I bet/hope your not the only 1 trying 2 make this script. lol
but anyway, keep going like this, your doing great.

plop
Title:
Post by: Stravides on 27 January, 2004, 05:04:18
QuoteOriginally posted by plop

but it would be handyer if you used txt files for reghelp and rules. Done

now function main confuses me a little bit, 1st you unreg 2 bots and next you reg 1 of them again.?????
adding of profiles is only needed 1x in your ptokax life, no need 2 do the same thing over and over again on every start of the script.
Done legacy code from when I had this changing bot name

function DoRead misses a vital part but you don't seem 2 use it so no problem, but you can mod it 2 show the rules/reghelp. Done not required

function OpConnected i guess you wanne add or have stripped the share/slots/hub stuff here as it does nothing.Done
tiny spelling error below that, botin isn't the same as BotIn.Done
fun idea btw 2 have a botname per op.

function OpDisconnected, here you do the same desc/speed/email/share check, but why i don't know.Done

Not sure on this bit tho...
the loading of the tables, i think you should change that a bit.
a strfind can do it all a lot faster as you know 100% how the file looks.
i'll give you a hint on that:
username|text  ---->   "(.+)|(.+)"
 
 

now you allready say yourself it's getting big.
you now have 4 save and 4 load functions, why not half that number 2 start with by stuffing the ops and vips in the same table.?
l8er you can even half that again.Done
no need 2 transfer user 2 these functions as they aren't used anymore SaveVIPLogInTables() whill do fine.Done

oke finaly DataArrival.
not much 2 say here looks great, got just 2 small things 2 say here.
loading of the tables isn't needed as they are in memory allready, you only need 2 safe here after changing.Done
which you do.
the other things is even smaller, everywhere you use that nice prefix except on rules and reghelp.
just looks nicer if you use the prefix there 2.Done

--    Developed By Stravides, tutored by Plop and the Lua boards
--    Many thanks to all that made this possible..
--    OriginalBOTName = "Smeagol"
--    OriginalHubAdress = "RPGBooks-Cymru.no-ip.org"
--    Variables  

BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Testing Beta Version V7.00"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:7.00 Smeagol $ $the Precioussss"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"
version = BOTName.." "..ScriptVersion
prefix = "!"
strGSep = "|"

log_in="logintext.txt"
log_out ="logouttext.txt"

ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

dofile("data.cfg");  -- this holds the rules and text files

UserBotTable = {
["Stravides"]="Thanatos",
["Blumpy"]="King Dung",
["Morgyn"]="Guest OP",
["Kyoya"]="Guest OP",
["Waylander"]="Scoobie",
["Tumnakitty"]="Bast",
};

LogInTable = { };
LogOutTable = { };

function Main()
frmHub:UnregBot(BOTName)
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
LoadLogInTables()
LoadLogOutTables()

end

--------- Begin Connection/Diconnection Functions ---------
function OpConnected(user)
local BotIn = ""
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogInTable[user.sName] then
SendToAll(BotIn,LogInTable[user.sName])
else    
SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
user:SendPM(BOTName,rules)
end

function OpDisconnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogOutTable[user.sName] then
SendToAll(BotIn,LogOutTable[user.sName])
elseif user.iProfile == 1 then
SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

function NewUserConnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogInTable[user.sName] then
SendToAll(BotIn,LogInTable[user.sName])
elseif user.iProfile == 2 then
SendToAll(BotIn, "[VIP] "..user.sName..", has Connected")  
elseif user.iProfile == nil then
SendToNick(BOTName, ""..user.sName..", has Connected" )
end
user:SendPM(BOTName,rules)
end

function UserDisconnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogOutTable[user.sName] then
SendToAll(BotIn,LogOutTable[user.sName])
elseif (user.sName == "fortywinks") then
SendToAll(BotIn, ""..fortywinks2.."")
elseif user.iProfile == 2 then
SendToAll(BOTName, "[VIP] "..user.sName..", has Disconnected")  
end
end
--------- End Connection Functions ---------


function tokenize (inString,token)
_WORDS = {}
local matcher = "([^"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

--------- End Load Table Functions ---------
function LoadLogInTables()
local handle = openfile(log_in, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
LogInTable[arrTmp[1]] = arrTmp[2]
end
line = read(handle)
end
closefile(handle)
end
end

function LoadLogOutTables()
local handle = openfile(log_out, "r")
if (handle) then
local line = read(handle)
while line do
local arrTmp = tokenize(line, strGSep)
if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
LogOutTable[arrTmp[1]] = arrTmp[2]
end
line = read(handle)
end
closefile(handle)
end
end
--------- End Load Table Functions ---------

--------- Start Save Table Functions ---------
function SaveLogInTables()
writeto(log_in)
for key, value in LogInTable do
LogInTable[key]=value
write(key.."|"..value.."\n")
end
    writeto()
end

function SaveLogOutTables()
writeto(log_out)
for key, value in LogOutTable do
LogOutTable[key]=value
write(key.."|"..value.."\n")
end
writeto()
end
--------- End Save Table Functions ---------

------ DataArrival Scripts

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new Login Message")
elseif user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
LoadLogOutTables()
if LogInTable[user.sName] then  
LogInTable[user.sName] = message
  SaveLogInTables()
user:SendPM(BOTName,"Login Changed to: "..message)
end
return 1
end
elseif cmd == prefix.."changelogout" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new Logout Message")
elseif user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
LoadLogOutTables()  
if LogOutTable[user.sName] then  
LogOutTable[user.sName] = message
  SaveLogOutTables()
user:SendPM(BOTName,"Logout Changed to: "..message)
end
return 1
end
elseif cmd == prefix.."rules" then
user:SendPM(BOTName,rules)
return 1
elseif cmd == prefix.."reghelp" then
user:SendPM(BOTName,reghelp)
return 1
elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end
end
end
end
Title:
Post by: Stravides on 27 January, 2004, 05:32:18
forget that, I suggest that this is whats needed

function LoadLogInTables()
local handle = openfile(log_in, "r")
if (handle) then
local line = read(handle)
while line do
username,text = strfind(line, "(.+)|(.+)")
if ((username ~= nil) and (text ~= nil)) then
LogInTable[username] = text
end
line = read(handle)
end
closefile(handle)
end
end

function LoadLogOutTables()
local handle = openfile(log_out, "r")
if (handle) then
local line = read(handle)
while line do
username,text = strfind(line, "(.+)|(.+)")
if ((username ~= nil) and (text ~= nil)) then
LogInTable[username] = text
end
line = read(handle)
end
closefile(handle)
end
end
Title:
Post by: Stravides on 27 January, 2004, 15:31:25
EEEEEEK

Thats not working am I losing my mind.... :(  ;(
Title:
Post by: plop on 27 January, 2004, 17:04:23
QuoteOriginally posted by Stravides
forget that, I suggest that this is whats needed

function LoadLogInTables()
local handle = openfile(log_in, "r")
if (handle) then
local line = read(handle)
while line do
username,text = strfind(line, "(.+)|(.+)")
if ((username ~= nil) and (text ~= nil)) then
LogInTable[username] = text
end
line = read(handle)
end
closefile(handle)
end
end

function LoadLogOutTables()
local handle = openfile(log_out, "r")
if (handle) then
local line = read(handle)
while line do
username,text = strfind(line, "(.+)|(.+)")
if ((username ~= nil) and (text ~= nil)) then
LogInTable[username] = text
end
line = read(handle)
end
closefile(handle)
end
end
your really close but your forgetting a vital part for strfind 2 work.
for a hint, check how you find the commands in DataArrival

i personaly never use handles on loading/saving.
if readfrom(file) then
   readfrom(file)
does the same as opening with handles in read mode.
1st line is just a check 2 see if the file excists.
but this a real personal thing, most scripters are using the handles way.

plop
Title:
Post by: Stravides on 27 January, 2004, 18:06:11
QuoteOriginally posted by plop

function LoadLogInTables()
local handle = openfile(log_in, "r")
if (handle) then
local line = read(handle)
while line do
username,text = strfind(line, "(.+)|(.+)")
if ((username ~= nil) and (text ~= nil)) then
LogInTable[username] = text
end
line = read(handle)
end
closefile(handle)
end
end

your really close but your forgetting a vital part for strfind 2 work.  for a hint, check how you find the commands in DataArrival
plop

ok I think the code below is missing, but does that mean that i need to pass data to the load function ?

if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(.+)|(.+)")

Title:
Post by: plop on 29 January, 2004, 14:03:33
compair these 2.
s,e,cmd = strfind(data,"%b<>%s+(%S+)")   <--- from DataArrival.
username,text = strfind(line, "(.+)|(.+)")  <---- from your load function.

plop
Title:
Post by: Stravides on 29 January, 2004, 15:12:34
QuoteOriginally posted by plop
compair these 2.
s,e,cmd = strfind(data,"%b<>%s+(%S+)")   <--- from DataArrival.
username,text = strfind(line, "(.+)|(.+)")  <---- from your load function.

plop
having said that, is this the corect syntax ?

s,e,cmd,username,text = strfind(data,"%b<>%s+(.+)|(.+)")
Title:
Post by: plop on 29 January, 2004, 15:52:25
QuoteOriginally posted by Stravides
QuoteOriginally posted by plop
compair these 2.
s,e,cmd = strfind(data,"%b<>%s+(%S+)")   <--- from DataArrival.
username,text = strfind(line, "(.+)|(.+)")  <---- from your load function.

plop
having said that, is this the corect syntax ?

s,e,cmd,username,text = strfind(data,"%b<>%s+(.+)|(.+)")
now your mixing them up.
the strfind in DataArrival is correct, but the 1 on loading of the file is wrong.
the s,e, part is missing there, which results in username and text getting the vallue which normaly s and e would get.

plop
Title:
Post by: Stravides on 29 January, 2004, 17:55:06
Sorry 2Watt bulb here again, musta played with this in any number of ways.. .still doesnt work..

The pattern that I am looking for is (.+)|(.+),
Now if I read your post on pattern matching
All of those chars are Magic except for the | Is this causing me a problem as I'm not using an escape char ?  I really am not sure on this one at all.

again in waiting

Stravides
The Dim Padawan
Title:
Post by: plop on 29 January, 2004, 21:44:40
this 1 is correct, don't touch it. lol
s,e,cmd = strfind(data,"%b<>%s+(%S+)")   <--- from DataArrival.

this 1 is just missing the s,e, part.
username,text = strfind(line, "(.+)|(.+)")  <---- from your load function.

this is all you need 2 do 2 fix it.
s,e,username,text = strfind(line, "(.+)|(.+)")

1 side note, i'm working on part 2 of the pattern matching howto which explains the magic stuff.

plop
Title:
Post by: Stravides on 30 January, 2004, 00:02:41
Excellent, await magics, ammends code to this... sure I've tried this before :)

but will post results here :)
Title:
Post by: plop on 30 January, 2004, 00:29:12
QuoteOriginally posted by Stravides
Excellent, await magics, ammends code to this... sure I've tried this before :)

but will post results here :)
pattern matching part 2 is posted, same thread as part 1.

plop
Title:
Post by: Stravides on 30 January, 2004, 00:49:29
Now I know I had tested that as it was in a previous rev... problem was, that i was still calling the old script too so it didnt work :)  Doh..  
Ok job done, heres the code...

Though I just have 1 more question... hehehe
Theres duplication here... is there a way that I can just use one of each of these and just pass the table name ?

is it simple as function loadtable(tablename)

and then tablename[username]=text

using the callup as loadtable(UserBotTable)

???

--------- Start Load Table Functions ---------
function LoadBotsTables()
local handle = openfile(botsfile, "r")
if (handle) then
local line = read(handle)
while line do
s,e,username,text = strfind(line, "(.+)|(.+)")
if username ~= nil and text ~= nil  then
UserBotTable[username]=text
end
line = read(handle)
end
closefile(handle)
end
end

function LoadLogInTables()
local handle = openfile(log_in, "r")
if (handle) then
local line = read(handle)
while line do
s,e,username,text = strfind(line, "(.+)|(.+)")
if username ~= nil and text ~= nil  then
LogInTable[username]=text
end
line = read(handle)
end
closefile(handle)
end
end

function LoadLogOutTables()
local handle = openfile(log_out, "r")
if (handle) then
local line = read(handle)
while line do
s,e,username,text = strfind(line, "(.+)|(.+)")
if username ~= nil and text ~= nil  then
LogOutTable[username]=text
end
line = read(handle)
end
closefile(handle)
end
end
--------- End Load Table Functions ---------

--------- Start Save Table Functions ---------
function SaveBotsTables()
writeto(botsfile)
for key, value in UserBotTable do
UserBotTable[key]=value
write(key.."|"..value.."\n")
end
    writeto()
end
function SaveLogInTables()
writeto(log_in)
for key, value in LogInTable do
LogInTable[key]=value
write(key.."|"..value.."\n")
end
    writeto()
end

function SaveLogOutTables()
writeto(log_out)
for key, value in LogOutTable do
LogOutTable[key]=value
write(key.."|"..value.."\n")
end
writeto()
end

--------- End Save Table Functions ---------
Title:
Post by: plop on 30 January, 2004, 04:01:48
QuoteOriginally posted by Stravides
Now I know I had tested that as it was in a previous rev... problem was, that i was still calling the old script too so it didnt work :)  Doh..  
Ok job done, heres the code...

Though I just have 1 more question... hehehe
Theres duplication here... is there a way that I can just use one of each of these and just pass the table name ?

is it simple as function loadtable(tablename)

and then tablename[username]=text

using the callup as loadtable(UserBotTable)

???
thats indeed posible, take a look @ my latest crazy bot.
4 modes use the same function 2 replace characters from 4 different tables.
modes 13-16 all call this function, just with a different table.
function Replace(letter, table)
   if table[letter] then
      letter = table[letter]
   end
   return letter
end
but hope i don't confuse you here on the way it's working, as far as i know only me and tezlo released scripts working with functions in tables and even in the functions in the tables calling other functions.
i think i should say, don't try this 2 home. lol
it can be really hard 2 find a bug in these kind of scripts.
but using 1 function for loading/saving multiple files/tables should be posible for you 2 do.
just replace letter for filename and table stays the same.
so you get loadtable(filename, tablename), same kind of thing for saving.

plop
Title:
Post by: Stravides on 30 January, 2004, 10:53:28
Very Very possible :)

Thanks, I think that this is going to be my released version, I have maybe some minor tweaks to do, but heres the skinny on it.

Smeagol uses 4 files
     logintext.txt
     logouttext.txt
     botstext.txt
     data.cfg

The 1st 3 are simple username|text for login/out and bot texts.

The data.cfg holds the rules and the reghelp for this proggy...

Again I give a huge thanks to Plop and the boards for making my 1st REAL bot.



--------------------------------------------------------------------------------------------------
-- --
-- Bot Name : Smeagol --
-- Home : RPGBooks-Cymru.no-ip.org --
-- Version : Final Release 1.00 --
-- Date Complete : 30th January 2004 --
--     Credits : Developed By Stravides, Tutored by Plop upon the Lua boards --
--     Thanks to : Many thanks to all that made this possible.. --
-- Copyright : There's no problem taking and ammending this script, but --
-- please leave in this Credit Section --
-- --
--------------------------------------------------------------------------------------------------

---------------- Variables used -----------------------

BOTName="Smeagol"
HubAdress = "RPGBooks-Cymru.no-ip.org"
ScriptVersion = "Final Release - V9.01"
BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:9.01 Smeagol $ $the Precioussss"..strchar( 1 ).."$Stravides@RPGBooks-Cymru.no-ip.org$"
version = BOTName.." "..ScriptVersion
prefix = "!"

----------------- Files Used --------------------------

log_in="smeagol/logintext.txt"
log_out ="smeagol/logouttext.txt"
botsfile="smeagol/botstext.txt"
configfile="smeagol/data.cfg"

dofile(configfile);  -- this holds the rules and text files
----------------- Tables Used --------------------------

UserBotTable = { };
LogInTable = { };
LogOutTable = { };

------------------ End Variables -----------------------

------------------ Begin Constants ---------------------
ptokaxcommands = {
op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
clrpermban = 1, topic = 1, reloadtxt = 1 }

------------------ End Constants -----------------------


function Main()
frmHub:UnregBot(BOTName)
frmHub:RegBot(BOTName)
SendToAll(BOTNameInfo)
UseTables(log_in,LogInTable)
UseTables(log_out,LogOutTable)
UseTables(botsfile,UserBotTable)
end

--------- Begin Connection/Disconnection Functions ---------
function OpConnected(user)
local BotIn = ""
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogInTable[user.sName] then
SendToAll(BotIn,LogInTable[user.sName])
else    
SendToAll(BOTName, "[OPS] "..user.sName.." has joined the hub")
end
user:SendPM(BOTName,rules)
end

function OpDisconnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogOutTable[user.sName] then
SendToAll(BotIn,LogOutTable[user.sName])
elseif user.iProfile == 1 then
SendToAll(BOTName, "[OP] "..user.sName.." Has Left the Hub")  
end
end

function NewUserConnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogInTable[user.sName] then
SendToAll(BotIn,LogInTable[user.sName])
elseif user.iProfile == 2 then
SendToAll(BotIn, "[VIP] "..user.sName..", has Connected")  
elseif user.iProfile == nil then
SendToNick(BOTName, ""..user.sName..", has Connected" )
end
user:SendPM(BOTName,rules)
end

function UserDisconnected(user)
if UserBotTable[user.sName] then
BotIn = UserBotTable[user.sName]
else
BotIn = BOTName
end
if LogOutTable[user.sName] then
SendToAll(BotIn,LogOutTable[user.sName])
elseif user.iProfile == 2 then
SendToAll(BOTName, "[VIP] "..user.sName..", has Disconnected")  
end
end
--------- End Connection Functions ---------

--------- Start Load Table Functions ---------
function UseTables(filename,table)
local handle = openfile(filename, "r")
if (handle) then
local line = read(handle)
while line do
s,e,username,text = strfind(line, "(.+)|(.+)")
if username ~= nil and text ~= nil  then
table[username]=text
end
line = read(handle)
end
closefile(handle)
end
end
--------- End Load Table Functions ---------

--------- Start Save Table Functions ---------

function SaveTable(filename,table)
writeto(filename)
for key, value in table do
table[key]=value
write(key.."|"..value.."\n")
end
    writeto()
end

--------- End Save Table Functions ---------

--------- This creates the dummy scripts for the new registered users.  If they are not in table they cant be ammended :)

function AddBlanksToTables(uName,filename,table)
UseTables(filename,table)
writeto(filename)
for key, value in table do
table[key]=value
write(key.."|"..value.."\n")
end
write(uName.."| New User Connected \n")
writeto()
end

-------------- DataArrival Script -----------------

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == prefix.."changelogin" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new Login Message")
elseif user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
UseTables(log_in,LogInTable)
if LogInTable[user.sName] then  
LogInTable[user.sName] = message
  SaveTable(log_in,LogInTable)
user:SendPM(BOTName,"Login Changed to: "..message)
end
return 1
end
elseif cmd == prefix.."changelogout" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new Logout Message")
elseif user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
UseTables(log_out,LogOutTable)  
if LogOutTable[user.sName] then  
LogOutTable[user.sName] = message
  SaveTable(log_out,LogOutTable)
user:SendPM(BOTName,"Logout Changed to: "..message)
end
return 1
end
elseif cmd == prefix.."changebot" then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if message == "" then
user:SendPM(BOTName,"Please supply a new BotName")
elseif user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
UseTables(botsfile,UserBotTable)  
if UserBotTable[user.sName] then  
UserBotTable[user.sName] = message
  SaveTable(botsfile,UserBotTable)
user:SendPM(BOTName,"Bot Changed to: "..message)
end
return 1
end
elseif cmd == prefix.."rules" then
user:SendPM(BOTName,rules)
return 1
elseif cmd == prefix.."reghelp" then
user:SendPM(BOTName,reghelp)
return 1
elseif (cmd == prefix.."myip" ) then
user:SendData(BOTName,"Your preciousssss IP issssss: "..user.sIP)
return 1
elseif (cmd == prefix.."mmop" ) then
_,_,cmd,message = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then
SendPmToOps(user.sName, message)
return 1
end
elseif (cmd=="!say") then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
local s,e,cmd,From,Text = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s*(.*)" )
SendToAll(From,Text)
return 1
end
elseif (cmd=="!saypm") then
if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 2 then
local s,e,cmd,From,To,Text = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s+(%S+)%s+(.*)")
SendPmToNick(To,From,Text)
return 1
end
elseif (cmd=="!addnewuser") then
if user.iProfile == 0 or user.iProfile == 1 then
s,e,cmd,uName,uPass,uLevel = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s+(%S+)%s+(.*)")
if uName == "" or uPass== "" or uLevel == "" then
user:SendPM(BOTName,"Please use Correct Format: !addnewuser ")
return 1
elseif uLevel == "Reg" then
AddRegUser(uName,uPass, 3)
elseif uLevel == "VIP" then
AddRegUser(uName,uPass, 2)
elseif uLevel == "Operator" then
AddRegUser(uName,uPass, 1)
elseif uLevel == "Master" then
AddRegUser(uName,uPass, 0)
else
user:SendPM(BOTName,"Please use Correct Format. Use !reghelp for details")
end
AddBlanksToTables(uName,log_in,LogInTable)
AddBlanksToTables(uName,log_out,LogOutTable)
AddBlanksToTables(uName,botsfile,UserBotTable)
user:SendPM(BOTName,"I've Registered "..uName)
return 1
else
SendToAll(BOTName,"Sorry, You cannot use the addnewuser command")
end
end
end    
end