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
if update.Message.IsCommand() { | |
var args []string | |
switch update.Message.Command() { | |
case "suma": // Comprobar comando suma | |
args = normalizaCadena(update.Message.CommandArguments()) | |
case "resta": // Comprobar comando resta | |
args = normalizaCadena(update.Message.CommandArguments()) | |
case "mult": // Comprobar comando multiplicación |
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
func validaArgumentosInt(args []string) (int, int, error) { | |
var a, b int | |
if len(args) == 2 { | |
a, err := strconv.Atoi(args[0]) | |
if err != nil { | |
return a, b, err | |
} | |
b, err := strconv.Atoi(args[1]) | |
if err != nil { | |
return a, b, err |
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
package main | |
import ( | |
"fmt" | |
"log" | |
"regexp" | |
"strconv" | |
"strings" | |
"gopkg.in/telegram-bot-api.v4" |
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
if esComandoValido(update.Message.Command()) { | |
if cmd, ok := esComandoCalc(update.Message.Command()); ok { | |
// Realizar operaciones de la calculadora | |
} else if esComandoInicio(update.Message.Command()) { | |
// Mostrar mensaje de inicio | |
} | |
} |
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
var txt string | |
args = normalizaCadena(update.Message.CommandArguments()) | |
a, b, err = validaArgumentosInt(args) | |
if err != nil { | |
af, bf, err = validaArgumentosFloat(args) | |
if err != nil { | |
txt = "Los operandos proporcionados no son validos" | |
enviarMensaje(bot, update.Message.Chat.ID, update.Message.MessageID, txt) | |
break | |
} |
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
if decimal { | |
switch cmd { | |
case "suma": | |
txt = fmt.Sprintf("%f", af+bf) | |
case "resta": | |
txt = fmt.Sprintf("%f", af-bf) | |
case "multi": | |
txt = fmt.Sprintf("%f", af*bf) | |
case "div": | |
if bf == 0 { |
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
package main | |
import ( | |
"fmt" | |
"log" | |
"regexp" | |
"strconv" | |
"strings" | |
"gopkg.in/telegram-bot-api.v4" |
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
$ brew install dep | |
$ brew upgrade dep |
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
$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |
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
pacman -S dep |