opchat invite
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

opchat invite

Started by jiten, 25 August, 2004, 10:11:07

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jiten

i'm looking for a script that invites or removes any user to OpChat.
i got this script from nErBoS but, i don't want two bots, just OpChat. is it possible?
ps: i tried to rename sBot to OpChat but, every op seems to receive the same message twice. can someone fix this?
thanks in advance.

code:

--## OpChat Modificado
--## Feito por nErBoS
--## Comandos para OPs:
--## +invite -- Convida um utilizador para participar no OpChat
--## +delinvite -- Retira o convite de participar no OpChat a um utilizador
--## +invitelist -- Mostra a lista de utilizadores convidados a falar no OpChat
--## +talklog -- Mostra a conversa que houve no OpChat na sua ausencia

sBot = "The Chat"
sOpChat = "OpChat"

arrInvite = {}
arrLog = {}
fInvite = "invite.dat"
fLog = "log.dat"

--## Configura??o ##--

uLaterPtokax = 1 -- 0 se tiveres a usar a vers?o do Ptokax 0.3.3.0 ou superior
-- 1 se tiveres a usar uma vers?o de Ptokax abaixo da 0.3.3.0

arrOpLevel = { --Coloque nesta tabela o nome de "profile" com privilegios de OP e o seu corresponde numero
["Master"] = 0,
["Operator"] = 1,
["Moderator"] = 4,
["NetFounder"] = 5,
}

--## FIM ##--

function Main()
frmHub:RegBot(sOpChat)
frmHub:EnableFullData(1)
LoadFromFile(fInvite)
LoadFromFile(fLog)
Refresh()
end

function OnExit()
SaveToFile(fInvite , arrInvite , "arrInvite")
SaveToFile(fLog , arrLog , "arrLog")
end

function OpConnected(user)
if (arrLog[user.sName] == nil) then
Refresh()
elseif (arrLog[user.sName]["Talk"] ~= "") then
user:SendPM(sBot, "Houve conversa no OpChat na tua aus?ncia. Escreve +talklog para a leres.")
end
arrLog[user.sName]["Mode"] = "online"
end

function OpDisconnected(user)
arrLog[user.sName]["Mode"] = "offline"
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+invite" and user.bOperator) then
InviteUser(user, data)
return 1
elseif (cmd == "+delinvite" and user.bOperator) then
RemoveInvite(user, data)
return 1
elseif (cmd == "+invitelist" and user.bOperator) then
InviteList(user)
return 1
elseif (cmd == "+talklog" and user.bOperator) then
ShowTalkLog(user)
return 1
end
end

if (strsub(data,1,5+strlen(sOpChat)) == "$To: "..sOpChat) then
if (user.bOperator or arrInvite[strlower(user.sName)] ~= nil) then
data = strsub(data,1,strlen(data)-1)
SendTalkToOps(data)
SendTalkToInvited(data)
else
user:SendPM(sBot, "N?o podes falar no OpChat.")
return 1
end
end
end

function InviteUser(user, data)
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (nick == nil) then
user:SendPM(sBot, "Syntax Erro, +invite . Tens de escrever um nick.")
elseif (arrInvite[strlower(nick)] ~= nil) then
user:SendPM(sBot, "O utilizador "..nick.." j? se encontra convidado para falar no OpChat.")
else
arrInvite[strlower(nick)] = user.sName
user:SendPM(sBot, "O utilizador "..nick.." foi convidado a falar no OpChat.")
if (GetItemByName(nick) ~= nil) then
GetItemByName(nick):SendPM(sBot, "Foste convidado para falar no OpChat pelo Operador "..user.sName)
end
SendPmToOps(sBot, "O utilizador "..nick.." foi convidado a falar no OpChat pelo Operador "..user.sName)
if (uLaterPtokax == 1) then
SaveToFile(fInvite , arrInvite , "arrInvite")
end
end
end

function RemoveInvite(user, data)
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (nick == nil) then
user:SendPM(sBot, "Syntax Erro, +delinvite . Tens de escrever um nick.")
elseif (arrInvite[strlower(nick)] == nil) then
user:SendPM(sBot, "O utilizador "..nick.." n?o se encontra convidado para falar no OpChat.")
else
arrInvite[strlower(nick)] = nil
user:SendPM(sBot, "O utilizador "..nick.." j? n?o se encontra convidado a falar no OpChat.")
if (GetItemByName(nick) ~= nil) then
GetItemByName(nick):SendPM(sBot, "O convite para falar no OpChat for removido pelo Operador "..user.sName)
end
SendPmToOps(sBot, "Ao utilizador "..nick.." foi lhe removido o convite para falar no OpChat pelo Operador "..user.sName)
if (uLaterPtokax == 1) then
SaveToFile(fInvite , arrInvite , "arrInvite")
end
end
end

