teeworlds_network/examples/01_chat_logger.rb

32 lines
683 B
Ruby
Raw Normal View History

2022-11-05 10:07:16 +00:00
#!/usr/bin/env ruby
2022-11-05 16:27:54 +00:00
# frozen_string_literal: true
2022-11-05 10:07:16 +00:00
2022-11-04 15:57:50 +00:00
# Print all incoming chat messages to stdout
require_relative '../lib/teeworlds_client'
2022-11-04 15:57:50 +00:00
client = TeeworldsClient.new(verbose: false)
# print all incoming chat messages
# the variable `msg` holds an instance of the class `ChatMessage` which has the following fields
#
# msg.mode
# msg.client_id
# msg.target_id
# msg.message
# msg.author.id
# msg.author.team
# msg.author.name
# msg.author.clan
client.on_chat do |_, msg|
2022-11-04 15:57:50 +00:00
puts "[chat] #{msg}"
end
# properly disconnect on ctrl+c
Signal.trap('INT') do
client.disconnect
end
# connect to localhost and block the current thread
2022-11-05 10:07:16 +00:00
client.connect('localhost', 8303, detach: false)