Skip to content

Instantly share code, notes, and snippets.

@arshamalh
Last active November 2, 2022 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arshamalh/819afbbe6fb2d31a8040096eb71f5de3 to your computer and use it in GitHub Desktop.
Save arshamalh/819afbbe6fb2d31a8040096eb71f5de3 to your computer and use it in GitHub Desktop.
Go simple interactive shell
package main
import (
"fmt"
"time"
)
const (
msg_welcome string = `
Welcome to Dockeroller!
Enter your desired number:
1 - help
2 - gates
Feel free to enter 0 to get back to the main menu.
`
msg_help = `
Dockeroller is an open-source project made for fun
But it appreas that it has many real-world use-cases and it is a part of ChatOps world!
You can find more information on it's github page!
WE WON'T STORE ANY OF YOUR DATA,
It's an open-source project that you can check, make sure and build it yourself.
As long as I know, this project is safe, but use it on your own risk.
This shell should remain open as long as you want this app to be working.
`
msg_gates = `
Here are the avaiable gates:
1 - Telegram off
2 - API off
You can turn them on by entering their number. (or 0 for main menu)
`
msg_telegram = `
You should activate telegram by making a bot and enter its token here.
Also, you should provide your telegram username,
Additional security layers are not needed as long as you keep your telegram account safe,
By the way, we're working on password mechanism.
`
msg_api = `
You should activate API by defining a superadmin password and a port
`
)
func main() {
var stage int = 0
for {
switch stage {
case 0:
stage = StageWelcome()
case 1:
stage = StageHelp()
case 2:
stage = StageGates()
case 11:
stage = StageTelegram()
case 12:
stage = StageAPI()
}
}
}
func StageWelcome() int {
fmt.Print(msg_welcome)
return getStage()
}
func StageHelp() int {
fmt.Print(msg_help)
return getStage()
}
func StageGates() int {
fmt.Print(msg_gates)
if stage := getStage(); stage != 0 {
return stage + 10
}
return 0
}
func StageTelegram() int {
fmt.Print(msg_telegram)
var token string
getInput("Token: ", &token)
var username string
getInput("Username: @", &username)
fmt.Println("Username and token successfully sat!")
time.Sleep(time.Second * 3)
return 0
}
func StageAPI() int {
fmt.Print(msg_api)
var port int
getInput("Port: ", &port)
var password string
getInput("Password: ", &password)
fmt.Println("Port and password successfully sat!")
time.Sleep(time.Second * 3)
return 0
}
func getStage() (stage int) {
fmt.Print("> ")
fmt.Scanln(&stage)
return
}
func getInput(print string, value interface{}) {
fmt.Print(print)
fmt.Scanln(value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment