teeworlds_network/examples/01_chat_logger.rb
ChillerDragon fe3e581f86 Make client callbacks arrays
Allows to setup multiple on_* hook blocks as a lib user

closed #10
2022-11-14 10:25:28 +01:00

32 lines
683 B
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
# Print all incoming chat messages to stdout
require_relative '../lib/teeworlds_client'
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|
puts "[chat] #{msg}"
end
# properly disconnect on ctrl+c
Signal.trap('INT') do
client.disconnect
end
# connect to localhost and block the current thread
client.connect('localhost', 8303, detach: false)