コード例 #1
0
    def __init__(self):
        super().__init__(command_prefix=os.getenv('PREFIX', '>'))
        self.session = aiohttp.ClientSession(loop=self.loop)
        self.mongo = AsyncIOMotorClient(os.getenv('MONGO'))
        self.statsy_mongo = AsyncIOMotorClient(os.getenv('STATSYMONGO'))
        self.client = clashroyale.OfficialAPI(
            os.getenv('CLASHROYALE'), is_async=True, session=self.session, timeout=10, url=os.getenv('SERVER')
        )

        self.remove_command('help')
        self.add_command(self.ping)
        self.add_command(self._eval)

        protected = ('cogs.logging', 'cogs.levelling')

        for i in os.listdir('cogs'):
            if i.endswith('.py'):
                cog_name = 'cogs.' + i.replace('.py', '')
                if os.name == 'nt' and cog_name in protected:
                    continue
                try:
                    self.load_extension(cog_name)
                except Exception as e:
                    traceback.print_exc()
                else:
                    print(f'Loaded: {cog_name}')

        self.run(os.getenv('TOKEN'), activity=discord.Game("for Stu's Army!"))
コード例 #2
0
ファイル: clashroyale.py プロジェクト: VeraButler/statsy
    def __init__(self, bot):
        self.bot = bot
        self.conv = TagCheck()
        self.cache = TTLCache(500, 180)
        scopes = [
            "https://www.googleapis.com/auth/userinfo.email",
            "https://www.googleapis.com/auth/firebase.database"
        ]
        self.firebase = ServiceAccountCredentials.from_json_keyfile_dict(
            json.loads(b64decode(os.getenv('firebase')).decode()),
            scopes=scopes)

        try:
            constants = json.loads(
                requests.get('https://fourjr.herokuapp.com/cr/constants').text)
        except json.JSONDecodeError:
            constants = None
        self.cr = clashroyale.OfficialAPI(
            os.getenv('clashroyale'),
            session=self.bot.session,
            is_async=True,
            timeout=20,
            constants=constants,
            url=
            f"http://{os.getenv('spike')}/redirect?url=https://api.clashroyale.com/v1"
        )
        self.royaleapi = clashroyale.RoyaleAPI(os.getenv('royaleapi'),
                                               session=self.bot.session,
                                               is_async=True,
                                               timeout=20)

        if not self.bot.dev_mode:
            self.bot.clan_update = self.bot.loop.create_task(
                self.clan_update_loop())
コード例 #3
0
 def __init__(self, bot):
     self.bot = bot
     self.auth = self.bot.get_cog('crtools').auth
     self.tags = self.bot.get_cog('crtools').tags
     self.clans = self.bot.get_cog('crtools').clans
     self.constants = self.bot.get_cog('crtools').constants
     self.clash = clashroyaleAPI.OfficialAPI(self.auth.getOfficialToken(),
                                             is_async=True)
コード例 #4
0
ファイル: duels.py プロジェクト: marshy2591/Legend-Cogs
 def __init__(self, bot):
     self.bot = bot
     self.settings = dataIO.load_json(settings_path)
     self.auth = self.bot.get_cog('crtools').auth
     self.tags = self.bot.get_cog('crtools').tags
     self.constants = self.bot.get_cog('crtools').constants
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(), is_async=True)
     self.active = False
コード例 #5
0
ファイル: welcome.py プロジェクト: rodelfard/Legend-Cogs
 def __init__(self, bot):
     self.bot = bot
     self.user_history = {}
     self.welcome = dataIO.load_json('data/legend/welcome.json')
     self.auth = self.bot.get_cog('crtools').auth
     self.tags = self.bot.get_cog('crtools').tags
     self.clans = self.bot.get_cog('crtools').clans
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(), is_async=True)
コード例 #6
0
ファイル: friendlink.py プロジェクト: marshy2591/Legend-Cogs
 def __init__(self, bot):
     self.bot = bot
     self.CRregex = re.compile(r"<?(https?:\/\/)?(www\.)?(link\.clashroyale\.com\/invite\/friend)\b([-a-zA-Z0-9/]*)>?")
     self.BSregex = re.compile(r"<?(https?:\/\/)?(www\.)?(link\.brawlstars\.com\/invite\/friend)\b([-a-zA-Z0-9/]*)>?")
     self.auth = self.bot.get_cog('crtools').auth
     self.tags = self.bot.get_cog('crtools').tags
     self.constants = self.bot.get_cog('crtools').constants
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(), is_async=True)
     self.brawl = brawlstats.Client(self.auth.getBSToken(), is_async=False)
コード例 #7
0
 def __init__(self, bot):
     self.bot = bot
     self.auth = self.bot.get_cog('crtools').auth
     self.clans = self.bot.get_cog('crtools').clans
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(),
                                          is_async=True)
     self.member_log = dataIO.load_json('data/clanlog/member_log.json')
     self.discord_log = dataIO.load_json('data/clanlog/discord_log.json')
     self.last_count = 0
コード例 #8
0
ファイル: shop.py プロジェクト: rodelfard/Legend-Cogs
 def __init__(self, bot):
     self.bot = bot
     self.banks = dataIO.load_json('data/economy/bank.json')
     self.auth = self.bot.get_cog('crtools').auth
     self.tags = self.bot.get_cog('crtools').tags
     self.clans = self.bot.get_cog('crtools').clans
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(),
                                          is_async=True)
     self.session = aiohttp.ClientSession()
