当前位置: 首页>>代码示例>>Golang>>正文


Golang TObject.FromId方法代码示例

本文整理汇总了Golang中github.com/PeterCxy/gotelegram.TObject.FromId方法的典型用法代码示例。如果您正苦于以下问题:Golang TObject.FromId方法的具体用法?Golang TObject.FromId怎么用?Golang TObject.FromId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/PeterCxy/gotelegram.TObject的用法示例。


在下文中一共展示了TObject.FromId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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())
			}
		}
	}
}
开发者ID:PeterCxy,项目名称:gotgbot,代码行数:28,代码来源:misc.go

示例2: 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
			}
		}
	}
}
开发者ID:PeterCxy,项目名称:gotgbot,代码行数:51,代码来源:scholar.go

示例3: Default

func (this *Scholar) Default(name string, msg telegram.TObject, state *map[string]interface{}) {
	if name == "google" {
		if (msg["text"] == nil) || (strings.ToLower(msg["text"].(string)) != "next") {
			return
		}

		start := (*state)["start"].(int)
		query := (*state)["query"].(string)

		this.tg.SendChatAction("typing", msg.ChatId())
		res, hasNext := Google(query, start, 5, this.ipv6)

		this.tg.SendMessageNoPreview(formatGoogle(res, hasNext), msg.ChatId())

		if hasNext {
			(*state)["start"] = start + len(res)
		} else {
			utils.ReleaseGrabber(msg.FromId(), msg.ChatId())
		}
	}
}
开发者ID:wan-qy,项目名称:gotgbot,代码行数:21,代码来源:scholar.go

示例4: 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)
		}
	}
}
开发者ID:PeterCxy,项目名称:gotgbot,代码行数:60,代码来源:server.go

示例5: 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)
	}
}
开发者ID:wan-qy,项目名称:gotgbot,代码行数:23,代码来源:misc.go


注:本文中的github.com/PeterCxy/gotelegram.TObject.FromId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。