function InviteList(user)
local sTmp,op,usr = "Lista de utilizadores convidados para falar no OpChat:\r\n\r\n"
for usr, op in arrInvite do
sTmp = sTmp.."Utilizador: "..usr.."\tConvidado por: "..op.."\r\n"
end
user:SendPM(sBot, sTmp)
end

function SendTalkToOps(data)
local s,e,from,talk = strfind(data, "$To:%s+%S+%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
local aux,profile,usr
if (from ~= nil and talk ~= nil) then
SaveToLog(from, talk)
for aux, profile in GetProfiles() do
for aux, usr in GetUsersByProfile(profile) do
if (GetItemByName(usr) ~= nil and GetItemByName(usr).bOperator and GetItemByName(usr).sName ~= from) then
SendToNick(GetItemByName(usr).sName, "$To: "..GetItemByName(usr).sName.." From: "..sOpChat.." $<"..from.."> "..talk)
end
end
end
end
end

function SendTalkToInvited(data)
local s,e,from,talk = strfind(data, "$To:%s+%S+%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
local aux,usr
if (from ~= nil and talk ~= nil) then
for usr, aux in arrInvite do
if (GetItemByName(usr) ~= nil and GetItemByName(usr).sName ~= from) then
SendToNick(GetItemByName(usr).sName, "$To: "..GetItemByName(usr).sName.." From: "..sOpChat.." $<"..from.."> "..talk)
end
end
end
end

function Refresh()
local aux,usr,profile
for aux, profile in arrOpLevel do
for aux, usr in GetUsersByProfile(GetProfileName(profile)) do
if (arrLog[usr] == nil) then
arrLog[usr] = {}
if (GetItemByName(usr) == nil) then
arrLog[usr]["Mode"] = "offline"
else
arrLog[usr]["Mode"] = "online"
end
arrLog[usr]["Talk"] = ""
elseif (GetItemByName(usr) == nil) then
arrLog[usr]["Mode"] = "offline"
else
arrLog[usr]["Mode"] = "online"
end
end
end
if (uLaterPtokax == 1) then
SaveToFile(fLog , arrLog , "arrLog")
end
end

function SaveToLog(from, talk)
local usr,aux
for usr, aux in arrLog do
if (arrLog[usr]["Mode"] == "offline") then
arrLog[usr]["Talk"] = arrLog[usr]["Talk"].."<"..from.."> "..talk.."\r\n"
end
end
if (uLaterPtokax == 1) then
SaveToFile(fLog , arrLog , "arrLog")
end
end

function ShowTalkLog(user)
if (arrLog[user.sName]["Talk"] == "") then
user:SendPM(sBot, "N?o existe mais nenhuma conversa no OpChat em que n?o estivesse presente.")
else
user:SendPM(sBot, "Conversa que houve no OpChat na sua ausencia:\r\n\r\n"..arrLog[user.sName]["Talk"])
user:SendPM(sBot, "O log foi limpo.")
arrLog[user.sName]["Talk"] = ""
if (uLaterPtokax == 1) then
SaveToFile(fLog , arrLog , "arrLog")
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

nErBoS

#1
Hi,

Try this then...

--## OpChat Modificado 
--## Feito por nErBoS 
--## Comandos para OPs: 
--## +invite  -- Convida um utilizador para participar no OpChat 
--## +delinvite  -- Retira o convite de participar no OpChat a um utilizador 
--## +invitelist -- Mostra a lista de utilizadores convidados a falar no OpChat 
--## +talklog -- Mostra a conversa que houve no OpChat na sua ausencia 

sOpChat = "OpChat" 

arrInvite = {} 
arrLog = {} 
fInvite = "invite.dat" 
fLog = "log.dat" 

--## Configura??o ##-- 

uLaterPtokax = 1 -- 0 se tiveres a usar a vers?o do Ptokax 0.3.3.0 ou superior 
-- 1 se tiveres a usar uma vers?o de Ptokax abaixo da 0.3.3.0 

arrOpLevel = { --Coloque nesta tabela o nome de "profile" com privilegios de OP e o seu corresponde numero 
["Master"] = 0, 
["Operator"] = 1, 
["Moderator"] = 4, 
["NetFounder"] = 5, 
} 

--## FIM ##-- 

function Main() 
frmHub:RegBot(sOpChat) 
frmHub:EnableFullData(1) 
LoadFromFile(fInvite) 
LoadFromFile(fLog) 
Refresh() 
end 

function OnExit() 
SaveToFile(fInvite , arrInvite , "arrInvite") 
SaveToFile(fLog , arrLog , "arrLog") 
end 

function OpConnected(user) 
if (arrLog[user.sName] == nil) then 
Refresh() 
elseif (arrLog[user.sName]["Talk"] ~= "") then 
user:SendPM(sBot, "Houve conversa no OpChat na tua aus?ncia. Escreve +talklog para a leres.") 
end 
arrLog[user.sName]["Mode"] = "online" 
end 

function OpDisconnected(user) 
arrLog[user.sName]["Mode"] = "offline" 
end 

function DataArrival(user, data) 
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sOpChat)) == "$To: "..sOpChat) then 
data = strsub(data,1,strlen(data)-1) 
s,e,cmd = strfind(data, "%b<>%s+(%S+)") 
if (cmd == "+invite" and user.bOperator) then 
InviteUser(user, data) 
return 1 
elseif (cmd == "+delinvite" and user.bOperator) then 
RemoveInvite(user, data) 
return 1 
elseif (cmd == "+invitelist" and user.bOperator) then 
InviteList(user) 
return 1 
elseif (cmd == "+talklog" and user.bOperator) then 
ShowTalkLog(user) 
return 1 
end 
end 

