Пример #1
0
// Help returns a list of help strings that are printed when the user requests them.
func (p *triviaPlugin) Help(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, detailed bool) []string {
	if service.IsPrivate(message) || !(service.IsModerator(message) || service.IsBotOwner(message)) {
		return nil
	}

	return []string{
		bruxism.CommandHelp(service, "trivia", "<start|stop> [theme]", "Starts or stops trivia with an optional theme.")[0],
		bruxism.CommandHelp(service, "trivia", "<score>", "Returns your current trivia score.")[0],
	}
}
Пример #2
0
// Message handler.
func (p *livePlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	defer bruxism.MessageRecover()
	if !service.IsMe(message) {
		messageChannel := message.Channel()

		if bruxism.MatchesCommand(service, "live", message) {
			ticks := ""
			if service.Name() == bruxism.DiscordServiceName {
				ticks = "`"
			}

			_, parts := bruxism.ParseCommand(service, message)

			if len(parts) == 0 {
				service.SendMessage(messageChannel, fmt.Sprintf("Incorrect command. eg: %s%slive [add|remove|list] <%s>%s", ticks, service.CommandPrefix(), "UCGmC0A8mEAPdlELQdP9xJbw", ticks))
			}

			switch parts[0] {
			case "list":
				if !service.IsModerator(message) {
					service.SendMessage(messageChannel, "I'm sorry, you must be the channel owner to list live announcements.")
					return
				}
				list := []string{}
				p.Lock()
				for ytChannel := range p.ChannelToYouTubeChannels[messageChannel] {
					list = append(list, fmt.Sprintf("%s (%s)", p.ytLiveChannel.ChannelName(ytChannel), ytChannel))
				}
				p.Unlock()
				if len(list) == 0 {
					service.SendMessage(messageChannel, "No Channels are being announced.")
				} else {
					service.SendMessage(messageChannel, fmt.Sprintf("Currently announcing: %s", strings.Join(list, ",")))
				}
			case "add":
				if !service.IsModerator(message) {
					service.SendMessage(messageChannel, "I'm sorry, you must be the channel owner to add live announcements.")
					return
				}
				if len(parts) != 2 || len(parts[1]) != 24 {
					service.SendMessage(messageChannel, fmt.Sprintf("Incorrect Channel ID. eg: %s%slive %s %s%s", ticks, service.CommandPrefix(), parts[0], "UCGmC0A8mEAPdlELQdP9xJbw", ticks))
					return
				}
				err := p.monitor(messageChannel, parts[1])
				if err != nil {
					service.SendMessage(messageChannel, fmt.Sprintf("Could not add Channel ID. %s", err))
					return
				}
				service.SendMessage(messageChannel, fmt.Sprintf("Messages will be sent here when %s goes live.", p.ytLiveChannel.ChannelName(parts[1])))
			case "remove":
				if !service.IsModerator(message) {
					service.SendMessage(messageChannel, "I'm sorry, you must be the channel owner to remove live announcements.")
					return
				}
				if len(parts) != 2 || len(parts[1]) != 24 {
					service.SendMessage(messageChannel, fmt.Sprintf("Incorrect Channel ID. eg: %s%slive %s %s%s", ticks, service.CommandPrefix(), parts[0], "UCGmC0A8mEAPdlELQdP9xJbw", ticks))
					return
				}
				p.Lock()
				delete(p.ChannelToYouTubeChannels[messageChannel], parts[1])
				delete(p.youTubeChannelToChannels[parts[1]], messageChannel)
				p.Unlock()
				service.SendMessage(messageChannel, fmt.Sprintf("Messages will no longer be sent here when %s goes live.", p.ytLiveChannel.ChannelName(parts[1])))
			}
		}
	}
}
Пример #3
0
// Message handler.
func (p *triviaPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
	defer bruxism.MessageRecover()
	if !service.IsMe(message) && !service.IsPrivate(message) {
		messageChannel := message.Channel()

		isCommand := bruxism.MatchesCommand(service, "trivia", message)

		if isCommand && (service.IsModerator(message) || service.IsBotOwner(message)) {
			p.Lock()
			tc := p.Channels[messageChannel]
			if tc == nil {
				tc = &triviaChannel{
					Channel: messageChannel,
					Scores:  map[string]*triviaScore{},
				}
				p.Channels[messageChannel] = tc
			}
			p.Unlock()

			_, parts := bruxism.ParseCommand(service, message)

			if len(parts) == 0 {
				return
			}

			switch parts[0] {
			case "start":
				theme := ""
				if len(parts) >= 2 {
					theme = parts[1]
				}
				tc.Start(bot, service, theme)
			case "stop":
				tc.Stop(bot, service)
			}

		} else {
			if isCommand {
				_, parts := bruxism.ParseCommand(service, message)
				if len(parts) == 0 {
					return
				}
				if parts[0] == "score" {
					p.RLock()
					tc := p.Channels[messageChannel]

					if tc != nil {
						ts := tc.Scores[message.UserID()]
						if ts != nil {
							service.SendMessage(message.Channel(), fmt.Sprintf("%s's score is %d.", message.UserName(), ts.Score))
						} else {
							service.SendMessage(message.Channel(), fmt.Sprintf("%s's score is 0.", message.UserName()))
						}
					}

					p.RUnlock()
				}

				return
			}

			p.RLock()
			tc := p.Channels[messageChannel]
			p.RUnlock()
			if tc != nil {
				tc.Message(bot, service, message)
			}
		}
	}
}