Code Monkey home page Code Monkey logo

midgaard_bot's Introduction

midgaard_bot

tl;dr;

midgaard_bot is a telegram bot designed to connect to the Midgaard MUD (but it can be used to connect to other MUDs or telnet servers).

Midgaard Bot, conneting to a MUD with Telegram

A full description regarding the creation of this bot can be read here.

The original author "had the idea of writing a bot to connect to a MUD (Multi User Dungeon) using Telegram". He "decided to use Golang to practice a little with this language and its goroutines".

This bot is available under a GPLv3 License.

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.

In that case, the bot launches a new goroutine for connecting with the MUD by telnet and serving as a connector between Telegram and the server.

For checking in which time the telnet connection has finished sending a complete message, and then send it to Telegram, a buffer was implemented 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: it isn't a magical solution, but for local connections it works well.

When the message is complete, we send it to a specific goroutine that receives messages from open sessions and forwards them to Telegram.

The original author created this bot as a PoC, but further development has been happening by the community.

midgaard_bot's People

Contributors

happytetrahedron avatar jsancho-gpl avatar marado avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

marado

midgaard_bot's Issues

break down long messages

Sometimes, the reply MUD reply to a command is too long, and the telegram user won't ever see it, since the bot gets a sendMessage resp: {"ok":false,"error_code":400,"description":"Bad Request: message is too long"}.

It seems that Telegram has a maximum message length of 4096 characters, so we should check the message size before sending it, and, if it is longer than 4096 characters, split it (in two or more). The split should happen on newlines (if they exist).

concurrency fail

Some more tests will need to be done, but it seems that the current model of sender and receiver workers doesn't work as expected when much activity is happening on both fronts: if you try to send a message while still in the process of receiving one, your message might end up not being sent at all. A first glance makes me wonder if a tgbotapi object is ready to be used concurrently at all.

Bad Request: strings must be encoded in UTF-8

Sometimes there are weird encodings coming from a MUD, resulting in a (silent) "Bad Request: strings must be encoded in UTF-8" failure instead of a message being delivered to the bot user(s).

We should force UTF-8 encoding on every string prior to send it.

strip ANSI codes

MUD connections will often send you data full of ANSI codes (for instance, to color the text). Since telegram won't be able to interpret those, we should strip them off from the data read from the MUD.

Send monospaced messages

MUDs often have ASCII art of some sort (maps, for eg.). It would be useful to send the text entirely monospaced.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.