is there a simple way of adding chat if people pm or say the bots name.
like "yeh im a bot this is all I say."
I want to beable to add it to all my custom bots
hope there is a simple way, like just pasting some code into each script.
Jase
Hi,
Not understanding right your request. You want to a user by addded to the Chat-Script by saying is name in the chat or in pm ???
Best regards, nErBoS
Yes.
oldDataArrival = DataArrival;
sBotName = "something";
-- if you use special characters (. % etc)
-- this will probably not work properly
function DataArrival(curUser, sData)
-- check to see if the BotsName is in the message
-- if( strfind(sData, sBotName) ) then
-- this one is a little more specific, avoid BotName within
-- other user names and include only PMs & Chat
if( strfind(sData, "^%b<>.*%s"..sBotName.."%s") or
strfind(sData, "^%$To: "..sBotName.." ") ) then
-- Do whatever
end
if( oldDataArrival ~= nil ) then
oldDataArrival(curUser, sData);
end
end
This code is far from complete. It is simply proof of concept that you can add this to the end of every bot to be generic.
-NotRabidWombat
Hi,
With few sleep on and not tested...
--Requested by jsjen
--Made by nErBoS
sBot = "ChatBot"
chatters = {}
chatsv = "chaters.txt"
function Main()
frmHub:RegBot(sBot)
end
function OnExit()
Refresh()
SaveToFile(chatsv , chatters , "chatters")
end
function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
data = strlower(data)
botname = strlower(sBot)
Refresh()
if (strfind(data, botname)) then
if (CheckUser(user) == 0) then
AddUser(user)
user:SendPM(sBot, "You can now talk in the chat "..sBot)
end
end
end
if (strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
Refresh()
if (CheckUser(user) == 0) then
AddUser(user)
user:SendPM(sBot, "You can now talk in the chat "..sBot)
return 1
else
data = strsub(data,1,strlen(data)-1)
local s,e,talker,talk = strfind(data, "<(%S+)>%s+(.*)")
for i=1, getn(chatters) do
if (GetItemByName(chatters[i]) ~= nil and chatters[i] ~= strlower(user.sName)) then
SendToNick(GetItemByName(chatters[i]).sName, "$To: "..GetItemByName(chatters[i]).sName.." From: "..sBot.." $<"..user.sName.."> "..talk)
end
end
end
end
end
function Refresh()
if (chatters[1] == nil and readfrom(chatsv) ~= nil) then
LoadFromFile(chatsv)
end
end
function AddUser(user)
local accept = 0
local pos = 0
for i=1, getn(chatters) do
if (chatters[i] == strlower(user.sName)) then
accept = 1
end
pos = i
end
if (accept == 0) then
chatters[pos+1] = strlower(user.sName)
end
end
function CheckUser(user)
local accept = 0
for i=1, getn(chatters) do
if (chatters[i] == strlower(user.sName)) then
accept = 1
end
end
return accept
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
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