2 midgaard_bot, a Telegram bot which sets a bridge to Midgaard Merc MUD
3 Copyright (C) 2017 by Javier Sancho Fernandez <jsf at jsancho dot org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/reiver/go-oi"
26 "github.com/reiver/go-telnet"
29 type TelnetCaller struct {
34 func (caller TelnetCaller) CallTELNET(ctx telnet.Context, writer telnet.Writer, reader telnet.Reader) {
38 var buffer bytes.Buffer
41 crlfBuffer := [2]byte{'\r', '\n'}
45 message := <-caller.Input
46 buffer.Write([]byte(message))
50 oi.LongWrite(writer, p)
55 // Receive text from MUD
56 chunks := make(chan string)
64 n, err := reader.Read(p)
65 if n <= 0 && err == nil {
67 } else if n <= 0 && err != nil {
77 case input := <-chunks:
81 case input := <-chunks:
83 case <-time.After(time.Millisecond * 500):
84 caller.Output <- chunk