當前位置: 首頁>>代碼示例>>Golang>>正文


Golang irc.Client類代碼示例

本文整理匯總了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
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:28,代碼來源:spacestatus.go

示例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.")
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:8,代碼來源:modules.go

示例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)
	}
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:8,代碼來源:feed.go

示例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)
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:9,代碼來源:twitter.go

示例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))
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:9,代碼來源:time.go

示例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
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:11,代碼來源:url.go

示例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
	}
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:11,代碼來源:twitter.go

示例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)
	}
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:15,代碼來源:spacestatus.go

示例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)
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:15,代碼來源:modules.go

示例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
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:16,代碼來源:twitter.go

示例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())
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:16,代碼來源:modules.go

示例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
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:16,代碼來源:nickserv.go

示例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)
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:17,代碼來源:twitter.go

示例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
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:17,代碼來源:rejoin.go

示例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
}
開發者ID:feuerrot,項目名稱:marvin,代碼行數:18,代碼來源:twitter.go


注:本文中的github.com/nmeum/marvin/irc.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。