当前位置: 首页>>代码示例>>Golang>>正文


Golang Service.ChannelCount方法代码示例

本文整理汇总了Golang中github.com/iopred/bruxism.Service.ChannelCount方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.ChannelCount方法的具体用法?Golang Service.ChannelCount怎么用?Golang Service.ChannelCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/iopred/bruxism.Service的用法示例。


在下文中一共展示了Service.ChannelCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func (p *carbonitexPlugin) Run(bot *bruxism.Bot, service bruxism.Service) {
	for {
		<-time.After(5 * time.Minute)

		http.PostForm("https://www.carbonitex.net/discord/data/botdata.php", url.Values{"key": {p.key}, "servercount": {fmt.Sprintf("%d", service.ChannelCount())}})

		<-time.After(55 * time.Minute)
	}

}
开发者ID:iopred,项目名称:bruxism,代码行数:10,代码来源:carbonitexplugin.go

示例2: StatsCommand

// StatsCommand returns bot statistics.
func StatsCommand(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, command string, parts []string) {
	stats := runtime.MemStats{}
	runtime.ReadMemStats(&stats)

	w := &tabwriter.Writer{}
	buf := &bytes.Buffer{}

	w.Init(buf, 0, 4, 0, ' ', 0)
	if service.Name() == bruxism.DiscordServiceName {
		fmt.Fprintf(w, "```\n")
	}
	fmt.Fprintf(w, "Bruxism: \t%s\n", bruxism.VersionString)
	if service.Name() == bruxism.DiscordServiceName {
		fmt.Fprintf(w, "Discordgo: \t%s\n", discordgo.VERSION)
	}
	fmt.Fprintf(w, "Go: \t%s\n", runtime.Version())
	fmt.Fprintf(w, "Uptime: \t%s\n", getDurationString(time.Now().Sub(statsStartTime)))
	fmt.Fprintf(w, "Memory used: \t%s / %s (%s garbage collected)\n", humanize.Bytes(stats.Alloc), humanize.Bytes(stats.Sys), humanize.Bytes(stats.TotalAlloc))
	fmt.Fprintf(w, "Concurrent tasks: \t%d\n", runtime.NumGoroutine())
	if service.Name() == bruxism.DiscordServiceName {
		discord := service.(*bruxism.Discord)
		fmt.Fprintf(w, "Connected servers: \t%d\n", service.ChannelCount())
		if len(discord.Sessions) > 1 {
			shards := 0
			for _, s := range discord.Sessions {
				if s.DataReady {
					shards++
				}
			}
			if shards == len(discord.Sessions) {
				fmt.Fprintf(w, "Shards: \t%d\n", shards)
			} else {
				fmt.Fprintf(w, "Shards: \t%d (%d connected)\n", len(discord.Sessions), shards)
			}
			guild, err := discord.Channel(message.Channel())
			if err == nil {
				id, err := strconv.Atoi(guild.ID)
				if err == nil {
					fmt.Fprintf(w, "Current shard: \t%d\n", ((id>>22)%len(discord.Sessions) + 1))
				}
			}
		}
	} else {
		fmt.Fprintf(w, "Connected channels: \t%d\n", service.ChannelCount())
	}

	plugins := bot.Services[service.Name()].Plugins
	names := []string{}
	for _, plugin := range plugins {
		names = append(names, plugin.Name())
		sort.Strings(names)
	}

	for _, name := range names {
		stats := plugins[name].Stats(bot, service, message)
		for _, stat := range stats {
			fmt.Fprint(w, stat)
		}
	}

	if service.Name() == bruxism.DiscordServiceName {
		fmt.Fprintf(w, "\n```")
	}

	w.Flush()
	out := buf.String()

	end := ""
	if IsSeptapus {
		end += "Septapus community: <https://discord.gg/HWN9pwj>\nPatreon: <https://www.patreon.com/iopred>\nBuilt with love by iopred."
	}

	if service.SupportsMultiline() {
		if end != "" {
			out += "\n" + end
		}
		service.SendMessage(message.Channel(), out)
	} else {
		service.SendMessage(message.Channel(), strings.Join(strings.Split(out, "\n"), " "))
		service.SendMessage(message.Channel(), strings.Join(strings.Split(end, "\n"), " "))
	}
}
开发者ID:iopred,项目名称:bruxism,代码行数:83,代码来源:statsplugin.go


注:本文中的github.com/iopred/bruxism.Service.ChannelCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。