86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"surdeus.su/core/tg"
|
|
"os"
|
|
)
|
|
|
|
var UsageAction = tg.Func(func(c tg.Context) {
|
|
c.Sendf(
|
|
"There is no such command %q",
|
|
c.CallbackUpdate().Message.Command(),
|
|
)
|
|
})
|
|
|
|
var PreStartAction = tg.Func(func(c tg.Context) {
|
|
c.Sendf("Please, use /start ")
|
|
})
|
|
|
|
var BotCommands = []tg.Command{
|
|
tg.NewCommand(
|
|
"start",
|
|
"start or restart the bot or move to the start screen",
|
|
).Go(StartWidget),
|
|
tg.NewCommand(
|
|
"info",
|
|
"info desc",
|
|
).WithAction(tg.Func(func(c tg.Context) {
|
|
c.SendfHTML(`<a href="https://res.cloudinary.com/demo/image/upload/v1312461204/sample.jpg">cock</a><strong>cock</strong> die`)
|
|
})),
|
|
tg.NewCommand("hello", "sends the 'Hello, World!' message back").
|
|
WithAction(tg.Func(func(c tg.Context) {
|
|
c.Sendf("Hello, World!")
|
|
})),
|
|
tg.NewCommand("read", "reads a string and sends it back").
|
|
WithWidget(
|
|
tg.Func(func(c tg.Context) {
|
|
str := c.ReadString("Type a string and I will send it back")
|
|
if str == "" {
|
|
return
|
|
}
|
|
c.Sendf2("You typed `%s`", str)
|
|
}),
|
|
),
|
|
tg.NewCommand("cat", "sends a sample image of cat from the server storage").
|
|
WithAction(tg.Func(func(c tg.Context) {
|
|
f, err := os.Open("media/cat.jpg")
|
|
if err != nil {
|
|
c.Sendf("err: %s", err)
|
|
return
|
|
}
|
|
defer f.Close()
|
|
photo := tg.NewFile(f).Photo().Name("cat.jpg").Caption("A cat!")
|
|
c.Send(photo)
|
|
})),
|
|
tg.NewCommand("document", "sends a sample text document").
|
|
WithAction(tg.Func(func(c tg.Context) {
|
|
f, err := os.Open("media/hello.txt")
|
|
if err != nil {
|
|
c.Sendf("err: %s", err)
|
|
return
|
|
}
|
|
defer f.Close()
|
|
doc := tg.NewFile(f).Document().Name("hello.txt").Caption("The document")
|
|
c.Send(doc)
|
|
})),
|
|
tg.NewCommand("botname", "get the bot name").
|
|
WithAction(tg.Func(func(c tg.Context) {
|
|
bd := c.Bot().Data().(*BotData)
|
|
c.Sendf("My name is %q", bd.Name)
|
|
})),
|
|
tg.NewCommand("history", "print go history").
|
|
WithAction(tg.Func(func(c tg.Context) {
|
|
c.Sendf("%q", c.PathHistory())
|
|
})),
|
|
tg.NewCommand(
|
|
"washington",
|
|
"send location of the Washington",
|
|
).WithAction(tg.Func(func(c tg.Context) {
|
|
c.Sendf("Washington location")
|
|
c.Send(
|
|
tg.Messagef("").Location(
|
|
47.751076, -120.740135,
|
|
),
|
|
)
|
|
})),
|
|
}
|