• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang telebot.Bot类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: onCommand

func onCommand(bot *telebot.Bot, command string, args []string) {
	if command == "msg" && len(args) > 1 {
		user := config.GetUser(args[0])
		if user.UID == config.NilUser.UID {
			log.Errorf("[Syscmds] Couldn't get an user with the name or UID %s", args[0])
		}

		msg := connect(args[1:])
		bot.SendMessage(user, "*[Sysadmin]* "+msg, util.Markdown)
		log.Infof("[Syscmds] Sent message %[1]s to %[2]s", msg, user.Name)
	} else if command == "broadcast" && len(args) > 0 {
		msg := connect(args)
		for _, user := range config.GetAllUsers() {
			bot.SendMessage(user, "*[Sysadmin Broadcast]* "+msg, util.Markdown)
		}
		log.Infof("[Syscmds] Broadcasted message %[1]s", msg)
	} else if command == "config" && len(args) > 0 {
		if strings.EqualFold(args[0], "save") {
			if !config.IndentConfig && len(args) > 1 && strings.EqualFold(args[0], "pretty") {
				config.IndentConfig = true
				config.Save()
				config.IndentConfig = false
			} else {
				config.Save()
			}
		} else if strings.EqualFold(args[0], "load") {
			config.Load()
		}
	} else if command == "stop" {
		Shutdown("Sysadmin")
	}
}
开发者ID:tulir293,项目名称:ranssibot,代码行数:32,代码来源:sysinput.go


示例2: Loop

// Loop is an infinite loop that checks for new Ranssi posts
func Loop(bot *telebot.Bot, noNotifAtInit bool) {
	for {
		readNow := config.GetConfig().LastReadPost + 1

		node := getPost(readNow)
		if node != nil {
			topic := strings.TrimSpace(node.FirstChild.FirstChild.Data)

			log.Infof("[Posts] New post detected: %s (ID %d)", topic, readNow)

			if !noNotifAtInit {
				config.GetUsersWithSettingAndRun(func(u config.User) {
					bot.SendMessage(u, lang.Translatef(u, "posts.new", topic, readNow), util.Markdown)
				}, subSetting)
			}

			config.GetConfig().LastReadPost = readNow
			config.ASave()
			updateNews()
			time.Sleep(5 * time.Second)
			continue
		}
		noNotifAtInit = false
		time.Sleep(1 * time.Minute)
	}
}
开发者ID:tulir293,项目名称:ranssibot,代码行数:27,代码来源:util.go


示例3: HandleCommand

// HandleCommand handles a /language command
func HandleCommand(bot *telebot.Bot, message telebot.Message, args []string) {
	sender := config.GetUserWithUID(message.Sender.ID)
	if len(args) > 0 {
		lang := GetLanguage(args[0])
		if lang == nil {
			bot.SendMessage(message.Chat, Translatef(sender, "lang.notfound", lang.Name), util.Markdown)
			return
		}

		if len(args) > 1 {
			user := config.GetUser(args[1])
			if user.UID != config.NilUser.UID && !sender.HasPermission(langChangeOtherPerm) {
				bot.SendMessage(message.Chat, Translatef(sender, "error.noperms", langChangeOtherPerm), util.Markdown)
				return
			}

			user.SetSetting("language", lang.Name)
			bot.SendMessage(message.Chat, Translatef(sender, "lang.changed.other", lang.Name, user.Name), util.Markdown)
		} else {
			sender.SetSetting("language", lang.Name)
			bot.SendMessage(message.Chat, Translatef(sender, "lang.changed", lang.Name), util.Markdown)
		}
	} else {
		bot.SendMessage(message.Chat, Translatef(sender, "lang.usage"), util.Markdown)
	}
}
开发者ID:tulir293,项目名称:ranssibot,代码行数:27,代码来源:commands.go


示例4: sendSecondYear

func sendSecondYear(day int, bot *telebot.Bot, message telebot.Message) {
	sender := config.GetUserWithUID(message.Sender.ID)
	bot.SendMessage(message.Chat,
		lang.Translatef(sender, "timetable.generic",
			secondyear[day][0].Subject, secondyear[day][1].Subject, secondyear[day][2].Subject, secondyear[day][3].Subject,
			util.DateToString(secondyear[day][0].Date))+"\n"+lang.Translatef(sender, "timetable.other", other[day].Subject),
		util.Markdown)
}
开发者ID:tulir293,项目名称:ranssibot,代码行数:8,代码来源:timetable.go


示例5: Run

func (m *NorrisPlugin) Run(bot *telebot.Bot, config util.Config, message telebot.Message) {

	if message.Text == config.CommandPrefix+"norris" {
		res, _ := getJoke("http://api.icndb.com/jokes/random")
		bot.SendMessage(message.Chat, res.Value.Joke, nil)

	}

}
开发者ID:gitter-badger,项目名称:yatzie,代码行数:9,代码来源:norris.go


