async def req(self): if not hasattr(self.bot, "logging_emotes") or self.bot.logging_emotes == {}: beginning_time = time.time() try: emotes = dataIO.load_json("logging_emotes.json") setattr(self.bot, "logging_emotes", emotes) end_time = time.time() tts = math.ceil((end_time - beginning_time) * 1000) print( f"Retrieved {str(len(bot.emotes))} emotes in {str(tts)} ms" ) except Exception as e: sendWebhookMessage( message= f"Cluster {str(self.bot.CLUSTER_ID)} EMOJI Error: `{str(e)}`", webhookurl= "https://canary.discordapp.com/api/webhooks/430691452826288130/XbXQ-6PYPM1wfBUlkQRGTQtVEgnZMqHmqI8TGmn_hNgPrasUh4KSCp05kcgLZ1-jIVt8" ) try: await self.bot.get_requests(self) except Exception as e: sendWebhookMessage( message= f"Cluster {str(self.bot.CLUSTER_ID)} CC Error: `{str(e)}`", webhookurl="")
def setup(bot): setattr(bot, "logging_emotes", dataIO.load_json("logging_emotes.json")) WelcomerInit(bot) bot.add_cog(SyncHandler(bot)) setattr(bot, "running", False) setattr(bot, "handler_ready", True) setattr(bot, "reload_data", WelcomerInit.reload_data) setattr(bot, "update_data", WelcomerInit.update_data) setattr(bot, "get_elevated", WelcomerInit.get_elevated) setattr(bot, "get_invites", WelcomerInit.get_invites) setattr(bot, "get_mutual", WelcomerInit.get_mutual) setattr(bot, "mutual_servers", WelcomerInit.mutual_servers) setattr(bot, "get_guild_invite", WelcomerInit.get_guild_invite) setattr(bot, "extractEmotes", WelcomerInit.extractEmotes) setattr(bot, "extractUserInfo", WelcomerInit.extractUserInfo) setattr(bot, "extractGuildInfo", WelcomerInit.extractGuildInfo) setattr(bot, "get_all_mutual", WelcomerInit.get_all_mutual) setattr(bot, "get_mutual", WelcomerInit.get_mutual) setattr(bot, "create_transaction", WelcomerInit.create_transaction) setattr(bot, "is_elevated", WelcomerInit.is_elevated) setattr(bot, "done", dict())
async def on_ready(self): self.bot.uptime = datetime.now() emotes = dataIO.load_json("logging_emotes.json") setattr(self.bot, "logging_emotes", emotes) if not bot.TEST_MODE: sendWebhookMessage( message= f":white_small_square: | Cluster **{str(bot.CLUSTER_ID)}** has restarted", webhookurl="")
def get_server_info(id): id = str(id) if id in bot.cache['server_info']: if "timeout" in bot.cache['server_info'][id]: if int(time.time()) < bot.cache['server_info'][id]['timeout']: bot.cache['server_info'][id]['timeout'] = int(time.time()) + 600 # Resets timer so it doesnt unload every 5 minutes, but only if not used in 5 minutes return bot.cache['server_info'][id]['content'] bot.cache['server_info'][id] = dict() if not os.path.exists("Servers/" + str(id) + ".json"): shutil.copy("default_server_config.json","Servers/" + str(id) + ".json") print("Added server " + str(id) + " to database") try: bot.cache['server_info'][id]['content'] = dataIO.load_json("Servers/" + str(id) + ".json") bot.cache['server_info'][id]['timeout'] = int(time.time()) + 600 return bot.cache['server_info'][id]['content'] except: print("CANT LOAD SVR " + id)
async def reload(self, ctx): """Reload config from file""" userInfo, guildInfo = self.bot.get_guild_user_info(ctx) if (ctx.message.author.guild_permissions.administrator ) or (ctx.message.author.id == ctx.message.guild.owner.id) or (str( ctx.message.author.id) in guildInfo['staff-members']) or (str( ctx.message.author.id) in self.bot.specialRoles['staff']): taskStart = datetime.now() self.bot.cache['server_info'][str( ctx.message.guild.id)]['content'] = dataIO.load_json( "Servers/" + str(ctx.message.guild.id) + ".json") taskEnd = datetime.now() taskLength = taskEnd - taskStart embed = discord.Embed( description="Task completed in " + str((taskLength.seconds * 1000000 + taskLength.microseconds) / 1000) + "ms.") await ctx.send(embed=embed) else: await ctx.message.add_reaction("\N{NO ENTRY}")
import psutil import rethinkdb as r import requests import sys import time import traceback r.set_loop_type("asyncio") global bot global data global connection global loadedmodules loadedmodules = dict() data = dataIO.load_json("data.json") token = dataIO.load_json("token.json")['token'] uptime = datetime.now() handler_ready = False # Enable affinity p = psutil.Process() all_cpus = list(range(psutil.cpu_count())) p.cpu_affinity(all_cpus) print(p.cpu_affinity()) # Arguments args = sys.argv if len(args) < 4: print(f"{args[0]} <shard count> <cluster count> <cluster id> <test mode>") sys.exit()
async def reload_data(self, name): try: dat = dataIO.load_json(name) return True, dat except: return False, {}
def __init__(self, bot): self.bot = bot self.running = False self.bot.logging_emotes = dataIO.load_json("logging_emotes.json")
async def specialrolesreload(self, ctx): if is_owner(ctx): bot.specialRoles = dataIO.load_json("special_roles.json")
p = psutil.Process() all_cpus = list(range(psutil.cpu_count())) p.cpu_affinity(all_cpus) print(p.cpu_affinity()) os.system("taskset -p 0xff %d" % os.getpid()) global bot print("shards: " + str(ushards)) print("count: " + str(len(ushards))) print("total: " + str(len(ushards) * int(sys.argv[4]))) bot = commands.AutoShardedBot(command_prefix="+", pm_help=True, shard_ids=ushards, shard_count=len(ushards) * int(sys.argv[4])) global blockedusers blockedusers = dataIO.load_json("blacklist.json") global botStart botStart = datetime.now() sys.argv print(sys.argv) ttw = (int(sys.argv[2]) - int(sys.argv[1])) * 5 * int(sys.argv[3]) print("Waiting " + str(ttw) + " seconds") time.sleep(ttw) setattr(bot, "uptime", botStart) setattr(bot, "get_user", bot.get_user_info) def is_owner(ctx):
from DataIO import dataIO import os total = len(os.listdir("Servers")) current = 0 for ext in os.listdir("Servers"): ext = ext[:-5] if os.path.exists("Images/custom_" + ext + ".png"): info = dataIO.load_json("Servers/" + ext + ".json") info['welcomer']['background'] = "custom_" + ext dataIO.save_json("Servers/" + ext + ".json",info) print(str(current) + "/" + str(total) + " :" + ext) current += 1
def reload_data(): try: bot.data = dataIO.load_json("data.json") return True except: return False