want bots to reply to chat or pm
 

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

want bots to reply to chat or pm

Started by jsjen, 26 April, 2004, 14:32:31

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jsjen

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


nErBoS

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
--## nErBoS Spot ##--

NotRabidWombat

#2
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


I like childish behavior. Maybe this post will be deleted next.

nErBoS

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
--## nErBoS Spot ##--

SMF spam blocked by CleanTalk