コード例 #9
0
ファイル: test_async.py プロジェクト: gogaz/clashroyale
 async def setUp(self):
     self.location_id = ['global', 57000249]  # united states
     self.player_tags = ['#2P0LYQ', '#2PP']
     self.clan_tags = ['#9Q8PYRLL', '#8LQ2P0RL']
     self.tournament_tags = ['#2PPV2VUL', '#20RUCV8Q']
     self.cr = clashroyale.OfficialAPI(TOKEN,
                                       url=URL,
                                       is_async=True,
                                       loop=self.loop,
                                       timeout=30)
コード例 #10
0
    async def initialize(self):
        crapikey = await self.bot.get_shared_api_tokens("crapi")
        if crapikey["api_key"] is None:
            raise ValueError("The Clash Royale API key has not been set.")
        self.crapi = clashroyale.OfficialAPI(crapikey["api_key"], is_async=True)

        ofcbsapikey = await self.bot.get_shared_api_tokens("ofcbsapi")
        if ofcbsapikey["api_key"] is None:
            raise ValueError("The Official Brawl Stars API key has not been set.")
        self.ofcbsapi = brawlstats.Client(ofcbsapikey["api_key"], is_async=True)
コード例 #11
0
ファイル: refresher.py プロジェクト: jykntr/wartracker
    def __init__(self, clan_tag: str, key: str, api: str,
                 sleep_seconds: int) -> None:
        self.clan_tag: str = clan_tag
        self.key: str = key
        self.sleep_seconds = sleep_seconds
        self.api = api

        if api.lower() == ROYALE_API:
            self.client = clashroyale.RoyaleAPI(key, is_async=False)
        else:
            self.client = clashroyale.OfficialAPI(key, is_async=False)
コード例 #12
0
 def __init__(self, bot):
     self.bot = bot
     self.auth = self.bot.get_cog('crtools').auth
     self.clans = self.bot.get_cog('crtools').clans
     self.constants = self.bot.get_cog('crtools').constants
     self.deck = Deck(self.bot)
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(),
                                          is_async=True,
                                          timeout=20)
     self.moment = time.time()
     self.completed = [[], []]
コード例 #13
0
ファイル: clanlog.py プロジェクト: zihadmahiuddin/Legend-Cogs
 def __init__(self, bot):
     self.bot = bot
     self.auth = self.bot.get_cog('crtools').auth
     self.clans = self.bot.get_cog('crtools').clans
     self.clubs = self.bot.get_cog('crtools').clubs
     self.tags = self.bot.get_cog('crtools').tags
     self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(), is_async=True)
     self.brawl = brawlstats.Client(self.auth.getBSToken(), is_async=False)
     self.member_log = dataIO.load_json('data/clanlog/member_log.json')
     self.bs_member_log = dataIO.load_json('data/clanlog/bs_member_log.json')
     self.discord_log = dataIO.load_json('data/clanlog/discord_log.json')
     self.last_count = 0
     self.bs_last_count = 0
コード例 #14
0
 def __init__(self):
     self.loop = asyncio.get_event_loop()
     self.session = aiohttp.ClientSession(loop=self.loop)
     self.client = clashroyale.OfficialAPI(os.environ['api_token'],
                                           is_async=True,
                                           timeout=10,
                                           session=self.session,
                                           url=os.environ['server'])
     self.log = logging.getLogger('cr-tournament-finder')
     self.mongo = AsyncIOMotorClient(os.environ['mongo'])
     self.is_closed = False
     try:
         self.loop.run_until_complete(self.poll())
     except KeyboardInterrupt:
         self.is_closed = True
         self.close()
コード例 #15
0
    def __init__(self, bot):
        self.bot = bot
        self.settings = dataIO.load_json(settings_path)
        self.cards = dataIO.load_json(cards_path)
        self.auth = self.bot.get_cog('crtools').auth
        self.tags = self.bot.get_cog('crtools').tags
        self.constants = self.bot.get_cog('crtools').constants
        self.clash = clashroyale.OfficialAPI(self.auth.getOfficialToken(), is_async=True)

        # init card data
        self.cards_abbrev = {}

        for k, v in self.cards.items():
            for value in v:
                self.cards_abbrev[value] = k
            self.cards_abbrev[k] = k
コード例 #16
0
    async def initialize(self):
        crapikey = await self.bot.db.api_tokens.get_raw(
            "crapi", default={"api_key": None})
        if crapikey["api_key"] is None:
            raise ValueError(
                "The Clash Royale API key has not been set. Use [p]set api crapi api_key,YOURAPIKEY"
            )
        self.crapi = clashroyale.OfficialAPI(crapikey["api_key"],
                                             is_async=True)

        bsapikey = await self.bot.db.api_tokens.get_raw(
            "bsapi", default={"api_key": None})
        if bsapikey["api_key"] is None:
            raise ValueError(
                "The Brawl Stars API key has not been set. Use [p]set api bsapi api_key,YOURAPIKEY"
            )
        self.bsapi = brawlstats.Client(bsapikey["api_key"], is_async=True)
コード例 #17
0
ファイル: cr.py プロジェクト: VerySmolDuck/LAcogs
 async def initialize(self):
     crapikey = await self.bot.get_shared_api_tokens("crapi")
     if crapikey["api_key"] is None:
         raise ValueError("The Clash Royale API key has not been set.")
     self.crapi = clashroyale.OfficialAPI(crapikey["api_key"],
                                          is_async=True)