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


Golang Service.Name方法代码示例

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


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

示例1: InviteCommand

// InviteCommand is a command for accepting an invite to a channel.
func InviteCommand(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, command string, parts []string) {
	if service.Name() == bruxism.DiscordServiceName {
		discord := service.(*bruxism.Discord)

		if discord.ApplicationClientID != "" {
			service.SendMessage(message.Channel(), fmt.Sprintf("Please visit https://discordapp.com/oauth2/authorize?client_id=%s&scope=bot to add %s to your server.", discord.ApplicationClientID, service.UserName()))
			return
		}
	}

	if len(parts) == 1 {
		join := parts[0]
		if service.Name() == bruxism.DiscordServiceName {
			join = discordInviteID(join)
		}
		if err := service.Join(join); err != nil {
			if service.Name() == bruxism.DiscordServiceName && err == bruxism.ErrAlreadyJoined {
				service.PrivateMessage(message.UserID(), "I have already joined that server.")
				return
			}
			log.Println("Error joining %s %v", service.Name(), err)
		} else if service.Name() == bruxism.DiscordServiceName {
			service.PrivateMessage(message.UserID(), "I have joined that server.")
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:27,代码来源:inviteplugin.go

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

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

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

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

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

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

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

示例9: messageFunc

func messageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if service.IsMe(message) || !bruxism.MatchesCommand(service, "myson", message) || service.Name() != bruxism.DiscordServiceName {
		return
	}

	discord := service.(*bruxism.Discord)
	discord.Session.ChannelMessageSendEmbed(message.Channel(), &discordgo.MessageEmbed{
		Color:       discord.UserColor(service.UserID(), message.Channel()),
		Description: "Don't ever talk to me or my son ever again.",
		Author: &discordgo.MessageEmbedAuthor{
			Name:    discord.NicknameForID(service.UserID(), service.UserName(), message.Channel()),
			IconURL: discordgo.EndpointUserAvatar(service.UserID(), discord.Session.State.User.Avatar),
		},
	})
}
开发者ID:iopred,项目名称:bruxism,代码行数:15,代码来源:mysonplugin.go

示例10: Message

func (p *ReminderPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if !service.IsMe(message) {
		if bruxism.MatchesCommand(service, "remind", message) || bruxism.MatchesCommand(service, "reminder", message) {
			_, parts := bruxism.ParseCommand(service, message)

			if len(parts) < 2 {
				service.SendMessage(message.Channel(), fmt.Sprintf("Invalid reminder, no time or message. eg: %s", p.randomReminder(service)))
				return
			}

			t, r, err := p.parseReminder(parts)

			now := time.Now()

			if err != nil || t.Before(now) || t.After(now.Add(time.Hour*24*365+time.Hour)) {
				service.SendMessage(message.Channel(), fmt.Sprintf("Invalid time. eg: %s", strings.Join(randomTimes, ", ")))
				return
			}

			if r == "" {
				service.SendMessage(message.Channel(), fmt.Sprintf("Invalid reminder, no message. eg: %s", p.randomReminder(service)))
				return
			}

			requester := message.UserName()
			if service.Name() == bruxism.DiscordServiceName {
				requester = fmt.Sprintf("<@%s>", message.UserID())
			}

			err = p.AddReminder(&Reminder{
				StartTime: now,
				Time:      t,
				Requester: requester,
				Target:    message.Channel(),
				Message:   r,
				IsPrivate: service.IsPrivate(message),
			})
			if err != nil {
				service.SendMessage(message.Channel(), err.Error())
				return
			}

			service.SendMessage(message.Channel(), fmt.Sprintf("Reminder set for %s.", humanize.Time(t)))
		}
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:46,代码来源:reminderplugin.go

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

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

示例13: emojiMessageFunc

func emojiMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if service.Name() == bruxism.DiscordServiceName && !service.IsMe(message) {
		if bruxism.MatchesCommand(service, "emoji", message) || bruxism.MatchesCommand(service, "hugemoji", message) {
			base := "emoji/twitter"
			if bruxism.MatchesCommand(service, "hugemoji", message) {
				base = "emoji/twitterhuge"
			}
			_, parts := bruxism.ParseCommand(service, message)
			if len(parts) == 1 {
				submatches := discordRegex.FindStringSubmatch(parts[0])
				if len(submatches) != 0 {
					h, err := http.Get("https://cdn.discordapp.com/emojis/" + submatches[1] + ".png")
					if err != nil {
						return
					}

					service.SendFile(message.Channel(), "emoji.png", h.Body)
					h.Body.Close()

					return

				}

				s := strings.TrimSpace(parts[0])
				for i := range s {
					filename := emojiFile(base, s[i:])
					if filename != "" {
						if f, err := os.Open(fmt.Sprintf("%s/%s.png", base, filename)); err == nil {
							defer f.Close()
							service.SendFile(message.Channel(), "emoji.png", f)

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

示例14: Help

// Help returns a list of help strings that are printed when the user requests them.
func (p *comicPlugin) Help(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, detailed bool) []string {
	help := bruxism.CommandHelp(service, "comic", "[1-10]", "Creates a comic from recent messages, or a number of messages if provided.")

	ticks := ""
	if service.Name() == bruxism.DiscordServiceName {
		ticks = "`"
	}
	if detailed {
		help = append(help, []string{
			bruxism.CommandHelp(service, "customcomic", "[id|name:] <text> | [id|name:] <text>", fmt.Sprintf("Creates a custom comic. Available names: %s%s%s", ticks, strings.Join(comicgen.CharacterNames, ", "), ticks))[0],
			bruxism.CommandHelp(service, "customcomicsimple", "[id:] <text> | [id:] <text>", "Creates a simple custom comic.")[0],
			"Examples:",
			bruxism.CommandHelp(service, "comic", "5", "Creates a comic from the last 5 messages")[0],
			bruxism.CommandHelp(service, "customcomic", "A | B | C", "Creates a comic with 3 lines.")[0],
			bruxism.CommandHelp(service, "customcomic", "0: Hi! | 1: Hello! | 0: Goodbye.", "Creates a comic with 3 lines, the second line spoken by a different character")[0],
			bruxism.CommandHelp(service, "customcomic", "tiki: Hi! | jordy: Hello! | tiki: Goodbye.", "Creates a comic with 3 lines, containing tiki and jordy.")[0],
			bruxism.CommandHelp(service, "customcomicsimple", "0: Foo | 1: Bar", "Creates a comic with 2 lines, both spoken by different characters.")[0],
		}...)
	}

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

示例15: messageFunc

func (p *streamerPlugin) messageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	if !service.IsMe(message) {
		if bruxism.MatchesCommand(service, "streamer", message) {
			query, parts := bruxism.ParseCommand(service, message)

			if len(parts) == 0 {
				return
			}

			r, _ := p.requests[query]
			if r == nil {
				r = &streamerPluginRequest{}
				p.requests[query] = r
			}

			n := time.Now()
			if !n.After(r.lastUpdate.Add(60 * time.Minute)) {
				if r.lastMessage != "" {
					service.SendMessage(message.Channel(), fmt.Sprintf("%s *Last updated %s.*", r.lastMessage, humanize.Time(r.lastUpdate)))
				}
				return
			}

			service.Typing(message.Channel())

			r.lastUpdate = n

			m, err := p.streamer(query, service.Name() == bruxism.DiscordServiceName)
			if err != nil {
				service.SendMessage(message.Channel(), "There was an error while requesting the streamer, please try again later.")
				return
			}

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


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