<commit_before>import json
import logging
import aiohttp

logging.basicConfig(format='[%(levelname)s] - %(message)s', level=logging.INFO)
config = json.load(open('config.json'))

class Stats:
  def __init__(self, bot):
    self.bot = bot
    self.payload = json.dumps({
      'server_count': len(self.bot.guilds)
    })
  async def listpost(self):
    session = aiohttp.ClientSession()
    if config['dbotsorg'] == False:
      logging.info('not posting to discordbots.org')
    else:
      dbl_headers = {
        'Authorization': config['dbl'],
        'Content-Type': 'application/json'
      }
      dbl_url = 'https://discordbots.org/api/bots/' + config['botid'] + '/stats'
      async with session.post(dbl_url, data=self.payload, headers=dbl_headers) as dbl_resp:
        if dbl_resp.status == 200:
          logging.info('dbl: posted!')
        else:
          logging.info(f'dbl: something weird happened: code {dbl_resp.status}.')                                                   

    if config['dbotspw'] == False:
      logging.info('not posting to bots.discord.pw')
    else:
      headers = {
        'Authorization': config['dbots'],
        'Content-Type': 'application/json'
      }
      dbots_url = 'https://bots.discord.pw/api/bots/' + config['botid'] + '/stats'
      async with session.post(dbots_url, data=self.payload, headers=headers) as resp:
        assert resp.status == 200
        logging.info('dbots: posted!')

  async def on_guild_join( self, guild ):
    logging.info('Joined guild "' + str(guild.name) + '" ID: ' + str(guild.id))
    await listpost()

  async def on_guild_remove( self, guild ):
    logging.info('Left ' + str(guild.name))
    await listpost()

def setup(bot):
  bot.add_cog(Stats(bot))<commit_msg>[cogs, stats] thonk<commit_after>import json
import logging
import aiohttp

logging.basicConfig(format='[%(levelname)s] - %(message)s', level=logging.INFO)
config = json.load(open('config.json'))

class Stats:
  async def listpost(self):
    session = aiohttp.ClientSession()
    if config['dbotsorg'] == False:
      logging.info('not posting to discordbots.org')
    else:
      dbl_headers = {
        'Authorization': config['dbl'],
        'Content-Type': 'application/json'
      }
      dbl_url = 'https://discordbots.org/api/bots/' + config['botid'] + '/stats'
      async with session.post(dbl_url, data=self.payload, headers=dbl_headers) as dbl_resp:
        if dbl_resp.status == 200:
          logging.info('dbl: posted!')
        else:
          logging.info(f'dbl: something weird happened: code {dbl_resp.status}.')                                                   

    if config['dbotspw'] == False:
      logging.info('not posting to bots.discord.pw')
    else:
      headers = {
        'Authorization': config['dbots'],
        'Content-Type': 'application/json'
      }
      dbots_url = 'https://bots.discord.pw/api/bots/' + config['botid'] + '/stats'
      async with session.post(dbots_url, data=self.payload, headers=headers) as resp:
        assert resp.status == 200
        logging.info('dbots: posted!')

  def __init__(self, bot):
    self.bot = bot
    self.payload = json.dumps({
      'server_count': len(self.bot.guilds)
    })
  async def on_guild_join( self, guild ):
    logging.info('Joined guild "' + str(guild.name) + '" ID: ' + str(guild.id))
    await listpost()

  async def on_guild_remove( self, guild ):
    logging.info('Left ' + str(guild.name))
    await listpost()

def setup(bot):
  bot.add_cog(Stats(bot))
{'fraction_non_alphanumeric': 0.14957264957264957, 'fraction_numerical': 0.003418803418803419, 'mean_word_length': 2.771213748657358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '859751', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1147, 'n_words': 233}