示例6: sendTo

// sends a fixer message to a single ID.
func sendTo(ID int, bot *telebot.Bot, fa *fixrdb.FixrDB) error {
	var err error
	rates, err := fa.GetRates(ID)
	base, err := fa.GetSetting(ID, "base")
	FixerData, err := fixerio.GetFixerData(base, rates)
	if err != nil {
		return err
	}
	bot.SendMessage(telebot.User{ID: ID}, FixerData.String(), nil)
	return nil
}
开发者ID:nubunto,项目名称:fixr,代码行数:12,代码来源:telegram.go


示例7: SendPhoto

func SendPhoto(url string, message telebot.Message, bot *telebot.Bot) error {
	imagefile, err := SaveImage(url)
	if err != nil {
		log.Println("Error fetching ")
		log.Println(err)
		bot.SendMessage(message.Chat, url, nil)

		return err
	}
	defer os.Remove(imagefile)

	var photo = telebot.Photo{}
	photo.Thumbnail.File, err = telebot.NewFile(imagefile)
	if err != nil {
		log.Println("Error creating the new file ")
		log.Println(err)
		bot.SendMessage(message.Chat, url, nil)

		return err
	}
	//photo.filename=imagefile

	err = bot.SendPhoto(message.Chat, &photo, nil)
	if err != nil {
		log.Println("Error sending photo")
		log.Println(err)
		bot.SendMessage(message.Chat, url, nil)

		return err
	}
	return err
}
开发者ID:piguet,项目名称:yatzie,代码行数:32,代码来源:net.go


示例8: Run

func (m *GooglePlugin) Run(bot *telebot.Bot, config util.Config, message telebot.Message) {
	if strings.Contains(message.Text, config.CommandPrefix+"imgsearch") {
		imgsearch := message.Text
		log.Println("Searching " + imgsearch)
		imgsearch = strings.Replace(imgsearch, config.CommandPrefix+"imgsearch ", "", -1)
		imgsearch = strings.Replace(imgsearch, " ", "%20", -1)

		util.DecodeJson("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q="+imgsearch, func(body io.ReadCloser) bool {
			var data Response
			err := json.NewDecoder(body).Decode(&data)

			for _, i := range data.Response.Results {
				util.SendPhoto(i.Url, message, bot)
				log.Println("Found " + i.Title)
			}

			if err != nil {
				return false
			} else {
				return true
			}
		})

	}

	if strings.Contains(message.Text, config.CommandPrefix+"search") {
		websearch := message.Text
		log.Println("Searching " + websearch)
		websearch = strings.Replace(websearch, config.CommandPrefix+"search ", "", -1)
		websearch = strings.Replace(websearch, " ", "%20", -1)

		util.DecodeJson("https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+websearch, func(body io.ReadCloser) bool {
			var data Response
			err := json.NewDecoder(body).Decode(&data)

			for _, i := range data.Response.Results {
				bot.SendMessage(message.Chat, i.Title+" - "+i.Url, nil)
				log.Println("Found " + i.Title)
			}
			if err != nil {
				return false
			} else {
				return true
			}
		})

	}

}
开发者ID:gitter-badger,项目名称:yatzie,代码行数:49,代码来源:google.go


示例9: handler_loc

// loc - search building number by name
func handler_loc(bot *telebot.Bot, msg telebot.Message, args []string) {
	if len(args) == 0 {
		bot.SendMessage(msg.Chat, msgfmt("loc_noarg"), nil)
		return
	}

	data := get_data("loc")
	arr := strings.Split(data, ",")
	result := ""
	for _, v := range arr {
		if strings.Contains(v, args[0]) {
			result += v + "\n"
		}
	}
	bot.SendMessage(msg.Chat, msgfmt("loc", result), nil)
}
开发者ID:a1sams1a,项目名称:telegram-kaist-bot,代码行数:17,代码来源:bot.go


示例10: processHook

func processHook(ctx webhooks.Context) {
	h := ctx.Hook()
	branch := strings.TrimPrefix(h.Ref, `refs/heads/`)

	for _, r := range cfg.Repos {
		go func(r repo) {
			if r.Name != h.Repo.Name ||
				(r.Branch != `*` && r.Branch != branch) {
				return
			}

			go r.Tasks.Run() //execute tasks
			if r.Notify.Telegram.ChatID != 0 &&
				r.Notify.Telegram.Token != `` {
				var (
					buf bytes.Buffer
					bot *telebot.Bot
					err error
				)

				err = tmpl.Execute(&buf, map[string]interface{}{
					`hook`:   h,
					`branch`: branch,
				})
				if err != nil {
					log.Println(`Template ERR:`, err)
					return
				}

				if bot, err = telebot.NewBot(r.Notify.Telegram.Token); err != nil {
					log.Println(`Telegram ERR:`, err)
					return
				}

				err = bot.SendMessage(telebot.User{ID: r.Notify.Telegram.ChatID}, buf.String(), &sendOpts)
				if err != nil {
					log.Println(`Telegram ERR:`, err)
					return
				}

				log.Println(`Message Sent`)
			}
		}(r)
	}
}
开发者ID:worg,项目名称:hookah,代码行数:45,代码来源:web.go


