From 60f81b5a72e4b6cb1d15fd476ee33d739f404c52 Mon Sep 17 00:00:00 2001 From: io mintz Date: Tue, 16 Feb 2021 06:39:34 +0000 Subject: [PATCH] remove stats cog --- bot.py | 1 - cogs/stats.py | 74 ------------------------------------------ data/config.example.py | 5 --- 3 files changed, 80 deletions(-) delete mode 100644 cogs/stats.py diff --git a/bot.py b/bot.py index 0dd9c0c..1def630 100755 --- a/bot.py +++ b/bot.py @@ -32,7 +32,6 @@ class Bot(Bot): startup_extensions = ( 'cogs.emote', 'cogs.meta', - 'cogs.stats', 'bot_bin.debug', 'bot_bin.misc', 'bot_bin.systemd', diff --git a/cogs/stats.py b/cogs/stats.py deleted file mode 100644 index e71a912..0000000 --- a/cogs/stats.py +++ /dev/null @@ -1,74 +0,0 @@ -# © 2020 io mintz -# -# Emote Manager is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Emote Manager is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Emote Manager. If not, see . - -from multiprocessing.shared_memory import ShareableList - -from discord.ext import commands -from bot_bin.stats import BotBinStats - -class Stats(BotBinStats): - def __init__(self, bot): - super().__init__(bot) - seq = [0] * self.bot.shard_count if self.is_opener() else None - # Use our user ID as part of the shm name - # to allow running multiple instances of the bot on the same machine. - # The shard count is incorporated to prevent the following situation: - # - Shard count is increased in the launcher script / unit file from 30 to 33 - # - All clusters are restarted - # - Clusters begin using the old 30-element-long list to store their shard counts, - # but because some clusters that haven't restarted yet are still using the old shlist. - shm_name = f'emote-manager-{self.bot.user_id}-{self.bot.shard_count}' - self.shlist = ShareableList(seq, name=shm_name) - self.count() - - def is_opener(self): - """return whether this is the process that should open the shared memory""" - return 0 in self.bot.shard_ids - - def is_reporter(self): - """return whether we should report stats to the bot lists""" - return self.bot.shard_count - 1 in self.bot.shard_ids - - def cog_unload(self): - self.shlist.shm.close() - if self.is_opener(): - self.shlist.shm.unlink() - - @commands.Cog.listener() - async def on_ready(self): - self.count() - if self.is_reporter(): - await self.send() - - def count(self): - for shard_id in self.bot.shard_ids: - self.shlist[shard_id] = 0 - - for guild in self.bot.guilds: - self.shlist[guild.shard_id] += 1 - - @commands.Cog.listener() - async def on_guild_join(self, guild): - self.shlist[guild.shard_id] += 1 - - @commands.Cog.listener() - async def on_guild_remove(self, guild): - self.shlist[guild.shard_id] -= 1 - - async def guild_count(self): - return sum(self.shlist) - -def setup(bot): - bot.add_cog(Stats(bot)) diff --git a/data/config.example.py b/data/config.example.py index e896ba6..8e015af 100644 --- a/data/config.example.py +++ b/data/config.example.py @@ -11,11 +11,6 @@ 'tokens': { 'discord': 'sek.rit.token', - 'stats': { - 'bots.discord.pw': None, - 'discordbots.org': None, - 'botsfordiscord.com': None, - }, }, 'ignore_bots': {