Permalink
Browse files

Remove old plugins that aren't useful. Add new monitoring YouTube inv…

…ite plugin.
  • Loading branch information...
1 parent e865057 commit be821aefb6c10d3bd97a2c25ac9927de96bac3ab @iopred committed Dec 10, 2016
View
@@ -2,23 +2,26 @@ language: go
go:
- 1.5
- 1.6
+ - 1.7
install:
- go get github.com/iopred/bruxism/carbonitexplugin
- go get github.com/iopred/bruxism/chartplugin
- go get github.com/iopred/bruxism/comicplugin
- - go get github.com/iopred/bruxism/directmessageinviteplugin
- go get github.com/iopred/bruxism/discordavatarplugin
- go get github.com/iopred/bruxism/emojiplugin
- go get github.com/iopred/bruxism/inviteplugin
- go get github.com/iopred/bruxism/liveplugin
- go get github.com/iopred/bruxism/mtgplugin
+ - go get github.com/iopred/bruxism/musicplugin
+ - go get github.com/iopred/bruxism/mysonplugin
- go get github.com/iopred/bruxism/numbertriviaplugin
- go get github.com/iopred/bruxism/playedplugin
- go get github.com/iopred/bruxism/playingplugin
- go get github.com/iopred/bruxism/reminderplugin
- - go get github.com/iopred/bruxism/slowmodeplugin
- go get github.com/iopred/bruxism/statsplugin
- go get github.com/iopred/bruxism/streamerplugin
- go get github.com/iopred/bruxism/topstreamersplugin
+ - go get github.com/iopred/bruxism/triviaplugin
+ - go get github.com/iopred/bruxism/youtubejoinplugin
- go get github.com/iopred/bruxism
- go get -v .
View
@@ -14,7 +14,7 @@ import (
)
// VersionString is the current version of the bot
-const VersionString string = "0.8"
+const VersionString string = "0.9"
type serviceEntry struct {
Service
@@ -179,7 +179,7 @@ func (p *chartPlugin) messageFunc(bot *bruxism.Bot, service bruxism.Service, mes
}
}
-// New will create a new comic plugin.
+// New will create a new chart plugin.
func New() bruxism.Plugin {
p := &chartPlugin{
SimplePlugin: *bruxism.NewSimplePlugin("Chart"),
View
@@ -2,39 +2,43 @@ package main
import (
"flag"
+ "fmt"
"log"
"math/rand"
+ "net/http"
"os"
"os/signal"
"strings"
"time"
"github.com/iopred/bruxism"
"github.com/iopred/bruxism/carbonitexplugin"
- "github.com/iopred/bruxism/directmessageinviteplugin"
+ "github.com/iopred/bruxism/chartplugin"
+ "github.com/iopred/bruxism/comicplugin"
"github.com/iopred/bruxism/discordavatarplugin"
"github.com/iopred/bruxism/emojiplugin"
"github.com/iopred/bruxism/inviteplugin"
"github.com/iopred/bruxism/liveplugin"
+ "github.com/iopred/bruxism/musicplugin"
"github.com/iopred/bruxism/mysonplugin"
"github.com/iopred/bruxism/numbertriviaplugin"
"github.com/iopred/bruxism/playedplugin"
"github.com/iopred/bruxism/playingplugin"
"github.com/iopred/bruxism/reminderplugin"
- "github.com/iopred/bruxism/slowmodeplugin"
"github.com/iopred/bruxism/statsplugin"
"github.com/iopred/bruxism/streamerplugin"
"github.com/iopred/bruxism/topstreamersplugin"
"github.com/iopred/bruxism/triviaplugin"
"github.com/iopred/bruxism/wormholeplugin"
- "github.com/iopred/bruxism/youtubeinviteplugin"
+ "github.com/iopred/bruxism/youtubejoinplugin"
)
var youtubeURL bool
var youtubeAuth string
var youtubeConfigFilename string
var youtubeTokenFilename string
var youtubeLiveVideoIDs string
+var youtubeInvitePort int
var discordToken string
var discordEmail string
var discordPassword string
@@ -58,6 +62,7 @@ func init() {
flag.StringVar(&youtubeConfigFilename, "youtubeconfig", "youtubeoauth2config.json", "The filename that contains the oauth2 config.")
flag.StringVar(&youtubeTokenFilename, "youtubetoken", "youtubeoauth2token.json", "The filename to store the oauth2 token.")
flag.StringVar(&youtubeLiveVideoIDs, "youtubelivevideoids", "", "Comma separated list of video id's to poll.")
+ flag.IntVar(&youtubeInvitePort, "youtubeinviteport", 7777, "The port to listen for invites.")
flag.StringVar(&discordToken, "discordtoken", "", "Discord token.")
flag.StringVar(&discordEmail, "discordemail", "", "Discord account email.")
flag.StringVar(&discordPassword, "discordpassword", "", "Discord account password.")
@@ -104,26 +109,28 @@ func main() {
}
}, nil)
- ytip := youtubeinviteplugin.New()
-
youtube := bruxism.NewYouTube(youtubeURL, youtubeAuth, youtubeConfigFilename, youtubeTokenFilename, youtubeLiveVideoIDs)
err := youtube.Init()
if err != nil {
log.Fatal(err)
}
ytLiveChannel := bruxism.NewYTLiveChannel(youtube.Service)
+ ytip := youtubejoinplugin.New(ytLiveChannel)
bot.RegisterService(youtube)
bot.RegisterPlugin(youtube, cp)
- bot.RegisterPlugin(youtube, slowmodeplugin.New())
- bot.RegisterPlugin(youtube, topstreamersplugin.New(youtube))
- bot.RegisterPlugin(youtube, streamerplugin.New(youtube))
+
+ bot.RegisterPlugin(youtube, chartplugin.New())
+ bot.RegisterPlugin(youtube, comicplugin.New())
+ bot.RegisterPlugin(youtube, liveplugin.New(ytLiveChannel))
bot.RegisterPlugin(youtube, reminderplugin.New())
+ bot.RegisterPlugin(youtube, streamerplugin.New(youtube))
+ bot.RegisterPlugin(youtube, topstreamersplugin.New(youtube))
bot.RegisterPlugin(youtube, triviaplugin.New())
bot.RegisterPlugin(youtube, wormholeplugin.New())
- bot.RegisterPlugin(youtube, liveplugin.New(ytLiveChannel))
+ bot.RegisterPlugin(youtube, ytip)
// Register the Discord service if we have an email or token.
if (discordEmail != "" && discordPassword != "") || discordToken != "" {
@@ -139,22 +146,25 @@ func main() {
bot.RegisterService(discord)
bot.RegisterPlugin(discord, cp)
- bot.RegisterPlugin(discord, topstreamersplugin.New(youtube))
- bot.RegisterPlugin(discord, streamerplugin.New(youtube))
- bot.RegisterPlugin(discord, playedplugin.New())
- bot.RegisterPlugin(discord, playingplugin.New())
- bot.RegisterPlugin(discord, directmessageinviteplugin.New())
- bot.RegisterPlugin(discord, reminderplugin.New())
- bot.RegisterPlugin(discord, emojiplugin.New())
- bot.RegisterPlugin(discord, liveplugin.New(ytLiveChannel))
- bot.RegisterPlugin(discord, discordavatarplugin.New())
+
if carbonitexKey != "" {
bot.RegisterPlugin(discord, carbonitexplugin.New(carbonitexKey))
}
+
+ bot.RegisterPlugin(discord, chartplugin.New())
+ bot.RegisterPlugin(discord, comicplugin.New())
+ bot.RegisterPlugin(discord, discordavatarplugin.New())
+ bot.RegisterPlugin(discord, emojiplugin.New())
+ bot.RegisterPlugin(discord, liveplugin.New(ytLiveChannel))
+ bot.RegisterPlugin(discord, musicplugin.New(discord))
+ bot.RegisterPlugin(discord, mysonplugin.New())
+ bot.RegisterPlugin(discord, playedplugin.New())
+ bot.RegisterPlugin(discord, playingplugin.New())
+ bot.RegisterPlugin(discord, reminderplugin.New())
+ bot.RegisterPlugin(discord, streamerplugin.New(youtube))
+ bot.RegisterPlugin(discord, topstreamersplugin.New(youtube))
bot.RegisterPlugin(discord, triviaplugin.New())
bot.RegisterPlugin(discord, wormholeplugin.New())
- bot.RegisterPlugin(discord, ytip)
- bot.RegisterPlugin(discord, mysonplugin.New())
}
// Register the IRC service if we have an IRC server and Username.
@@ -163,13 +173,15 @@ func main() {
bot.RegisterService(irc)
bot.RegisterPlugin(irc, cp)
- bot.RegisterPlugin(irc, topstreamersplugin.New(youtube))
- bot.RegisterPlugin(irc, streamerplugin.New(youtube))
+
+ bot.RegisterPlugin(irc, chartplugin.New())
+ bot.RegisterPlugin(irc, comicplugin.New())
+ bot.RegisterPlugin(irc, liveplugin.New(ytLiveChannel))
bot.RegisterPlugin(irc, reminderplugin.New())
+ bot.RegisterPlugin(irc, streamerplugin.New(youtube))
+ bot.RegisterPlugin(irc, topstreamersplugin.New(youtube))
bot.RegisterPlugin(irc, triviaplugin.New())
bot.RegisterPlugin(irc, wormholeplugin.New())
- bot.RegisterPlugin(irc, liveplugin.New(ytLiveChannel))
- bot.RegisterPlugin(irc, ytip)
}
if slackToken != "" {
@@ -178,17 +190,27 @@ func main() {
bot.RegisterService(slack)
bot.RegisterPlugin(slack, cp)
- bot.RegisterPlugin(slack, topstreamersplugin.New(youtube))
+
+ bot.RegisterPlugin(slack, chartplugin.New())
+ bot.RegisterPlugin(slack, comicplugin.New())
+ bot.RegisterPlugin(slack, liveplugin.New(ytLiveChannel))
bot.RegisterPlugin(slack, streamerplugin.New(youtube))
+ bot.RegisterPlugin(slack, topstreamersplugin.New(youtube))
bot.RegisterPlugin(slack, triviaplugin.New())
bot.RegisterPlugin(slack, wormholeplugin.New())
- bot.RegisterPlugin(slack, liveplugin.New(ytLiveChannel))
- bot.RegisterPlugin(slack, ytip)
}
// Start all our services.
bot.Open()
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ channel := r.FormValue("channel")
+ if channel != "" {
+ ytip.Monitor(channel)
+ }
+ })
+ http.ListenAndServe(fmt.Sprintf(":%d", youtubeInvitePort), nil)
+
// Wait for a termination signal, while saving the bot state every minute. Save on close.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
@@ -26,6 +26,7 @@ type comicPlugin struct {
Comics int
}
+// Load will load plugin state from a byte array.
func (p *comicPlugin) Load(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
if data != nil {
if err := json.Unmarshal(data, p); err != nil {
@@ -36,10 +37,12 @@ func (p *comicPlugin) Load(bot *bruxism.Bot, service bruxism.Service, data []byt
return nil
}
+// Save will save plugin state to a byte array.
func (p *comicPlugin) Save() ([]byte, error) {
return json.Marshal(p)
}
+// 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.")
@@ -141,6 +144,7 @@ func (p *comicPlugin) makeComic(bot *bruxism.Bot, service bruxism.Service, messa
}
}
+// Message handler.
func (p *comicPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if service.IsMe(message) {
return
@@ -231,7 +235,7 @@ func (p *comicPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message
p.makeComic(bot, service, message, makeScriptFromMessages(service, message, log[len(log)-lines:]))
} else {
// Don't append commands.
- if strings.HasPrefix(strings.ToLower(strings.Trim(message.Message(), " ")), strings.ToLower(service.CommandPrefix())) {
+ if bruxism.MatchesCommand(service, "", message) {
return
}
@@ -261,6 +265,7 @@ func (p *comicPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message
}
}
+// Name returns the name of the plugin.
func (p *comicPlugin) Name() string {
return "Comic"
}
View
@@ -40,8 +40,8 @@ func MatchesCommandString(service Service, commandString string, private bool, m
// MatchesCommand returns true if a message matches a command.
func MatchesCommand(service Service, commandString string, message Message) bool {
- // Only new messages can trigger commands.
- if message.Type() != MessageTypeCreate {
+ // Deleted messages can't trigger commands.
+ if message.Type() == MessageTypeDelete {
return false
}
return MatchesCommandString(service, commandString, service.IsPrivate(message), message.Message())
@@ -62,7 +62,11 @@ func ParseCommandString(service Service, message string) (string, []string) {
parts := strings.Split(message, " ")
if len(parts) > 1 {
rest := parts[1:]
- return strings.Join(rest, " "), parts[1:]
+ query := strings.Join(rest, " ")
+ for i, v := range rest {
+ rest[i] = strings.TrimSpace(v)
+ }
+ return query, rest
}
return "", []string{}
}
@@ -1,56 +0,0 @@
-package directmessageinviteplugin
-
-import (
- "fmt"
- "log"
- "strings"
-
- "github.com/iopred/bruxism"
-)
-
-func discordInviteID(id string) string {
- id = strings.Replace(id, "://discordapp.com/invite/", "://discord.gg/", -1)
- id = strings.Replace(id, "https://discord.gg/", "", -1)
- id = strings.Replace(id, "http://discord.gg/", "", -1)
- return id
-}
-
-func directMessageInviteLoadFunc(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
- if service.Name() != bruxism.DiscordServiceName {
- panic("Direct Message Invite Plugin only supports Discord.")
- }
- return nil
-}
-
-func directMessageInviteMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
- if service.Name() == bruxism.DiscordServiceName && !service.IsMe(message) && service.IsPrivate(message) {
- discord := service.(*bruxism.Discord)
-
- messageMessage := message.Message()
- id := discordInviteID(messageMessage)
- if id != messageMessage && strings.HasPrefix(messageMessage, "http") {
-
- if discord.ApplicationClientID != "" {
- service.PrivateMessage(message.UserID(), fmt.Sprintf("Please visit https://discordapp.com/oauth2/authorize?client_id=%s&scope=bot to add %s to your server.", discord.ApplicationClientID, service.UserName()))
- } else {
- if err := service.Join(id); err != nil {
- if err == bruxism.ErrAlreadyJoined {
- service.PrivateMessage(message.UserID(), "I have already joined that server.")
- return
- }
- log.Println("Error joining %s %v", service.Name(), err)
- return
- }
- service.PrivateMessage(message.UserID(), "I have joined that server.")
- }
- }
- }
-}
-
-// New creates a new direct message invite plugin.
-func New() bruxism.Plugin {
- p := bruxism.NewSimplePlugin("DirectMessageInvite")
- p.LoadFunc = directMessageInviteLoadFunc
- p.MessageFunc = directMessageInviteMessageFunc
- return p
-}
@@ -10,8 +10,15 @@ import (
var userIDRegex = regexp.MustCompile("<@!?([0-9]*)>")
+func avatarLoadFunc(bot *bruxism.Bot, service bruxism.Service, data []byte) error {
+ if service.Name() != bruxism.DiscordServiceName {
+ panic("DiscordAvatar plugin only supports Discord.")
+ }
+ return nil
+}
+
func avatarMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
- if service.Name() == bruxism.DiscordServiceName && !service.IsMe(message) {
+ if !service.IsMe(message) {
if bruxism.MatchesCommand(service, "avatar", message) {
query := strings.Join(strings.Split(message.RawMessage(), " ")[1:], " ")
@@ -42,7 +49,8 @@ func avatarHelpFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.M
// New creates a new discordavatar plugin.
func New() bruxism.Plugin {
- p := bruxism.NewSimplePlugin("discordavatar")
+ p := bruxism.NewSimplePlugin("DiscordAvatar")
+ p.LoadFunc = avatarLoadFunc
p.MessageFunc = avatarMessageFunc
p.HelpFunc = avatarHelpFunc
return p
View
@@ -12,10 +12,12 @@ type helpPlugin struct {
Private map[string]bool
}
+// Name returns the name of the service.
func (p *helpPlugin) Name() string {
return "Help"
}
+// Help returns a list of help strings that are printed when the user requests them.
func (p *helpPlugin) Help(bot *Bot, service Service, message Message, detailed bool) []string {
privs := service.SupportsPrivateMessages() && !service.IsPrivate(message) && (service.IsBotOwner(message) || service.IsModerator(message))
if detailed && !privs {
Oops, something went wrong.

0 comments on commit be821ae

Please sign in to comment.