async def avrae(dhttp): # set up a way for us to send events to Avrae # monkey-patch in .message bot.message = message.__get__(bot, type(bot)) # add error event listener bot.add_listener(on_command_error, "on_command_error") # set up http bot.http = dhttp # noinspection PyProtectedMember bot._connection.http = dhttp bot.state = "run" await bot.login(config.TOKEN) # handled by our http proxy # we never do initialize the websocket - we just replay discord's login sequence # to initialize a "channel" to send testing messages to # in this case, we initialize a testing guild and dummy DMChannel # noinspection PyProtectedMember bot._connection.parse_ready(DUMMY_READY) # noinspection PyProtectedMember bot._connection.parse_guild_create(DUMMY_GUILD_CREATE) # noinspection PyProtectedMember bot._connection.parse_channel_create(DUMMY_DMCHANNEL_CREATE) log.info("Ready for testing") yield bot await bot.logout()
async def avrae(dhttp, mock_ldclient): # set up a way for us to send events to Avrae # monkey-patch in .message and .add_reaction bot.message = message.__get__(bot, type(bot)) bot.add_reaction = add_reaction.__get__(bot, type(bot)) # add error event listener bot.add_listener(on_command_error, "on_command_error") # set up http bot.http = dhttp # noinspection PyProtectedMember bot._connection.http = dhttp # feature flags monkey-patch bot.ldclient = mock_ldclient bot.state = "run" await bot.login(config.TOKEN) # handled by our http proxy # we never do initialize the websocket - we just replay discord's login sequence # to initialize a "channel" to send testing messages to # in this case, we initialize a testing guild and dummy DMChannel # noinspection PyProtectedMember bot._connection.parse_ready(DUMMY_READY) # noinspection PyProtectedMember bot._connection.parse_guild_create(DUMMY_GUILD_CREATE) # noinspection PyProtectedMember bot._connection.add_dm_channel(DUMMY_DMCHANNEL_CREATE) # noinspection PyProtectedMember # used to allow the delay_ready task to progress bot._connection.shards_launched.set() log.info("Ready for testing") yield bot await bot.close()