當前位置: 首頁>>代碼示例>>Golang>>正文


Golang TObject.Chat方法代碼示例

本文整理匯總了Golang中github.com/PeterCxy/gotelegram.TObject.Chat方法的典型用法代碼示例。如果您正苦於以下問題:Golang TObject.Chat方法的具體用法?Golang TObject.Chat怎麽用?Golang TObject.Chat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/PeterCxy/gotelegram.TObject的用法示例。


在下文中一共展示了TObject.Chat方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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())
		}
	}
}
開發者ID:PeterCxy,項目名稱:gotgbot,代碼行數:34,代碼來源:help.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


注:本文中的github.com/PeterCxy/gotelegram.TObject.Chat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。