if (strsub(data,1,5+strlen(sOpChat)) == "$To: "..sOpChat) then 
if (user.bOperator or arrInvite[strlower(user.sName)] ~= nil) then 
SendTalkToOps(data) 
SendTalkToInvited(data) 
return 1
else 
user:SendPM(sBot, "N?o podes falar no OpChat.") 
return 1 
end 
end 
end 

function InviteUser(user, data) 
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)") 
if (nick == nil) then 
user:SendPM(sOpChat, "Syntax Erro, +invite  . Tens de escrever um nick.") 
elseif (arrInvite[strlower(nick)] ~= nil) then 
user:SendPM(sOpChat, "O utilizador "..nick.." j? se encontra convidado para falar no OpChat.") 
else 
arrInvite[strlower(nick)] = user.sName 
user:SendPM(sOpChat, "O utilizador "..nick.." foi convidado a falar no OpChat.") 
if (GetItemByName(nick) ~= nil) then 
GetItemByName(nick):SendPM(sOpChat, "Foste convidado para falar no OpChat pelo Operador "..user.sName) 
end 
SendPmToOps(sOpChat, "O utilizador "..nick.." foi convidado a falar no OpChat pelo Operador "..user.sName) 
if (uLaterPtokax == 1) then 
SaveToFile(fInvite , arrInvite , "arrInvite") 
end 
end 
end 

function RemoveInvite(user, data) 
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)") 
if (nick == nil) then 
user:SendPM(sOpChat, "Syntax Erro, +delinvite  . Tens de escrever um nick.") 
elseif (arrInvite[strlower(nick)] == nil) then 
user:SendPM(sOpChat, "O utilizador "..nick.." n?o se encontra convidado para falar no OpChat.") 
else 
arrInvite[strlower(nick)] = nil 
user:SendPM(sOpChat, "O utilizador "..nick.." j? n?o se encontra convidado a falar no OpChat.") 
if (GetItemByName(nick) ~= nil) then 
GetItemByName(nick):SendPM(sOpChat, "O convite para falar no OpChat for removido pelo Operador "..user.sName) 
end 
SendPmToOps(sOpChat, "Ao utilizador "..nick.." foi lhe removido o convite para falar no OpChat pelo Operador "..user.sName) 
if (uLaterPtokax == 1) then 
SaveToFile(fInvite , arrInvite , "arrInvite") 
end 
end 
end 

function InviteList(user) 
local sTmp,op,usr = "Lista de utilizadores convidados para falar no OpChat:\r\n\r\n" 
for usr, op in arrInvite do 
sTmp = sTmp.."Utilizador: "..usr.."\tConvidado por: "..op.."\r\n" 
end 
user:SendPM(sBot, sTmp) 
end 

function SendTalkToOps(data) 
local s,e,from,talk = strfind(data, "$To:%s+%S+%s+From:%s+(%S+)%s+$%b<>%s+(.+)") 
local aux,profile,usr 
if (from ~= nil and talk ~= nil) then 
SaveToLog(from, talk) 
for aux, profile in GetProfiles() do 
for aux, usr in GetUsersByProfile(profile) do 
if (GetItemByName(usr) ~= nil and GetItemByName(usr).bOperator and GetItemByName(usr).sName ~= from) then 
SendToNick(GetItemByName(usr).sName, "$To: "..GetItemByName(usr).sName.." From: "..sOpChat.." $<"..from.."> "..talk) 
end 
end 
end 
end 
end 

