M README.md => README.md +2 -2
@@ 2,7 2,7 @@
Hacked up version of theboxmage's [discord-cli](https://github.com/theboxmage/discordcli)
-JSON config is in `$home/lib//lib/disco.cfg` for setting password, should be made automatically after first run.
+JSON config is in `$home/lib/disco.cfg` for setting password, should be made automatically after first run.
## Install
@@ 27,7 27,7 @@ Commands available in chat:
| Command | Function |
| ------------- |-------------|
-| :q | Quits discord-cli |
+| :q | Quits disco |
| :g | Change listening Guild|
| :c | Change listening Channel inside Guild |
| :m [n] | Display last [n] messages: ex. `:m 2` displays last two messages |
M config.go => config.go +8 -22
@@ 58,44 58,30 @@ func CreateConfig() {
var EmptyStruct Configuration
//Set Default values
- fmt.Println("Input your email")
+ fmt.Print("Input your email: ")
scan := bufio.NewScanner(os.Stdin)
scan.Scan()
EmptyStruct.Username = scan.Text()
- fmt.Println("Input your password")
+ fmt.Print("Input your password: ")
//password, err := terminal.ReadPassword(0)
plan9 := true
/* Plan 9 raw mode for rio */
- consctl, err := os.OpenFile("/dev/consctl", os.O_WRONLY, 0200)
+ err = Rawon()
if err != nil {
- /* not on Plan 9 */
- fmt.Println("Not running on Plan 9")
+ fmt.Println("Failed to set rawon")
plan9 = false
}
password := "";
if plan9 {
- rawon := []byte("rawon")
- _, err = consctl.Write(rawon)
+ password = GetPass()
+
+ err = Rawoff()
if err != nil {
- fmt.Println("Failed to set rawon")
- } else {
- cons, err := os.OpenFile("/dev/cons", os.O_RDWR, 0600)
- if err != nil {
- fmt.Println("Failed to open /dev/cons")
- }
- consScan := bufio.NewScanner(cons)
- consScan.Scan()
- password = consScan.Text()
-
- rawoff := []byte("rawoff")
- _, err = consctl.Write(rawoff)
- if err != nil {
- fmt.Println("Failed to set rawoff")
- }
+ fmt.Println("Failed to set rawoff")
}
} else {
/* Maybe put linux terminal raw mode in here one day */
M helper.go => helper.go +43 -0
@@ 94,3 94,46 @@ func MessagePrint(Time, Username, Content string) {
func dis(a, b int) float64 {
return float64((a - b) * (a - b))
}
+
+func Rawon() {
+ consctl, err := os.OpenFile("/dev/consctl", os.O_WRONLY, 0200)
+ if err != nil {
+ /* not on Plan 9 */
+ fmt.Println("\nNot running on Plan 9")
+ return err
+ }
+
+ rawon := []byte("rawon")
+ _, err = consctl.Write(rawon)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func RawOff() {
+ consctl, err := os.OpenFile("/dev/consctl", os.O_WRONLY, 0200)
+ if err != nil {
+ /* not on Plan 9 */
+ return err
+ }
+
+ rawoff := []byte("rawoff")
+ _, err = consctl.Write(rawoff)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func GetPass() {
+ cons, err := os.OpenFile("/dev/cons", os.O_RDWR, 0600)
+ if err != nil {
+ fmt.Println("Failed to open /dev/cons")
+ }
+ consScan := bufio.NewScanner(cons)
+ consScan.Scan()
+ return consScan.Text()
+}
M main.go => main.go +4 -2
@@ 76,8 76,10 @@ func main() {
line = ParseForMentions(line)
if line != "" {
- /*_ ,err :=*/ State.Session.DiscordGo.ChannelMessageSend(State.Channel.ID, line)
- //fmt.Print("Error: ", err, "\n")
+ _ ,err := State.Session.DiscordGo.ChannelMessageSend(State.Channel.ID, line)
+ if err != nil {
+ fmt.Print("Error: ", err, "\n")
+ }
}
}