async def fetch_from_redis(self, bot: CustomBot) -> str: """Fetches information for the given user from the redis cache""" async with bot.redis() as re: self.name = await re.get(f"UserName-{self.user_id}") self.age = 0 self.fetch_when_expired = True # We can't trust redis forever if self.name is None: return await self.fetch_from_api(bot) return self.name
async def fetch_from_api(self, bot: CustomBot) -> str: """Fetches information for the given user from the Discord API""" # Grab user data try: data = await bot.fetch_user(self.user_id) except (discord.Forbidden, discord.NotFound): self.name = "Deleted User" self.age = -1 # This should never change babey self.fetch_when_expired = True else: self.name = str(data) self.age = 0 self.fetch_when_expired = False # Push it to redis async with bot.redis() as re: await re.set(f"UserName-{self.user_id}", self.name) # Return data return self.name
def setup(bot: CustomBot): x = Hidden(bot) bot.add_cog(x)
def setup(bot:CustomBot): x = HotColdCommands(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = CalebOnly(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = EmancipateRandomText(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = ProposeRandomText(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = MoneyCommands(bot) bot.add_cog(x)
from glob import glob from discord import Game from cogs.utils.custom_bot import CustomBot bot = CustomBot(default_prefix='.', pm_help=True, run_giveaway=True) # List all files in the Cogs directory that end in .py extensions = [] cog_files = glob('./cogs/[!_]*.py') + glob('./cogs/games/[!_]*.py') for filepath in cog_files: file = filepath.replace('\\', '/').replace('/', '.') # Linux + Windows compatible filename = file[2:-3] # Remove .py and ./ extensions.append(filename) @bot.event async def on_ready(): print('Booted and ready for action') print(' - {0.user}'.format(bot)) print(' - {0.user.id}'.format(bot)) await bot.run_database_setup() print('Loading extensions...') for ext in extensions: try: bot.load_extension(ext) print(' - Loaded extension', ext) except Exception as e:
def setup(bot:CustomBot): x = GoogleAnalytics(bot) if '' in list(bot.config['google_analytics'].values()): x.log_handler.error("Google Analytics authorization not set in config - not loading cog.") else: bot.add_cog(x)
def setup(bot: CustomBot): x = LeaveEvent(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = AdoptRandomText(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = OwnerCommands(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = ConnectionEvent(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = GoogleAnalytics(bot) bot.add_cog(x)
def setup(bot:CustomBot): x = Marriage(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = ProfileVerification(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = CommandEvent(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = Misc(bot) bot.add_cog(x)
def setup(bot:CustomBot): x = Simulation(bot) bot.add_cog(x)
parser.add_argument("--sslport", type=int, default=8443, help="The port to run the SSL webserver on.") args = parser.parse_args() # Create bot object shard_ids = None if args.shardcount == None else list( range(args.min, args.max + 1)) if args.shardcount == None and (args.min or args.max): raise Exception("You set a min/max shard handler but no shard count") bot = CustomBot( config_file=args.config_file, activity=Game(name="Restarting..."), status=Status.dnd, commandline_args=args, case_insensitive=True, shard_count=args.shardcount, shard_ids=shard_ids, shard_id=args.min, ) # Create website object - don't start based on argv app = Application(loop=bot.loop, debug=True) app.add_routes(api_routes) app.router.add_static('/static', getcwd() + '/website/static') app['bot'] = bot app['static_root_url'] = '/static' jinja_setup(app, loader=FileSystemLoader(getcwd() + '/website/templates')) session_setup(app, ECS(token_bytes(32))) if __name__ == '__main__':
def setup(bot:CustomBot): x = DiceDuelCommands(bot) bot.add_cog(x)
def setup(bot:CustomBot): x = RollCommands(bot) bot.add_cog(x)
def setup(bot:CustomBot): x = GuildEvent(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = ErrorEvent(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = ServerSpecific(bot) bot.add_cog(x)
def setup(bot:CustomBot): x = JoinEvent(bot) bot.add_cog(x)
def setup(bot: CustomBot): bot.remove_command('help') x = Help(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = TicketCommands(bot) bot.add_cog(x)
def setup(bot: CustomBot): x = DatabaseCommands(bot) bot.add_cog(x)