mirror of
https://github.com/uhIgnacio/EmoteManager.git
synced 2024-08-15 02:23:13 +00:00
stats: fix reloading the cog (discord token is popped after launch)
This commit is contained in:
parent
e284b9ee62
commit
8739902754
2 changed files with 5 additions and 4 deletions
4
bot.py
4
bot.py
|
@ -15,6 +15,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
|
@ -42,6 +43,9 @@ class Bot(Bot):
|
|||
config = eval(f.read(), {})
|
||||
|
||||
super().__init__(config=config, **kwargs)
|
||||
# allow use of the bot's user ID before ready()
|
||||
token_part0 = self.config['tokens']['discord'].partition('.')[0].encode()
|
||||
self.user_id = int(base64.b64decode(token_part0 + b'=' * (3 - len(token_part0) % 3)))
|
||||
|
||||
def process_config(self):
|
||||
"""Load the emojis from the config to be used when a command fails or succeeds
|
||||
|
|
|
@ -23,10 +23,7 @@ class Stats(BotBinStats):
|
|||
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.
|
||||
# on_ready() hasn't run yet, so we don't have self.bot.user.
|
||||
token = self.bot.config['tokens']['discord']
|
||||
user_id = token.partition('.')[0]
|
||||
self.shlist = ShareableList(seq, name=f'emote-manager-{user_id}')
|
||||
self.shlist = ShareableList(seq, name=f'emote-manager-{self.bot.user_id}')
|
||||
|
||||
def is_opener(self):
|
||||
"""return whether this is the process that should open the shared memory"""
|
||||
|
|
Loading…
Reference in a new issue