]> git.jsancho.org Git - blog.git/commitdiff
Midgaard Bot post
authorJavier Sancho <jsf@jsancho.org>
Tue, 9 Jan 2018 16:34:33 +0000 (17:34 +0100)
committerJavier Sancho <jsf@jsancho.org>
Tue, 9 Jan 2018 16:34:33 +0000 (17:34 +0100)
posts/20171227-midgaard_bot.html

index 8307d2e0d1531c4cb0a0206d2dfae84d187e1fc9..116dcb06098bd38a3b1ee23eb7d79c9db1b68bf3 100644 (file)
@@ -8,19 +8,19 @@ date: 2017-12-27 11:51
 
   <p>The <a href="https://git.jsancho.org/?p=midgaard_bot.git;a=summary">source code of midgaard_bot</a> is available under GPLv3 license.</p>
 
-  <p>Cuando el bot arranca, lanza una gorrutina que se queda escuchando los mensajes que le llegan desde Telegram. Cuando llega un mensaje comprueba si tiene una sesión abierta para el chat desde el que llega el mensaje. Lo normal es que cuando se trate del primer mensaje del chat no tenga sesión.</p>
+  <p>When the bot starts, it launchs a new goroutine that listens messages that arrive from Telegram. When a message arrives, it checks if there is an open session for the chat owner of the message. If it's the first message from that chat, propably there won't be an open session.</p>
 
-  <p>En el caso de no tener sesión, el bot lanza una nueva gorrutina para conectar por telnet al MUD y servir de conector entre Telegram y el juego.</p>
+  <p>In that case, the bot launchs a new goroutine for connecting with the MUD by telnet and serving as a connector between Telegram and the game.</p>
 
-  <p>Para controlar en qué momento la conexión telnet ha acabado de mandar un mensaje completo, y por lo tanto poder mandarlo a Telegram para que lo reciba el jugador, tuve que implementar un buffer que recogiera los datos que iban llegando desde el MUD y usar un timeout de 500 milisegundos, tras el cual se entiende que el mensaje está completo y se puede mandar. No es ninguna maravilla pero para conexiones locales funciona bien.</p>
+  <p>For checking in which time the telnet connection has finished sending a complete message, and then send it to Telegram, I had to implement a buffer to receive data from the MUD and use a 500 milliseconds timeout. After the timeout, in theory the message is complete so it can be sent. I know it isn't a magical solution, but for local connections it runs so well.</p>
 
-  <p>Cuando ya tenemos el mensaje completo lo mandamos a una gorrutina específica que se encarga de recibir mensajes desde las sesiones abiertas y los reenvía a Telegram.</p>
+  <p>When the message is complete, we send it to a specific goroutine that receives messages from open sessions and forwards them to Telegram.</p>
 
-  <p>Durante el desarrollo me ocurrió una cosa graciosa que me tuvo en jaque un buen rato y que te hace pensar en cómo funcionan en realidad las gorrutinas. La gorrutina que controla la sesión escribía un mensaje en un canal y se quedaba colgada. El problema estaba que aún no había implementado la otra parte del programa que leía de ese canal y los canales de Go son bloqueantes.</p>
+  <p>During the development, a funny thing happened to me, and that makes me think about how goroutines really work. The goroutine in charge of an open session wrote a message to a channel and, after that, it got suspended. The problem was taht I didn't develop the code to read that channel yet, and Go channels block the execution.</p>
 
-  <p>Al pensar en los canales yo tenía una idea de ellos similar a los mensajes de Erlang, que tienes un proceso que manda mensajes de forma asíncrona y y la ejecución sigue de forma independiente. Pero en Golang no es así, los canales no son "tuberías", son puntos de unión entre gorrutinas. Si escribes un mensaje en un canal, te quedas bloqueado hasta que otra gorrutina lee ese canal y libera a la gorrutina que ha escrito ese mensaje.</p>
+  <p>I thought Go channels run in a similar way than messages work in Erlang. In Erlang, a process send messages asynchronously, and the execution continues independently. But in Golang is different, channels aren't pipes, are meeting points for goroutines. If you put a message in a channel, you are blocked until another goroutine reads that channel and releases the goroutine that has written that message.</p>
 
-  <p>Cosas curiosas que tiene la concurrencia usando estos mecanismos.</p>
+  <p>Curious things that concurrency has when you use these tools.</p>
 
-  <p>Midgaard Bot está sin acabar y no creo que continue con su desarrollo, ya que mi objetivo era ver si podía conectar con el MUD a través de Telegram y eso ya está conseguido. Pero si alguien quiere seguir, en el repositorio están todas las bases para hacerlo crecer.</p>
+  <p>Midgaard Bot is unfinished and I'm not interested in continue with the development, my goal was to check if I could connect with the MUD using Telegram, and that is already achieved. But if someone wants to continue, you have everything necessary in the repo.</p>
 </div>