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


Golang gotelegram.TObject类代码示例

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


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

示例1: Default

func (this *Chinese) Default(name string, msg telegram.TObject, state *map[string]interface{}) {
	if msg["text"] != nil {
		text := msg["text"].(string)
		if !strings.HasPrefix(text, "/") {
			this.Learn(text, msg.ChatId())
		}
	}
}
开发者ID:PeterCxy,项目名称:gotgbot,代码行数:8,代码来源:chinese.go

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

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

示例4: 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

示例5: 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

示例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() {
					this.tg.SendMessage("@"+msg.From()["username"].(string)+" "+text, msg.ChatId())
				}, duration)

				utils.ReleaseGrabber(msg.FromId(), msg.ChatId())
			}
		}
	}
}
开发者ID:wan-qy,项目名称:gotgbot,代码行数:23,代码来源:misc.go

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

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

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

示例10: 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

示例11: 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
			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, num, this.ipv6)

			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:wan-qy,项目名称:gotgbot,代码行数:46,代码来源:scholar.go


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