]> git.jsancho.org Git - midgaard_bot.git/blob - midgaard_bot.go
ce92e73df009718e755192226d283ed5cc3d5bb0
[midgaard_bot.git] / midgaard_bot.go
1 /*
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>
4
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.
9
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.
14
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/>.
17 */
18
19 package main
20
21 import (
22         "context"
23         "log"
24         "os"
25         "os/signal"
26
27         "github.com/jessevdk/go-flags"
28 )
29
30 type TelegramConfig struct {
31         Token string `short:"t" long:"token" description:"Telegram API Token" required:"true"`
32 }
33
34 type MercConfig struct {
35         Host string `short:"h" long:"host" description:"Host and port for Merc MUD" required:"true"`
36 }
37
38 var Config struct {
39         Telegram TelegramConfig `group:"Telegram config"`
40         Merc MercConfig `group:"Merc MUD config"`
41 }
42
43 func main() {
44         _, err := flags.Parse(&Config)
45         if err != nil {
46                 log.Panic(err)
47         }
48
49         ctx, cancel := context.WithCancel(context.Background())
50         defer cancel()
51
52         err = initSessions(ctx)
53         if err != nil {
54                 log.Panic(err)
55         }
56
57         err = initTelegramWorkers(Config.Telegram.Token, ctx)
58         if err != nil {
59                 log.Panic(err)
60         }
61
62         intChannel := make(chan os.Signal, 1)
63         signal.Notify(intChannel, os.Interrupt)
64         <-intChannel
65
66         log.Print("Exit")
67 }