示例11: inlineHandler

func inlineHandler(bot *telebot.Bot) {
	for query := range bot.Queries {
		log.Printf("Helped @%s with printer facts!", query.From.Username)

		fact, err := GetPrinterFact()
		if err != nil {
			panic(err)
		}

		results := []telebot.Result{
			fact,
		}

		// And finally respond to the query:
		if err := bot.Respond(query, results); err != nil {
			log.Println("ouch:", err)
		}
	}
}
开发者ID:Xe,项目名称:trolling,代码行数:19,代码来源:main.go


示例12: Run

func (m *HelpPlugin) Run(bot *telebot.Bot, config util.Config, message telebot.Message) {
	if message.Text == config.CommandPrefix+"help" || message.Text == config.CommandPrefix+"start" {
		mk := make([]string, len(plugin_registry.Commands))
		i := 0
		for k, _ := range plugin_registry.Commands {
			mk[i] = k
			i++
		}
		sort.Strings(mk)
		var buffer bytes.Buffer

		for _, v := range mk {
			buffer.WriteString(config.CommandPrefix + v + " - " + plugin_registry.Commands[v] + "\n")
		}

		bot.SendMessage(message.Chat,
			util.RandomFromArray(quips)+", "+message.Sender.FirstName+"\n Those are my commands: \n"+buffer.String(), nil)
	}
}
开发者ID:gitter-badger,项目名称:yatzie,代码行数:19,代码来源:help.go


示例13: Send

