本文整理匯總了Golang中github.com/nmeum/marvin/irc.Client類的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Load
func (m *Module) Load(client *irc.Client) error {
if len(m.URL) <= 0 {
return nil
}
duration, err := time.ParseDuration(m.Interval)
if err != nil {
return err
}
if err := m.updateHandler(client); err != nil {
return err
}
if m.api.API != apiVersion {
return errors.New("unsupported spaceapi version")
}
go func(c *irc.Client) {
for {
time.Sleep(duration)
m.updateHandler(c)
}
}(client)
client.CmdHook("privmsg", m.statusCmd)
return nil
}
示例2: helpCmd
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.")
}
示例3: notify
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)
}
}
示例4: tweetCmd
func (m *Module) tweetCmd(client *irc.Client, msg irc.Message) error {
splited := strings.Fields(msg.Data)
if len(splited) < 2 || splited[0] != "!tweet" || !client.Connected(msg.Receiver) {
return nil
}
status := strings.Join(splited[1:], " ")
return m.tweet(status, url.Values{}, client, msg)
}
示例5: timeCmd
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))
}
示例6: Load
func (m *Module) Load(client *irc.Client) error {
regex, err := regexp.Compile(m.RegexStr)
if err != nil {
return err
}
m.regex = regex
client.CmdHook("privmsg", m.urlCmd)
return nil
}
示例7: tweet
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
}
}
示例8: notify
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)
}
}
示例9: modulesCmd
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)
}
示例10: directMsgCmd
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
}
示例11: moduleCmd
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())
}
示例12: Load
func (m *Module) Load(client *irc.Client) error {
if len(m.Password) <= 0 {
return nil
}
client.CmdHook("notice", func(c *irc.Client, msg irc.Message) error {
if msg.Sender.Name != m.NickServ || !strings.Contains(msg.Data, m.Keyword) {
return nil
}
return c.Write("PRIVMSG %s :identify %s",
m.NickServ, m.Password)
})
return nil
}
示例13: replyCmd
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)
}
示例14: Load
func (m *Module) Load(client *irc.Client) error {
duration, err := time.ParseDuration(m.Timeout)
if err != nil {
return err
}
client.CmdHook("kick", func(c *irc.Client, msg irc.Message) error {
if msg.Data != client.Nickname {
return nil
}
time.Sleep(duration)
return c.Write("JOIN %s", strings.Fields(msg.Receiver)[0])
})
return nil
}
示例15: favoriteCmd
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
}