func (m *Module) notify(client *irc.Client, post post) { ftitle := html.UnescapeString(post.Feed.Title) for _, ch := range client.Channels { ititle := html.UnescapeString(post.Item.Title) client.Write("NOTICE %s :%s -- %s new entry %s: %s", ch, strings.ToUpper(m.Name()), ftitle, ititle, post.Item.Link) } }
func (m *ModuleSet) helpCmd(client *irc.Client, msg irc.Message) error { if msg.Data != "!help" { return nil } return client.Write("NOTICE %s :%s", msg.Receiver, "Use !help MODULE to see the help message for the given module, use !modules to list all modules.") }
func (m *Module) timeCmd(client *irc.Client, msg irc.Message) error { if msg.Data != "!time" { return nil } now := time.Now().UTC() return client.Write("NOTICE %s :%s", msg.Receiver, now.Format(m.Format)) }
func (m *Module) tweet(t string, v url.Values, c *irc.Client, p irc.Message) error { _, err := m.api.PostTweet(t, v) if err != nil && len(t) > maxChars { return c.Write("NOTICE %s :ERROR: Tweet is too long, remove %d characters", p.Receiver, len(t)-maxChars) } else if err != nil { return c.Write("NOTICE %s :ERROR: %s", p.Receiver, err.Error()) } else { return nil } }
func (m *ModuleSet) modulesCmd(client *irc.Client, msg irc.Message) error { if msg.Data != "!modules" || len(m.modules) <= 0 { return nil } var names []string for _, module := range m.modules { names = append(names, module.Name()) } help := fmt.Sprintf("The following modules are available: %s", strings.Join(names, ", ")) return client.Write("NOTICE %s :%s", msg.Receiver, help) }
func (m *Module) notify(client *irc.Client, open bool) { var oldState, newState string if open { oldState = "closed" newState = "open" } else { oldState = "open" newState = "closed" } for _, ch := range client.Channels { client.Write("NOTICE %s :%s changed door status from %s to %s", ch, m.api.Space, oldState, newState) } }
func (m *ModuleSet) moduleCmd(client *irc.Client, msg irc.Message) error { splited := strings.Fields(msg.Data) if len(splited) < 2 || splited[0] != "!help" { return nil } name := strings.ToLower(splited[1]) module := m.findModule(name) if module == nil { return client.Write("NOTICE %s :Module %q isn't installed", msg.Receiver, name) } return client.Write("NOTICE %s :%s: %s", msg.Receiver, module.Name(), module.Help()) }
func (m *Module) directMsgCmd(client *irc.Client, msg irc.Message) error { splited := strings.Fields(msg.Data) if len(splited) < 3 || splited[0] != "!directmsg" || !client.Connected(msg.Receiver) { return nil } scname := splited[1] status := strings.Join(splited[2:], " ") if _, err := m.api.PostDMToScreenName(status, scname); err != nil { return client.Write("NOTICE %s :ERROR: %s", msg.Receiver, err.Error()) } return nil }
func (m *Module) replyCmd(client *irc.Client, msg irc.Message) error { splited := strings.Fields(msg.Data) if len(splited) < 3 || splited[0] != "!reply" || !client.Connected(msg.Receiver) { return nil } status := strings.Join(splited[2:], " ") if !strings.Contains(status, "@") { return client.Write("NOTICE %s :ERROR: %s", msg.Receiver, "A reply must contain an @mention") } values := url.Values{} values.Add("in_reply_to_status_id", splited[1]) return m.tweet(status, values, client, msg) }
func (m *Module) favoriteCmd(client *irc.Client, msg irc.Message) error { splited := strings.Fields(msg.Data) if len(splited) < 2 || splited[0] != "!favorite" || !client.Connected(msg.Receiver) { return nil } id, err := strconv.Atoi(splited[1]) if err != nil { return err } if _, err := m.api.Favorite(int64(id)); err != nil { return client.Write("NOTICE %s :ERROR: %s", msg.Receiver, err.Error()) } return nil }
func (m *Module) statusCmd(client *irc.Client, msg irc.Message) error { if msg.Data != "!spacestatus" { return nil } else if m.api == nil { return client.Write("NOTICE %s :Status currently unknown.", msg.Receiver) } var state string if m.api.State.Open { state = "open" } else { state = "closed" } return client.Write("NOTICE %s :%s is currently %s", msg.Receiver, m.api.Space, state) }
func (m *Module) statCmd(client *irc.Client, msg irc.Message) error { splited := strings.Fields(msg.Data) if len(splited) < 2 || splited[0] != "!stat" || !client.Connected(msg.Receiver) { return nil } id, err := strconv.Atoi(splited[1]) if err != nil { return err } tweet, err := m.api.GetTweet(int64(id), url.Values{}) if err != nil { return err } return client.Write("NOTICE %s :Stats for tweet %d by %s: ↻ %d ★ %d", msg.Receiver, tweet.Id, tweet.User.ScreenName, tweet.RetweetCount, tweet.FavoriteCount) }
func (m *Module) urlCmd(client *irc.Client, msg irc.Message) error { url := m.regex.FindString(msg.Data) if len(url) <= 0 { return nil } resp, err := http.Head(url) if err != nil { return err } resp.Body.Close() // HEAD response doesn't have a body info := m.infoString(resp) if len(info) <= 0 { return nil } return client.Write("NOTICE %s :%s", msg.Receiver, info) }
func (m *Module) notify(client *irc.Client, text string) { for _, ch := range client.Channels { client.Write("NOTICE %s :%s", ch, text) } }