function SendTalkToInvited(data) 
local s,e,from,talk = strfind(data, "$To:%s+%S+%s+From:%s+(%S+)%s+$%b<>%s+(.+)") 
local aux,usr 
if (from ~= nil and talk ~= nil) then 
for usr, aux in arrInvite do 
if (GetItemByName(usr) ~= nil and GetItemByName(usr).sName ~= from) then 
SendToNick(GetItemByName(usr).sName, "$To: "..GetItemByName(usr).sName.." From: "..sOpChat.." $<"..from.."> "..talk) 
end 
end 
end 
end 

function Refresh() 
local aux,aux2,usr,profile 
for profile, aux in arrOpLevel do 
for aux2, usr in GetUsersByProfile(profile) do 
if (arrLog[usr] == nil) then 
arrLog[usr] = {} 
if (GetItemByName(usr) == nil) then 
arrLog[usr]["Mode"] = "offline" 
else 
arrLog[usr]["Mode"] = "online" 
end 
arrLog[usr]["Talk"] = "" 
elseif (GetItemByName(usr) == nil) then 
arrLog[usr]["Mode"] = "offline" 
else 
arrLog[usr]["Mode"] = "online" 
end 
end 
end 
if (uLaterPtokax == 1) then 
SaveToFile(fLog , arrLog , "arrLog") 
end 
end 

function SaveToLog(from, talk) 
local usr,aux 
for usr, aux in arrLog do 
if (arrLog[usr]["Mode"] == "offline") then 
arrLog[usr]["Talk"] = arrLog[usr]["Talk"].."<"..from.."> "..talk.."\r\n" 
end 
end 
if (uLaterPtokax == 1) then 
SaveToFile(fLog , arrLog , "arrLog") 
end 
end 

function ShowTalkLog(user) 
if (arrLog[user.sName]["Talk"] == "") then 
user:SendPM(sOpChat, "N?o existe mais nenhuma conversa no OpChat em que n?o estivesse presente.") 
else 
user:SendPM(sOpChat, "Conversa que houve no OpChat na sua ausencia:\r\n\r\n"..arrLog[user.sName]["Talk"]) 
user:SendPM(sOpChat, "O log foi limpo.") 
arrLog[user.sName]["Talk"] = "" 
if (uLaterPtokax == 1) then 
SaveToFile(fLog , arrLog , "arrLog") 
end 
end 
end 

function Serialize(tTable, sTableName, sTab) 
assert(tTable, "tTable equals nil"); 
assert(sTableName, "sTableName equals nil"); 
assert(type(tTable) == "table", "tTable must be a table!"); 
assert(type(sTableName) == "string", "sTableName must be a string!"); 
sTab = sTab or ""; 
sTmp = "" 
sTmp = sTmp..sTab..sTableName.." = {\n" 
for key, value in tTable do 
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key); 
if(type(value) == "table") then 
sTmp = sTmp..Serialize(value, sKey, sTab.."\t"); 
else 
local sValue = (type(value) == "string") and format("%q",value) or tostring(value); 
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue 
end 
sTmp = sTmp..",\n" 
end 
sTmp = sTmp..sTab.."}" 
return sTmp 
end 

function SaveToFile(file , table , tablename) 
writeto(file) 
write(Serialize(table, tablename)) 
writeto() 
end 

function LoadFromFile(file) 
if (readfrom(file) ~= nil) then 
readfrom(file) 
dostring(read("*all")) 
readfrom() 
end 
end

Best regards, nErBoS
--## nErBoS Spot ##--

jiten

hi there nErBoS.
i tried the modified OpChat but, it didn't work. It had an error (strlen...). Then, I modified sBot to sOpChat and it worked just like the first script: the ops receive the messages send to opchat twice.
Can you check it again?
Thanks in advance.

nErBoS

Hi,

I have edited the script above try out.

Best regards, nErBoS
--## nErBoS Spot ##--

jiten

hi there.
well, i tested the script again and the following things happened:
- the OpChat works perfectly with the invited user;
- the operators who write something to OpChat, their message is sent twice to everyone else.
best regards,

jiten

nErBoS

Hi,

Forgot a return 1. I have edited the script above.

Best regards, nErBoS
--## nErBoS Spot ##--

jiten

thanks nErBoS! now it's working 100%.

SMF spam blocked by CleanTalk