func (img *Image) Send(bot *telebot.Bot, msg telebot.Message) (err error) {
	if img == nil {
		warning := "You are trying to call a method of inexistent object :-)"
		bot.SendMessage(msg.Chat, warning, nil)
		return errors.New(warning)
	}

	img.Filename = fmt.Sprint("assets/", msg.ID, img.Ext)
	if img.Filename == "" {
		bot.SendMessage(msg.Chat, "There's any filename associated to this query.", nil)
		return errors.New("There's any filename associated to this query.")
	}

	i, err := telebot.NewFile(img.Filename)
	if err != nil {
		return err
	}

	caption := img.Caption[:int(math.Min(float64(len(img.Caption)), MaxCaption))]
	photo := telebot.Photo{Thumbnail: telebot.Thumbnail{File: i, Width: img.Width, Height: img.Height}, Caption: caption}

	err = bot.SendPhoto(msg.Chat, &photo, &telebot.SendOptions{ReplyTo: msg})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:gloob,项目名称:gfxBot,代码行数:28,代码来源:image.go


示例14: Run

func (m *IMDBPlugin) Run(bot *telebot.Bot, config util.Config, message telebot.Message) {
	if strings.Contains(message.Text, config.CommandPrefix+"imdb") {
		imdbsearch := message.Text
		log.Println("Searching " + imdbsearch)
		imdbsearch = strings.Replace(imdbsearch, config.CommandPrefix+"imdb ", "", -1)
		imdbsearch = strings.Replace(imdbsearch, " ", "%20", -1)

		util.DecodeJson("http://www.imdbapi.com/?t="+imdbsearch, func(body io.ReadCloser) bool {
			var imdb Movie
			err := json.NewDecoder(body).Decode(&imdb)

			bot.SendMessage(message.Chat, imdb.Title+" - "+imdb.Year+"\n"+imdb.Genre+" - "+imdb.Duration+"\n"+imdb.Image+"\n"+"http://imdb.com/title/"+imdb.Id, nil)

			if err != nil {
				return false
			} else {
				return true
			}
		})

	}

}
开发者ID:gitter-badger,项目名称:yatzie,代码行数:23,代码来源:imdb.go


示例15: Run

func (m *XkcdPlugin) Run(bot *telebot.Bot, config util.Config, message telebot.Message) {
	if strings.Contains(message.Text, config.CommandPrefix+"xkcd") {
		xkcd := message.Text
		log.Println("Searching " + xkcd)
		xkcd = strings.Replace(xkcd, config.CommandPrefix+"xkcd ", "", -1)

		util.DecodeJson("https://xkcd.com/"+xkcd+"/info.0.json", func(body io.ReadCloser) bool {
			var data Result
			err := json.NewDecoder(body).Decode(&data)
			bot.SendMessage(message.Chat, strconv.Itoa(data.Id)+" - "+data.Img+" - "+data.Title, nil)
			log.Println("Found " + data.Title)

			if err != nil {
				return false
			} else {
				return true
			}
		})

	}

	if message.Text == config.CommandPrefix+"xkcd" {
		util.DecodeJson("https://xkcd.com/info.0.json", func(body io.ReadCloser) bool {
			var data Result
			err := json.NewDecoder(body).Decode(&data)
			bot.SendMessage(message.Chat, strconv.Itoa(data.Id)+" - "+data.Img+" - "+data.Title, nil)
			log.Println("Found " + data.Title)

			if err != nil {
				return false
			} else {
				return true
			}
		})
	}

}
开发者ID:gitter-badger,项目名称:yatzie,代码行数:37,代码来源:xkcd.go


示例16: handler_weather

// weather - get weather information of Daejon
func handler_weather(bot *telebot.Bot, msg telebot.Message, args []string) {
	bot.SendChatAction(msg.Chat, "typing")

	if !check_external("weather", "2") {
		bot.SendMessage(msg.Chat, "Fatal(0x4)", nil)
		return
	}

	bot.SendMessage(msg.Chat, datafmt("weather", get_data("weather")), nil)
}
开发者ID:a1sams1a,项目名称:telegram-kaist-bot,代码行数:11,代码来源:bot.go


示例17: handler_food

// food - get menu of north, east, west cafe
func handler_food(bot *telebot.Bot, msg telebot.Message, args []string) {
	if len(args) == 0 {
		bot.SendMessage(msg.Chat, msgfmt("food_noarg"), nil)
		return
	}

	if args[0] != "n" && args[0] != "w" && args[0] != "e" {
		bot.SendMessage(msg.Chat, msgfmt("food_invarg"), nil)
		return
	}

	iname := "food_" + args[0]
	if !check_external(iname, "d") {
		bot.SendMessage(msg.Chat, "Fatal(0x4)", nil)
		return
	}

	bot.SendMessage(msg.Chat, msgfmt(iname, get_data(iname)), nil)
}
开发者ID:a1sams1a,项目名称:telegram-kaist-bot,代码行数:20,代码来源:bot.go


示例18: ListPlugins

func ListPlugins(message telebot.Message, bot *telebot.Bot) {
	var loaded bytes.Buffer
	var unloaded bytes.Buffer

	for k, _ := range plugin_registry.Plugins {
		loaded.WriteString("\t" + k + "\n")

	}

	for k, _ := range plugin_registry.DisabledPlugins {
		unloaded.WriteString("\t" + k + "\n")
	}
	bot.SendMessage(message.Chat, "Enabled plugins: ", nil)

	bot.SendMessage(message.Chat, loaded.String(), nil)
	bot.SendMessage(message.Chat, "Disabled plugins: ", nil)

	bot.SendMessage(message.Chat, unloaded.String(), nil)
}
开发者ID:piguet,项目名称:yatzie,代码行数:19,代码来源:admin.go


示例19: handler_rand

// rand - get random integer in [0, n)
func handler_rand(bot *telebot.Bot, msg telebot.Message, args []string) {
	if len(args) == 0 {
		bot.SendMessage(msg.Chat, msgfmt("rand_noarg"), nil)
		return
	}

	num, err := strconv.Atoi(args[0])
	if err != nil || num <= 0 {
		bot.SendMessage(msg.Chat, msgfmt("rand_invarg"), nil)
		return
	}

	result := rand.Intn(num)
	bot.SendMessage(msg.Chat, msgfmt("rand", num, result), nil)
}
开发者ID:a1sams1a,项目名称:telegram-kaist-bot,代码行数:16,代码来源:bot.go


示例20: Run

func (m *HalPlugin) Run(bot *telebot.Bot, config util.Config, message telebot.Message) {
	if !strings.HasPrefix(message.Text, config.CommandPrefix) && !util.MatchAnyURL(message.Text) {
		text := strings.Replace(message.Text, "@"+bot.Identity.Username, "", -1)
		// then call hal for random answers
		if len(text) >= MarkovChainOrder {
			m.brainIn <- text
			res := <-m.brainOut
			if res == "" && config.Eloquens == true {
				bot.SendMessage(message.Chat, util.RandomFromArray(quips), nil)

			} else {
				bot.SendMessage(message.Chat,
					res, nil)

			}
		} else {
			bot.SendMessage(message.Chat, util.RandomFromArray(quips), nil)
		}
	}
}
开发者ID:gitter-badger,项目名称:yatzie,代码行数:20,代码来源:hal.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang telebot.Chat类代码示例发布时间:2022-05-28
下一篇:
Golang telebot.NewBot函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap