-
Notifications
You must be signed in to change notification settings - Fork 8
Python
Jake edited this page Jul 28, 2017
·
6 revisions
"""
BOTLIST DUMPER.
:copyright: (c) 2017 Jakeoid.
:license: MIT, see LICENSE.md for details.
"""
# DISCORD
import discord
# HOUSEKEEPING
import json
import time
import datetime
# VARIABLES
client = discord.AutoShardedClient()
ignore_guilds = [
110373943822540800,
264445053596991498
]
startTime = time.time()
info = "\u001b[0m[ \u001b[32;1mINFO \u001b[0m]"
# EDITME
token = ""
trigger_amt = 0.6
print(f'{info} The bot has begun, give it some time to run.')
@client.event
async def on_ready():
"""Called when the bot is ready for Discord."""
blacklist = []
for guild in [guild for guild in client.guilds if len(list(filter(lambda member: member.bot, guild.members))) / len(guild.members) >= trigger_amt]:
if guild.id not in ignore_guilds:
print(f'{info} Dumping information for {guild.name} ({guild.id})')
blacklist.append(guild)
else:
print(f'{info} Ignoring whitelisted guild {guild.name} ({guild.id})')
print(f'{info} Generating JSON file..')
json_output = {}
for guild in blacklist:
ts = time.time()
json_output[str(guild.id)] = {
'id': guild.id,
'name': guild.name,
'totalMembers': len(guild.members),
'userAccounts': len(list(filter(lambda m: m.bot, guild.members))),
'botAccounts': len(list(filter(lambda m: not m.bot, guild.members))),
'percentageBots': len(list(filter(lambda m: m.bot, guild.members))) / len(guild.members),
'timestamp': datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%dT%H:%M:%S-%H:%M'),
'icon': guild.icon_url
}
with open(f'{client.user.name.lower()}.json', 'w') as outfile:
json.dump(json_output, outfile, ensure_ascii=False)
print(f'{info} Finished dumping servers for {client.user.name}#{client.user.discriminator}!')
print(f'{info} Took a total of {time.time() - startTime} seconds!')
await client.logout()
@client.event
async def on_shard_ready(shard):
"""Called when the bots shard is ready for Discord."""
print(f'{info} Shard ready, the shards number is {shard}')
client.run(token)
