aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
blob: 64a5120f0c1b884c85832316dd3c26ff13f29340 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package telegram

const notEnoughArguments string = "Not enough arguments"
const telegramNotInitialized string = "Telegram connection is not initialized yet"

// ProcessTransportCommand executes commands sent directly to the component
func (c *Client) ProcessTransportCommand(cmd string, args []string) string {
	switch cmd {
	case "login", "code", "password":
		if cmd == "login" && c.Session.Login != "" {
			return ""
		}

		if len(args) < 1 {
			return notEnoughArguments
		}
		if c.authorizer == nil {
			return telegramNotInitialized
		}

		switch cmd {
		case "login":
			c.authorizer.PhoneNumber <- args[0]
			c.Session.Login = args[0]
		case "code":
			c.authorizer.Code <- args[0]
		case "password":
			c.authorizer.Password <- args[0]
		}
	}

	return ""
}