Jump to content

Chat Bot


Recommended Posts

Posted

I want to make a Chat Bot for Jedi Knight Academy.

 

Basically the bot reads the chat of the server, then if a user types in chat a '!', followed by a command, the bot responds accordingly. 

 

For example if a user was to type '!Weather', the bot would respond in chat by printing out the weather.

 

The problem is I have no real idea on how to approach this. I've never done something like this before, but it sounds like a fun thing to try to do. I've only been programming for about 9 months so I'm not sure if this project is out of my bounds or not. Any advice?

 

I know such bots have been made in the past I can't find any information on them. The closest I could get was finding this: http://jediknight3.filefront.com/file/JK3_Chat_Scan;23795

 

I'd like to do this in C# if possible.

Link likes this
Posted

You can either look through the code to find out about the communication protocol or capture the packets sent when you join a server as a spectator and chat. In general you'll mostly need to send and receive UDP packets, googling for "Quake 3 network protocol" yields some potentially useful results.

Posted
 

You can either look through the code to find out about the communication protocol or capture the packets sent when you join a server as a spectator and chat. In general you'll mostly need to send and receive UDP packets, googling for "Quake 3 network protocol" yields some potentially useful results.

 

Is that how tools like Ultra Utility do it?

Basically there are two methods I am thinking of,

 

1: Have a bot actually join the server as a client, then join spectator and wait for commands.

2: Skip the bot and just make the client(me in this case) respond to the commands automatically. Not really a bot per say, just parsing input and responding. 

 

Either way would do fine for me.

 

I'll start looking around at the Quake 3 network protocol. 

Posted

It can be done in the JA++ client with Lua, or by modifying the source code if you're more familiar with C.

More info please? Particularly on the JA++ with LUA part?

Posted

Put this in japlus/lua/cl/chatbot/plugin.lua

 

local chatbot = RegisterPlugin( "ChatBot", "1.0" )

local function SplitChatMessage( msg )
	local splitMsg = JPUtil.explode( string.format( "%c", 0x19 ), msg )
	local len = #splitMsg

	if len == 2 then -- for regular messages, only one escape character
		local name = string.sub( splitMsg[1], 1, string.len(splitMsg[1])-2 ) -- strip the ^7 at the end
		local message = string.sub( splitMsg[2], 3 ) -- strip the ': ' before each message
		return name, message
	elseif len == 4 then -- for JA+ admin messages...
		local name = string.sub( splitMsg[2], 2, string.len(splitMsg[2])-2 ) -- strip the '(' at the start and ^7 at the end
		local message = string.sub( splitMsg[4], 4 ) -- strip the ': ^3' at the start
		return name, message
	end
end

AddListener( "JPLUA_EVENT_CHATMSGRECV", function( msg )
	local sender, message = SplitChatMessage( msg )
	local ply = GetPlayer( sender )
	if ply and ply:IsBot() then
		-- ... do something with 'message'
		local reply = 'some response'
		SendServerCommand( 'say ' .. reply )
	end
	return msg
end )
and go from there =]
Posted

Put this in japlus/lua/cl/chatbox/plugin.lua

 

local chatbot = RegisterPlugin( "ChatBot", "1.0" )

local function SplitChatMessage( msg )
	local splitMsg = JPUtil.explode( string.format( "%c", 0x19 ), msg )
	local len = #splitMsg

	if len == 2 then -- for regular messages, only one escape character
		local name = string.sub( splitMsg[1], 1, string.len(splitMsg[1])-2 ) -- strip the ^7 at the end
		local message = string.sub( splitMsg[2], 3 ) -- strip the ': ' before each message
		return name, message
	elseif len == 4 then -- for JA+ admin messages...
		local name = string.sub( splitMsg[2], 2, string.len(splitMsg[2])-2 ) -- strip the '(' at the start and ^7 at the end
		local message = string.sub( splitMsg[4], 4 ) -- strip the ': ^3' at the start
		return name, message
	end
end

AddListener( "JPLUA_EVENT_CHATMSGRECV", function( msg )
	local sender, message = SplitChatMessage( msg )
	local ply = GetPlayer( sender )
	if ply and ply:IsBot() then
		-- ... do something with 'message'
		local reply = 'some response'
		SendServerCommand( 'say ' .. reply )
	end
	return msg
end )
and go from there =]

 

 

Thank you!

I'm not too familiar with LUA but I'll go brush up and start on this.

Raz0r likes this
Posted

You can look at existing plugins here or the source code here.

There used to be some basic documentation but most of it is irrelevant now or missing.

 

Mmm that's unfortunate.

Someone should make one!

Posted

Alright so I managed to get it working.

 

Now it responds whenever someone types in the chat !test.

 

But the problem now is that only other people can do it. If I do it, the message doesn't show up because it tries to send it IMMEDIATELY AFTER I send !test. Antispam blocks it.

 

Been trying for the past hour to find a way to pause the script after it receives the trigger, but to no avail. 

 

I do have a way to pause it, but it pauses the ENTIRE CLIENT each time someone uses the bot.

 

Any advice? 

Posted

Store the last-message-recieved-time in a global variable.

Every frame (i.e. JPLUA_EVENT_FRAME or whatever it is) check if the current time is ~2s after the last received time (and the last received time is not 0), and if so, send the message

then set the last received time to 0 so it won't keep trying to resend.

Posted

Store the last-message-recieved-time in a global variable.

Every frame (i.e. JPLUA_EVENT_FRAME or whatever it is) check if the current time is ~2s after the last received time (and the last received time is not 0), and if so, send the message

then set the last received time to 0 so it won't keep trying to resend.

 

So that sounds easy enough, but I'm not exactly sure about how to do this:

 

Store the last-message-recieved-time in a global variable.

 

How do I find the last message received time?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...