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

Golang bruxism.Service类代码示例

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

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



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

示例1: messageFunc

func (p *topStreamersPlugin) messageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if !service.IsMe(message) {
		if bruxism.MatchesCommand(service, "topstreamers", message) {
			n := time.Now()
			if !n.After(p.lastUpdate.Add(1 * time.Minute)) {
				if p.lastMessage != "" {
					service.SendMessage(message.Channel(), fmt.Sprintf("%s *Last updated %s.*", p.lastMessage, humanize.Time(p.lastUpdate)))
				}
				return
			}

			service.Typing(message.Channel())

			p.lastUpdate = n

			m, err := p.topStreamers(5)
			if err != nil {
				service.SendMessage(message.Channel(), "There was an error while requesting the top streamers, please try again later.")
				return
			}

			service.SendMessage(message.Channel(), m)
			p.lastMessage = m
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:26,代码来源:topstreamersplugin.go


示例2: Message

func (t *triviaChannel) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if strings.ToLower(message.Message()) == t.Answer {
		t.Lock()
		defer t.Unlock()

		if !t.Active {
			return
		}

		ts := t.Scores[message.UserID()]
		if ts == nil {
			ts = &triviaScore{}
			t.Scores[message.UserID()] = ts
		}
		ts.Name = message.UserName()
		ts.Score++

		service.SendMessage(message.Channel(), fmt.Sprintf("%s got it! The answer was %s.", message.UserName(), t.Answer))
		service.SendMessage(message.Channel(), fmt.Sprintf("%s answered in %d seconds and their score is now %d.", message.UserName(), int(time.Now().Sub(t.Asked).Seconds()), ts.Score))

		t.Unanswered = 0

		if t.hintChan != nil {
			close(t.hintChan)
			t.hintChan = nil
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:28,代码来源:triviaplugin.go


示例3: SendReminder

// SendReminder sends a reminder.
func (p *ReminderPlugin) SendReminder(service bruxism.Service, reminder *Reminder) {
	if reminder.IsPrivate {
		service.SendMessage(reminder.Target, fmt.Sprintf("%s you set a reminder: %s", humanize.Time(reminder.StartTime), reminder.Message))
	} else {
		service.SendMessage(reminder.Target, fmt.Sprintf("%s %s set a reminder: %s", humanize.Time(reminder.StartTime), reminder.Requester, reminder.Message))
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:8,代码来源:reminderplugin.go


示例4: makeScriptFromMessages

func makeScriptFromMessages(service bruxism.Service, message bruxism.Message, messages []bruxism.Message) *comicgen.Script {
	speakers := make(map[string]int)
	avatars := make(map[int]string)

	script := []*comicgen.Message{}

	for _, message := range messages {
		speaker, ok := speakers[message.UserName()]
		if !ok {
			speaker = len(speakers)
			speakers[message.UserName()] = speaker
			avatars[speaker] = message.UserAvatar()
		}

		script = append(script, &comicgen.Message{
			Speaker: speaker,
			Text:    message.Message(),
			Author:  message.UserName(),
		})
	}
	return &comicgen.Script{
		Messages: script,
		Author:   fmt.Sprintf(service.UserName()),
		Avatars:  avatars,
		Type:     comicgen.ComicTypeChat,
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:27,代码来源:comicplugin.go


示例5: carbonitexPluginLoadFunc

func (p *carbonitexPlugin) carbonitexPluginLoadFunc(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
	if service.Name() != bruxism.DiscordServiceName {
		panic("Carbonitex Plugin only supports Discord.")
	}

	go p.Run(bot, service)
	return nil
}
开发者ID:iopred,项目名称:bruxism,代码行数:8,代码来源:carbonitexplugin.go


示例6: randomReminder

func (p *ReminderPlugin) randomReminder(service bruxism.Service) string {
	ticks := ""
	if service.Name() == bruxism.DiscordServiceName {
		ticks = "`"
	}

	return fmt.Sprintf("%s%sreminder %s %s%s", ticks, service.CommandPrefix(), p.random(randomTimes), p.random(randomMessages), ticks)
}
开发者ID:iopred,项目名称:bruxism,代码行数:8,代码来源:reminderplugin.go


示例7: randomChart

func (p *chartPlugin) randomChart(service bruxism.Service) string {
	ticks := ""
	if service.Name() == bruxism.DiscordServiceName {
		ticks = "`"
	}

	return fmt.Sprintf("%s%schart %s %s, %s%s", ticks, service.CommandPrefix(), p.random(randomDirection), p.random(randomY), p.random(randomX), ticks)
}
开发者ID:iopred,项目名称:bruxism,代码行数:8,代码来源:chartplugin.go


示例8: helpFunc

// Help returns a list of help strings that are printed when the user requests them.
func (p *playingPlugin) helpFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, detailed bool) []string {
	if detailed {
		return nil
	}

	if !service.IsBotOwner(message) {
		return nil
	}

	return bruxism.CommandHelp(service, "playing", "<game>, <url>", fmt.Sprintf("Set which game %s is playing.", service.UserName()))
}
开发者ID:iopred,项目名称:bruxism,代码行数:12,代码来源:playingplugin.go


示例9: Message

// Message handler.
func (p *YouTubeJoinPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if (service.IsBotOwner(message) || service.IsChannelOwner(message)) && bruxism.MatchesCommand(service, "leave", message) {
		video, ok := p.youtube.VideoIDForChatID(message.Channel())
		if ok {
			channel, ok := p.youtube.ChannelIDForVideoID(video)
			if ok {
				p.Unmonitor(channel)
			}
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:12,代码来源:youtubejoinplugin.go


示例10: Run

// Run will poll YouTube for channels going live and send messages.
func (p *livePlugin) Run(bot *bruxism.Bot, service bruxism.Service) {
	p.RLock()
	lvc := p.liveVideoChan
	p.RUnlock()
	for {
		v := <-lvc
		p.RLock()
		for channel := range p.youTubeChannelToChannels[v.Snippet.ChannelId] {
			service.SendMessage(channel, fmt.Sprintf("%s has just gone live! http://gaming.youtube.com/watch?v=%s", v.Snippet.ChannelTitle, v.Id))
		}
		p.RUnlock()
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:14,代码来源:liveplugin.go


示例11: MTGCommand

// MTGCommand is a command for getting information about MTG cards..
func MTGCommand(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, command string, parts []string) {
	cardNames := fuzzy.RankFindFold(command, MTGCardNames)
	if len(cardNames) == 0 {
		service.SendMessage(message.Channel(), "Could not find a card with that name, sorry.")
		return
	}

	sort.Sort(cardNames)

	card := MTGCardMap[cardNames[0].Target]

	rest := ""
	if card.Text != "" {
		rest += "\n"
	}
	if card.Power != nil {
		rest += MTGRestReplacer.Replace(fmt.Sprintf("%s/%s", *card.Power, *card.Toughness))
	}
	if card.Loyalty != nil {
		rest += MTGRestReplacer.Replace(fmt.Sprintf("%d", *card.Loyalty))
	}
	if card.ID != nil {
		if rest != "" && rest != "\n" {
			rest += "\n"
		}
		rest += fmt.Sprintf("(http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=%d&type=card)", *card.ID)
	}

	if service.Name() == bruxism.DiscordServiceName {
		service.SendMessage(message.Channel(), fmt.Sprintf("**%s** %s\n*%s*\n%s%s", card.Name, card.ManaCost, card.Type, MTGTextReplacer.Replace(card.Text), rest))
	} else {
		service.SendMessage(message.Channel(), strings.Replace(fmt.Sprintf("%s. %s. %s. %s%s", card.Name, card.Type, card.ManaCost, card.Text, rest), "\n", " ", -1))
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:35,代码来源:mtgplugin.go


示例12: InviteHelp

// InviteHelp will return the help text for the invite command.
func InviteHelp(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) (string, string) {
	switch service.Name() {
	case bruxism.DiscordServiceName:
		discord := service.(*bruxism.Discord)

		if discord.ApplicationClientID != "" {
			return "", fmt.Sprintf("Returns a URL to add %s to your server.", service.UserName())
		}
		return "<discordinvite>", "Joins the provided Discord server."
	case bruxism.YouTubeServiceName:
		return "<videoid>", "Joins the provided YouTube live stream."
	}
	return "<channel>", "Joins the provided channel."
}
开发者ID:iopred,项目名称:bruxism,代码行数:15,代码来源:inviteplugin.go


示例13: Load

// Load will load plugin state from a byte array.
func (p *playedPlugin) Load(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
	if service.Name() != bruxism.DiscordServiceName {
		panic("Played Plugin only supports Discord.")
	}

	if data != nil {
		if err := json.Unmarshal(data, p); err != nil {
			log.Println("Error loading data", err)
		}
	}

	go p.Run(bot, service)
	return nil
}
开发者ID:iopred,项目名称:bruxism,代码行数:15,代码来源:playedplugin.go


示例14: Load

// Load will load plugin state from a byte array.
func (p *MusicPlugin) Load(bot *bruxism.Bot, service bruxism.Service, data []byte) (err error) {
	if service.Name() != bruxism.DiscordServiceName {
		panic("Music Plugin only supports Discord.")
	}

	if data != nil {
		if err = json.Unmarshal(data, p); err != nil {
			log.Println("musicplugin: loading data err:", err)
		}
	}

	go p.init()

	return nil
}
开发者ID:iopred,项目名称:bruxism,代码行数:16,代码来源:musicplugin.go


示例15: Stop

func (t *triviaChannel) Stop(bot *bruxism.Bot, service bruxism.Service) {
	t.Lock()
	defer t.Unlock()

	if !t.Active {
		return
	}

	t.Active = false
	if t.hintChan != nil {
		close(t.hintChan)
		t.hintChan = nil
	}

	service.SendMessage(t.Channel, "Trivia stopped.")

	return
}
开发者ID:iopred,项目名称:bruxism,代码行数:18,代码来源:triviaplugin.go


示例16: Start

func (t *triviaChannel) Start(bot *bruxism.Bot, service bruxism.Service, theme string) {
	t.Lock()
	defer t.Unlock()

	if t.Active {
		return
	}

	service.SendMessage(t.Channel, "Trivia started.")

	t.Active = true
	t.Theme = theme
	t.Unanswered = 0

	go t.question(bot, service)

	return
}
开发者ID:iopred,项目名称:bruxism,代码行数:18,代码来源:triviaplugin.go


示例17: Load

// Load will load plugin state from a byte array.
func (p *playingPlugin) Load(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
	if service.Name() != bruxism.DiscordServiceName {
		panic("Playing Plugin only supports Discord.")
	}

	if data != nil {
		if err := json.Unmarshal(data, p); err != nil {
			log.Println("Error loading data", err)
		}
	}

	if p.Game != "" {
		service.(*bruxism.Discord).Session.UpdateStreamingStatus(0, p.Game, p.URL)
	} else {
		service.(*bruxism.Discord).Session.UpdateStatus(0, p.Game)
	}

	return nil
}
开发者ID:iopred,项目名称:bruxism,代码行数:20,代码来源:playingplugin.go


示例18: messageFunc

// Message handler.
func (p *playingPlugin) messageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if !service.IsMe(message) {
		if bruxism.MatchesCommand(service, "playing", message) {
			if !service.IsBotOwner(message) {
				return
			}
			query, _ := bruxism.ParseCommand(service, message)

			split := strings.Split(query, ",")

			p.Game = strings.Trim(split[0], " ")
			if len(split) > 1 {
				p.URL = strings.Trim(split[1], " ")
				service.(*bruxism.Discord).Session.UpdateStreamingStatus(0, p.Game, p.URL)
			} else {
				service.(*bruxism.Discord).Session.UpdateStatus(0, p.Game)
			}
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:21,代码来源:playingplugin.go


示例19: Load

// Load will load plugin state from a byte array.
func (p *YouTubeJoinPlugin) Load(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
	if service.Name() != bruxism.YouTubeServiceName {
		panic("YouTubeJoin plugin only supports YouTube.")
	}

	if data != nil {
		if err := json.Unmarshal(data, p); err != nil {
			log.Println("Error loading data", err)
		}
	}

	p.youtube = service.(*bruxism.YouTube)

	for channel, _ := range p.Channels {
		p.monitor(channel, false)
	}

	go p.Run(bot, service)

	return nil
}
开发者ID:iopred,项目名称:bruxism,代码行数:22,代码来源:youtubejoinplugin.go


示例20: avatarMessageFunc

func avatarMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if !service.IsMe(message) {
		if bruxism.MatchesCommand(service, "avatar", message) {
			query := strings.Join(strings.Split(message.RawMessage(), " ")[1:], " ")

			id := message.UserID()
			match := userIDRegex.FindStringSubmatch(query)
			if match != nil {
				id = match[1]
			}

			discord := service.(*bruxism.Discord)

			u, err := discord.Session.User(id)
			if err != nil {
				return
			}

			service.SendMessage(message.Channel(), discordgo.EndpointUserAvatar(u.ID, u.Avatar))
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:22,代码来源:discordavatarplugin.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang style.Style函数代码示例发布时间:2022-05-23
下一篇:
Golang bruxism.Message类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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