コード例 #1
0
ファイル: leaguerank.py プロジェクト: sgaweda/troybot
    def league_rank(self, bot, source, message, **rest):
        try:
            from riotwatcher import RiotWatcher, LoLException
        except ImportError:
            log.error(
                "Missing required module for League Rank module: riotwatcher")
            return False

        riot_api_key = self.settings["riot_api_key"]
        summoner_name = self.settings["default_summoner"]
        def_region = self.settings["default_region"]

        if len(riot_api_key) == 0:
            log.error("Missing riot API key in settings.")
            return False

        region_list = [
            "br", "eune", "euw", "kr", "lan", "las", "na", "oce", "ru", "tr"
        ]

        if message:
            summoner_name = message.split()[0]
            try:
                region = message.split()[1].lower()
            except IndexError:
                region = def_region.lower()

            if region not in region_list:
                bot.whisper(
                    source,
                    f"Region is not valid. Please enter a valid region, region is optional and the default region is {def_region.upper()}",
                )
                return False
            else:
                pass
        else:
            region = def_region.lower()

        if len(summoner_name) == 0 or len(region) == 0:
            return False

        error_404 = "Game data not found"
        error_429 = "Too many requests"

        try:
            rw = RiotWatcher(riot_api_key, default_region=region)

            summoner = rw.get_summoner(name=summoner_name)
            summoner_id = str(summoner["id"])
            summoner_name = summoner["name"]

        except LoLException as e:
            if e == error_429:
                bot.say(
                    f"Too many requests. Try again in {e.headers['Retry-After']} seconds"
                )
                return False
            elif e == error_404:
                bot.say(
                    "The summoner not found. Use a valid summoner name (remove spaces) and region FailFish"
                )
                return False
            else:
                log.info(f"Something unknown went wrong: {e}")
                return False

        try:
            summoner_league = rw.get_league_entry(summoner_ids=(summoner_id, ))

            tier = summoner_league[summoner_id][0]["tier"]
            division = summoner_league[summoner_id][0]["entries"][0][
                "division"]
            league_points = summoner_league[summoner_id][0]["entries"][0][
                "leaguePoints"]

            bot.say(
                f"The Summoner {summoner_name} on region {region.upper()} is currently in {tier} {division} with {league_points} LP 4Head"
            )
        except LoLException as e:
            if e == error_429:
                bot.say(
                    f"Too many requests. Try again in {e.headers['Retry-After']} seconds"
                )
                return False
            elif e == error_404:
                bot.say(
                    f"The Summoner {summoner_name} on region {region.upper()} is currently UNRANKED.. FeelsBadMan"
                )
                return False
            else:
                bot.say(
                    "Trouble fetching summoner rank.. Kappa Try again later!")
                return False
