-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Telegram remote control and monitoring integrated
- Loading branch information
Showing
8 changed files
with
123 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
{ | ||
"WaitSeconds": 1800, | ||
"StartupCheck" : true, | ||
"Log" : true, | ||
"Log" : true, | ||
"TgBotActivate" : false, | ||
"TgAPIKey" : "API-KEY", | ||
"TgAdminUserName" : "USERNAME", | ||
"Miners": [ | ||
{ "Name": "machine 1", "Pin": "40", "Ip": "192.168.0.100", "Info": "R9 290's" }, | ||
{ "Name": "machine 2", "Pin": "38", "Ip": "192.168.0.101", "Info": "RX480's" }, | ||
{ "Name": "machine 3", "Pin": "37", "Ip": "192.168.0.102", "Info": "RX480's" }, | ||
{ "Name": "machine 4", "Pin": "36", "Ip": "192.168.0.103", "Info": "RX480's" }, | ||
{ "Name": "machine 5", "Pin": "35", "Ip": "192.168.0.104", "Info": "RX480's" }, | ||
{ "Name": "machine 6", "Pin": "33", "Ip": "192.168.0.105", "Info": "RX480's" }, | ||
{ "Name": "machine 7", "Pin": "32", "Ip": "192.168.0.106", "Info": "RX480's" }, | ||
{ "Name": "machine 8", "Pin": "31", "Ip": "192.168.0.107", "Info": "RX480's" }, | ||
{ "Name": "machine 9", "Pin": "29", "Ip": "192.168.0.108", "Info": "RX480's" }, | ||
{ "Name": "machine 10", "Pin": "22", "Ip": "192.168.0.109", "Info": "RX480's" }, | ||
{ "Name": "machine 11", "Pin": "18", "Ip": "192.168.0.110", "Info": "RX480's" }, | ||
{ "Name": "machine 12", "Pin": "16", "Ip": "192.168.0.111", "Info": "RX480's" } | ||
{ "Name": "machine 0", "Pin": "40", "Ip": "192.168.0.100", "Info": "R9 290's" }, | ||
{ "Name": "machine 1", "Pin": "38", "Ip": "192.168.0.101", "Info": "RX480's" }, | ||
{ "Name": "machine 2", "Pin": "37", "Ip": "192.168.0.102", "Info": "RX480's" }, | ||
{ "Name": "machine 3", "Pin": "36", "Ip": "192.168.0.103", "Info": "RX480's" }, | ||
{ "Name": "machine 4", "Pin": "35", "Ip": "192.168.0.104", "Info": "RX480's" }, | ||
{ "Name": "machine 5", "Pin": "33", "Ip": "192.168.0.105", "Info": "RX480's" }, | ||
{ "Name": "machine 6", "Pin": "32", "Ip": "192.168.0.106", "Info": "RX480's" }, | ||
{ "Name": "machine 7", "Pin": "31", "Ip": "192.168.0.107", "Info": "RX480's" }, | ||
{ "Name": "machine 8", "Pin": "29", "Ip": "192.168.0.108", "Info": "RX480's" }, | ||
{ "Name": "machine 9", "Pin": "22", "Ip": "192.168.0.109", "Info": "RX480's" }, | ||
{ "Name": "machine 10", "Pin": "18", "Ip": "192.168.0.110", "Info": "RX480's" }, | ||
{ "Name": "machine 11", "Pin": "16", "Ip": "192.168.0.111", "Info": "RX480's" } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import "time" | ||
import "github.com/go-telegram-bot-api/telegram-bot-api" | ||
import "strconv" | ||
import "fmt" | ||
|
||
func TelegramBot(rigs []Rig) { | ||
machines := rigs | ||
bot, err := tgbotapi.NewBotAPI(Config.TgAPIKey) | ||
if err != nil { | ||
log.Fatal("Problem with the API key. Fix the problem or disable the TelegramBot from the config file") | ||
} | ||
|
||
bot.Debug = false | ||
|
||
log.Noticef("TelegramBot Authorteleized on account %s", bot.Self.UserName) | ||
|
||
u := tgbotapi.NewUpdate(0) | ||
u.Timeout = 60 | ||
|
||
updates, err := bot.GetUpdatesChan(u) | ||
time.Sleep(time.Millisecond * 500) | ||
updates.Clear() | ||
|
||
for update := range updates { | ||
if update.Message == nil { | ||
continue | ||
} | ||
log.Noticef("[%s] %s", update.Message.From.UserName, update.Message.Text) | ||
if update.Message.IsCommand() { | ||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "") | ||
commandArgs := update.Message.CommandArguments() | ||
|
||
if update.Message.From.UserName != Config.TgAdminUserName { | ||
msg.Text = "You are not my master" | ||
} else { | ||
args, err := strconv.ParseInt(commandArgs, 10, 32) | ||
if err != nil { | ||
log.Error(err) | ||
} | ||
|
||
switch update.Message.Command() { | ||
case "help": | ||
msg.Text = "there is no help for the people here\nbut you can try /status /miners /turnon /turnoff /restart /ping" | ||
|
||
case "status": | ||
msg.Text = "I'm fine. Thanks for asking" | ||
|
||
case "miners": | ||
msg.Text = printConf() | ||
|
||
case "ping": | ||
msg.Text = fmt.Sprintf("Machine online status: %t", machines[args].Ping()) | ||
|
||
case "restart": | ||
machines[args].Restarter() | ||
msg.Text = fmt.Sprintf("Machine %d was restarted", args) | ||
|
||
case "turnon": | ||
machines[args].TurnOn() | ||
msg.Text = fmt.Sprintf("Machine %d started", args) | ||
|
||
case "turnoff": | ||
machines[args].ForceShutDown() | ||
msg.Text = fmt.Sprintf("Machine %d was turnedoff", args) | ||
|
||
default: | ||
msg.Text = "I don't know that command, try /help" | ||
} | ||
} | ||
|
||
bot.Send(msg) | ||
} | ||
} | ||
} | ||
|
||
//return string with raw data from config file | ||
func printConf() string { | ||
return fmt.Sprintf("Config:\n%+v", Config) | ||
} |