本文整理汇总了Golang中github.com/PeterCxy/gotelegram.TObject.MessageId方法的典型用法代码示例。如果您正苦于以下问题:Golang TObject.MessageId方法的具体用法?Golang TObject.MessageId怎么用?Golang TObject.MessageId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PeterCxy/gotelegram.TObject
的用法示例。
在下文中一共展示了TObject.MessageId方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Command
func (this *Chinese) Command(name string, msg telegram.TObject, args []string) {
if name == "learn" {
this.Learn(strings.Join(args, " "), msg.ChatId())
} else if name == "speak" {
this.tg.SendMessage(this.Speak(msg.ChatId()), msg.ChatId())
} else if name == "answer" {
text := strings.Join(args, " ")
id := msg.MessageId()
if (text == "") && (msg["reply_to_message"] != nil) && (msg.ReplyToMessage()["text"] != nil) {
text = msg.ReplyToMessage()["text"].(string)
id = msg.ReplyToMessage().MessageId()
}
text = strings.Trim(text, " \n")
if text == "" {
this.tg.ReplyToMessage(msg.MessageId(), "Please provide a question or reply to a message for me to answer.", msg.ChatId())
} else {
r := this.Answer(text, msg.ChatId())
if r != "" {
this.tg.ReplyToMessage(id, r, msg.ChatId())
}
}
}
}
示例2: handle
func handle(msg telegram.TObject) {
if Debug {
log.Println(msg)
}
// Parse arguments (including the command)
args := make([]string, 0)
text := ""
if msg["text"] != nil {
text = strings.Trim(msg["text"].(string), " ")
}
if text != "" {
args = telegram.ParseArgs(text)
}
// A command
if (len(args) > 0) && strings.HasPrefix(args[0], "/") {
cmd := args[0][1:]
args = args[1:]
if strings.Contains(cmd, "@") {
if !strings.HasSuffix(cmd, "@"+BotName) {
// This command is not our business
return
} else {
cmd = cmd[0:strings.Index(cmd, "@")]
}
}
command := Commands[cmd]
if command.Processor == nil {
return
}
if (command.ArgNum < 0) || (command.ArgNum == len(args)) {
command.Processor.Command(cmd, msg, args)
} else {
str := fmt.Sprintf("Usage: /%s %s\nDescription: %s", command.Name, command.Args, command.Desc)
Telegram.ReplyToMessage(
msg.MessageId(),
str,
msg.ChatId())
}
} else {
if utils.HasGrabber(msg.FromId(), msg.ChatId()) {
// Distribute to grabbers
name, processor := utils.Grabber(msg.FromId(), msg.ChatId())
processor.Default(name, msg, utils.GrabberState(msg.FromId(), msg.ChatId()))
}
// Grabbers and default processors are both called
if Default.Processor != nil {
// Distribute to default processor
Default.Processor.Default(Default.Name, msg, nil)
}
}
}
示例3: Gun
func Gun(tg *telegram.Telegram, msg telegram.TObject) bool {
if msg["text"] != nil {
out := eng.Calculate(common.TextToSample(msg["text"].(string)))
log.Println(out)
if (out[0] > 0.5) && (out[0]-out[1] > 0.3) {
tg.ReplyToMessage(msg.MessageId(), "#RICH", msg.ChatId())
return true
}
}
return false
}
示例4: Command
func (this *Help) Command(name string, msg telegram.TObject, args []string) {
if name == "help" {
str := ""
for _, v := range *this.cmds {
// Skip debug functions
if v.Debug {
continue
}
str += fmt.Sprintf(
"/%s %s\n%s\n\n",
v.Name, v.Args, v.Desc)
}
this.tg.ReplyToMessage(msg.MessageId(), str, msg.ChatId())
}
}
示例5: Command
func (this *Help) Command(name string, msg telegram.TObject, args []string) {
if name == "help" {
if !msg.Chat().IsGroup() {
str := "Source code available at https://github.com/PeterCxy/gotgbot , written in Golang\n\n"
for _, v := range *this.cmds {
// Skip debug functions
if v.Debug {
continue
}
str += fmt.Sprintf(
"/%s %s\n%s\n\n",
v.Name, v.Args, v.Desc)
}
this.tg.ReplyToMessage(msg.MessageId(), str, msg.ChatId())
} else {
this.tg.ReplyToMessage(msg.MessageId(), "Help only available in private chats.", msg.ChatId())
}
} else if name == "father" {
if !msg.Chat().IsGroup() {
str := ""
for _, v := range *this.cmds {
if v.Debug {
continue
}
str += fmt.Sprintf(
"%s - %s %s\n",
v.Name, v.Args, strings.Split(v.Desc, "\n")[0])
}
this.tg.ReplyToMessage(msg.MessageId(), str, msg.ChatId())
}
}
}
示例6: Default
func (this *Misc) Default(name string, msg telegram.TObject, state *map[string]interface{}) {
if name == "remind" {
if (*state)["remind"] == nil {
(*state)["remind"] = msg["text"].(string)
this.tg.ReplyToMessage(msg.MessageId(), "How long after now should I remind you?", msg.ChatId())
} else {
duration, err := time.ParseDuration(msg["text"].(string))
if err != nil {
this.tg.ReplyToMessage(msg.MessageId(), "Invalid time. Supported format: BhCmDsEmsFnsGus", msg.ChatId())
} else {
text := (*state)["remind"].(string)
this.tg.ReplyToMessage(msg.MessageId(), "Yes, sir!", msg.ChatId())
utils.PostDelayed(func() {
if !strings.HasPrefix(text, "\\/") {
this.tg.SendMessage("@"+msg.From()["username"].(string)+" "+text, msg.ChatId())
} else {
msg["text"] = text[1:]
utils.Handler()(msg)
}
}, duration)
utils.ReleaseGrabber(msg.FromId(), msg.ChatId())
}
}
}
}
示例7: Command
func (this *Misc) Command(name string, msg telegram.TObject, args []string) {
switch name {
case "echo":
this.tg.SendMessage(args[0], msg.ChatId())
case "parse":
this.tg.ReplyToMessage(msg.MessageId(), strings.Join(args, "\n"), msg.ChatId())
case "cancel":
if utils.HasGrabber(msg.FromId(), msg.ChatId()) {
utils.ReleaseGrabber(msg.FromId(), msg.ChatId())
this.tg.SendMessage("Current session cancelled", msg.ChatId())
}
case "remind":
this.tg.ReplyToMessage(msg.MessageId(), "What do you want me to remind you of?", msg.ChatId())
utils.SetGrabber(types.Grabber{
Name: "remind",
Uid: msg.FromId(),
Chat: msg.ChatId(),
Processor: this,
})
case "choose":
this.choose(msg, args)
}
}
示例8: Command
func (this *Scholar) Command(name string, msg telegram.TObject, args []string) {
if name == "calc" {
res, err := calc.Calculate(strings.Join(args, " "))
if err == nil {
this.tg.ReplyToMessage(msg.MessageId(), fmt.Sprintf("%f", res), msg.ChatId())
} else {
this.tg.ReplyToMessage(msg.MessageId(), err.Error(), msg.ChatId())
}
} else if name == "google" {
query := strings.Join(args, " ")
if query == "" {
this.tg.ReplyToMessage(msg.MessageId(), "Please provide something to search for.", msg.ChatId())
} else {
num := 5
maxNum := 5
irc := false
if (msg.Chat()["title"] != nil) && strings.HasPrefix(msg.Chat()["title"].(string), "#") {
num = 1 // Disable long output in IRC-connected groups
irc = true
}
this.tg.SendChatAction("typing", msg.ChatId())
res, hasNext := Google(query, 0, maxNum, this.ipv6)
if len(res) > num {
res = res[0:num]
}
if irc {
hasNext = false
}
this.tg.SendMessageNoPreview(formatGoogle(res, hasNext), msg.ChatId())
if hasNext {
state := utils.SetGrabber(types.Grabber{
Name: "google",
Uid: msg.FromId(),
Chat: msg.ChatId(),
Processor: this,
})
(*state)["start"] = len(res)
(*state)["query"] = query
}
}
}
}
示例9: choose
func (this *Misc) choose(msg telegram.TObject, args []string) {
if len(args) <= 1 {
this.tg.ReplyToMessage(msg.MessageId(), "Please provide the output format.", msg.ChatId())
} else {
items := strings.Split(args[0], ";")
results := make([]interface{}, len(items))
for i, v := range items {
// Random number in a range
if strings.HasPrefix(v, "[") && strings.HasSuffix(v, "]") && strings.Contains(v, "-") {
v = v[1 : len(v)-1]
a := strings.Split(v, "-")
if len(a) == 2 {
start, err1 := strconv.ParseInt(a[0], 10, 64)
end, err2 := strconv.ParseInt(a[1], 10, 64)
if (err1 == nil) && (err2 == nil) {
r := float64(start) + rand.Float64()*float64(end-start)
results[i] = r
continue
}
}
this.tg.ReplyToMessage(msg.MessageId(), "Range format: [start-end]", msg.ChatId())
return
} else {
a := strings.Split(v, ",")
results[i] = a[rand.Intn(len(a))]
}
}
format := strings.Join(args[1:], " ")
tokens := ParseFormat(format)
// Now let's do the heavy type conversion stuff
i := 0
for _, t := range tokens {
if i >= len(results) {
break
}
if len(t) < 1 {
continue
}
switch t[len(t)-1] {
case 'b', 'c', 'd', 'o', 'q', 'x', 'X', 'U':
// Integer
switch t := results[i].(type) {
case string:
results[i], _ = strconv.ParseInt(results[i].(string), 10, 64)
case float64:
results[i] = int64(results[i].(float64))
default:
_ = t
}
case 'e', 'E', 'f', 'F', 'g', 'G':
// Float
switch t := results[i].(type) {
case string:
results[i], _ = strconv.ParseFloat(results[i].(string), 64)
case int64:
results[i] = float64(results[i].(int64))
default:
_ = t
}
}
if t != "%" {
i += 1
}
}
this.tg.ReplyToMessage(
msg.MessageId(),
fmt.Sprintf(format, results...),
msg.ChatId())
}
}