コード例 #2
0
ファイル: leaguerank.py プロジェクト: SanderVDA/pajbot
    def league_rank(self, **options):
        try:
            from riotwatcher import RiotWatcher, LoLException
        except ImportError:
            log.error('Missing required module for League Rank module: riotwatcher')
            return False

        source = options['source']
        message = options['message']
        bot = options['bot']

        riot_api_key = self.settings['riot_api_key']
        summoner_name = self.settings['default_summoner']
        def_region = self.settings['default_region']

        if len(riot_api_key) == 0:
            log.error('Missing riot API key in settings.')
            return False

        region_list = ['br', 'eune', 'euw', 'kr', 'lan', 'las', 'na', 'oce', 'ru', 'tr']

        if message:
            summoner_name = message.split()[0]
            try:
                region = message.split()[1].lower()
            except IndexError:
                region = def_region.lower()

            if region not in region_list:
                bot.whisper(source.username, 'Region is not valid. Please enter a valid region, region is optional and the default region is {}'.format(def_region.upper()))
                return False
            else:
                pass
        else:
            region = def_region.lower()

        if len(summoner_name) == 0 or len(region) == 0:
            return False

        error_404 = 'Game data not found'
        error_429 = 'Too many requests'

        try:
            rw = RiotWatcher(riot_api_key, default_region=region)

            summoner = rw.get_summoner(name=summoner_name)
            summoner_id = str(summoner['id'])
            summoner_name = summoner['name']

        except LoLException as e:
            if e == error_429:
                bot.say('Too many requests. Try again in {} seconds'.format(e.headers['Retry-After']))
                return False
            elif e == error_404:
                bot.say('The summoner not found. Use a valid summoner name (remove spaces) and region FailFish')
                return False
            else:
                log.info('Something unknown went wrong: {}'.format(e))
                return False

        try:
            summoner_league = rw.get_league_entry(summoner_ids=(summoner_id, ))

            tier = summoner_league[summoner_id][0]['tier']
            division = summoner_league[summoner_id][0]['entries'][0]['division']
            league_points = summoner_league[summoner_id][0]['entries'][0]['leaguePoints']

            bot.say('The Summoner {} on region {} is currently in {} {} with {} LP 4Head'.format(summoner_name, region.upper(), tier, division, league_points))
        except LoLException as e:
            if e == error_429:
                bot.say('Too many requests. Try again in {} seconds'.format(e.headers['Retry-After']))
                return False
            elif e == error_404:
                bot.say('The Summoner {} on region {} is currently UNRANKED.. FeelsBadMan'.format(summoner_name, region.upper()))
                return False
            else:
                bot.say('Trouble fetching summoner rank.. Kappa Try again later!')
                return False
コード例 #3
0
ファイル: leaguerank.py プロジェクト: polle-vanhoof/pajbot
    def league_rank(self, **options):
        try:
            from riotwatcher import RiotWatcher, LoLException
        except ImportError:
            log.error('Missing required module for League Rank module: riotwatcher')
            return False

        source = options['source']
        message = options['message']
        bot = options['bot']

        riot_api_key = self.settings['riot_api_key']
        summoner_name = self.settings['default_summoner']
        def_region = self.settings['default_region']
        region_list = ['br', 'eune', 'euw', 'kr', 'lan', 'las', 'na', 'oce', 'ru', 'tr']

        if message:
            summoner_name = message.split()[0]
            try:
                region = message.split()[1].lower()
            except IndexError:
                region = def_region.lower()

            if region not in region_list:
                bot.whisper(source.username, 'Region is not valid. Please enter a valid region, region is optional and the default region is {}'.format(def_region.upper()))
                return False
            else:
                pass
        else:
            region = def_region.lower()

        error_404 = "Game data not found"
        error_429 = "Too many requests"

        try:
            rw = RiotWatcher(riot_api_key, default_region=region)

            summoner = rw.get_summoner(name=summoner_name)
            summoner_id = str(summoner['id'])
            summoner_name = summoner['name']

        except LoLException as e:
            if e == error_429:
                bot.say('Too many requests. Try again in {} seconds'.format(e.headers['Retry-After']))
                return False
            elif e == error_404:
                bot.say('The summoner not found. Use a valid summoner name (remove spaces) and region FailFish')
                return False

        try:
            summoner_league = rw.get_league_entry(summoner_ids=(summoner_id, ))

            tier = summoner_league[summoner_id][0]['tier']
            division = summoner_league[summoner_id][0]['entries'][0]['division']
            league_points = summoner_league[summoner_id][0]['entries'][0]['leaguePoints']

            bot.say('The Summoner {} on region {} is currently in {} {} with {} LP 4Head'.format(summoner_name, region.upper(), tier, division, league_points))
        except LoLException as e:
            if e == error_429:
                bot.say('Too many requests. Try again in {} seconds'.format(e.headers['Retry-After']))
                return False
            elif e == error_404:
                bot.say('The Summoner {} on region {} is currently UNRANKED.. FeelsBadMan'.format(summoner_name, region.upper()))
                return False
            else:
                bot.say('Trouble fetching summoner rank.. Kappa Try again later!')
                return False