Author Topic: Letting ops ammend their own welcomes  (Read 13629 times)

0 Members and 1 Guest are viewing this topic.

Offline Stravides

  • Triple Ace
  • **
  • Posts: 171
  • Karma: +0/-0
(No subject)
« Reply #50 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)

???

Code: [Select]
--------- 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 ---------
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

PtokaX forum

(No subject)
« Reply #50 on: 30 January, 2004, 00:49:29 »

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #51 on: 30 January, 2004, 04:01:48 »
Quote
Originally 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.
Code: [Select]
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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Stravides

  • Triple Ace
  • **
  • Posts: 171
  • Karma: +0/-0
(No subject)
« Reply #52 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.



Code: [Select]
--------------------------------------------------------------------------------------------------
-- --
-- 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
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

PtokaX forum

(No subject)
« Reply #52 on: 30 January, 2004, 10:53:28 »