本文整理汇总了Golang中github.com/iopred/bruxism.Service类的典型用法代码示例。如果您正苦于以下问题:Golang Service类的具体用法?Golang Service怎么用?Golang Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
}
}
示例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
}
}
}
示例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))
}
}
示例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,
}
}
示例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
}
示例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)
}
示例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)
}
示例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()))
}
示例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)
}
}
}
}
示例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()
}
}
示例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))
}
}
示例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."
}
示例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
}
示例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
}
示例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
}