Beispiel #1
0
    async def do_work(self) -> int:
        await self.click(Work.selector(), 3)
        await self.browser.wait_for(".imp.yellow.tip")

        soup = await self.get_soup()
        energy, energy_cooldown_time = Status.check_energy(soup)
        gold = Work.check_region_gold(soup)

        if not Work.can_work(soup):
            LOG.info("Working is not possible")
            return 600

        if gold > 0 and energy >= 10:
            try:
                await self.click(Work.work_selector(), 3)
                await self.click(utils.close_selector(), 3)
                LOG.info("Work is completed {} energys use to work".format(energy))
            except Exception as err:
                LOG.debug(err)
                LOG.error("Can not work, maybe the factory owner doesn't have enough money?")
                return 600
        elif gold > 0 and energy_cooldown_time == 0 and int(self.perks['END'][0]) >= 50:
            await self.click(Status.energy_bar_selector(), 3)
        else:
            if int(self.perks['END'][0]) < 50:
                return 600
            elif gold == 0:
                LOG.info("Region lack of gold")
                return 600
            elif energy >= 10 or energy_cooldown_time == 0:
                LOG.error("Some error occurred in work")
                return 600
            return energy_cooldown_time

        return await self.do_work()
Beispiel #2
0
 async def do_military_training(self) -> int:
     try:
         await self.click(War.selector(), 1)
         await self.click(War.military_training_selector(), 1)
         await self.click(War.send_ok_selector(), 1)
         await self.click(utils.close_selector(), 2)
         LOG.info("Military training completed")
     except Exception as err:
         LOG.debug(err)
         LOG.error("Military training failed")
     return 3598
Beispiel #3
0
 async def do_perks_upgrade(self) -> int:
     LOG.debug("Do perks upgrade")
     await self.click(Overview.selector(),
                      wait_for='#chat input[name=name]')
     t = await self.calculate_perks_time()
     LOG.debug(f'countdown {t/3600:.2f} hours')
     if t == 0:
         perk = Perks.perk_strategy(**self.perks)
         await self.upgrade(perk)
         return 600
     else:
         return t
Beispiel #4
0
async def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument("-l", "--login_method", help="登入選項: 'GOOGLE'、'FB'、'VK'", dest='login_method')
    parser.add_argument(
        "-u",
        "--use_to_upgrade",
        help='''升級道具: 'RRCash'、'GOLD'、'GOLD1' 預設使用 RRCash
        1. 'GOLD' 當GOLD小於4320將會改用RRCash
        2. 'GOLD1' 同1,並且對於upgrade_strategy中的最小值會使用RRCash升級
        例如: "2:1:1" STR將會使用GOLD, EDU, END將會使用RRCash 也就是窮人的選擇''',
        default='RRCash',
        dest='use_to_upgrade'
    )
    parser.add_argument("-p", "--profile", help="帳戶profile: 預設為'default', 修改可更換帳戶", default='default', dest='profile')

    parser.add_argument("--poor", help="你是窮人, 你買不起高級會員, 你必須手動挖礦、軍演, 可憐哪 我來幫你", action="store_true")

    parser.add_argument("--headless", help="確定使用者有登入成功後可開啟 將瀏覽器GUI關閉節省資源", action="store_true", dest='headless')

    parser.add_argument("--proxy", help="正確格式如下: socks5://localhost:1080, https://localhost:1080", dest='proxy')

    parser.add_argument(
        "--upgrade_strategy", help="三圍100後將按照時間比例來升級 default '2:1:1'", default='2:1:1', dest="upgrade_strategy"
    )
    parser.add_argument("--debug", help="開啟Debug mod", action="store_true")

    args = parser.parse_args()
    if (args.login_method is None):
        parser.print_help()
    else:
        initLog(args.profile, DEBUG=args.debug)

        while (True):
            try:
                r = None
                if args.poor is True:
                    from app.poorbot import PoorBot
                    r = await PoorBot(**vars(args))
                else:
                    from app.rrbot import RRBot
                    r = await RRBot(**vars(args))

                await r.start()
                break
            except Exception as err:
                LOG.debug('Bot detect error: {}'.format(err))
                # Due to "browser.close" sometime not working, use kill child processes instead.
                kill_child_processes(os.getpid())
                if r:
                    await r.quit()

                LOG.info('Restarting...')
Beispiel #5
0
 async def check_login(self):
     LOG.debug("check login")
     try:
         await self.browser.wait_for('() => {return c_html;}',
                                     timeout=10000)
         LOG.debug("check login successed")
     except Exception:
         LOG.debug("check login failed")
         await self.login()
Beispiel #6
0
    async def do_storage_supply(self):
        LOG.debug("Do storage supply")
        await self.click(Storage.selector(),
                         wait_for="span[action='leader/storage']")

        soup = BeautifulSoup((await self.browser.content()), "html5lib")

        # Produce energy drink
        if int(
                soup.find("span", {
                    "urlbar": str(Storage.Energydrink.value)
                }).text.replace('.', '')) <= 3600:
            await self.click(Storage.selector(Storage.Energydrink.value), 3)
            gold, _ = Status.check_money(await self.get_soup())

            # 6 hours ~ 24 hours
            amount = random.randrange(10800, 43200, 1000)
            if gold < amount / 10:
                amount = gold * 10

            if amount > 300:
                await self.type('.storage_produce_ammount', str(amount))
                await self.click('.storage_produce_button', 3)
                LOG.info('Produced: energy drink {} pcs.'.format(amount))

        need_products = [(Storage.Bombers, 10000), (Storage.Moontanks, 10000),
                         (Storage.Spacestations, 1280)]

        # Buy products
        for pair in need_products:
            product, number = pair
            if int(
                    soup.find("span", {
                        "urlbar": str(product.value)
                    }).text.replace('.', '')) < number:
                await self.buy_product(product, number)
Beispiel #7
0
    async def login(self):
        LOG.debug("Login")
        await self.browser.goto(self.uri, waitUntil='networkidle0')
        selectors = {
            'FB': '.sa_link[href*="facebook.com"]',
            'GOOGLE': '.sa_link[href*="google.com"]',
            'VK': '.sa_link[href*="vk.com"]'
        }
        try:
            LOG.debug("Try login")
            await self.browser.click(selectors[self.login_method])
            await self.browser.wait_for_response('https://rivalregions.com/',
                                                 timeout=240000)
            await self.browser.wait_for('#chat input[name=name]',
                                        timeout=10000)
            name = await self.browser.query_selector_eval(
                '#chat input[name=name]', 'node => node.value')
            LOG.info("Login success {}".format(name))
            await self.save_cookies()
        except Exception as err:
            LOG.debug(err)

        await self.check_login()
Beispiel #8
0
 async def refresh(self):
     LOG.debug("refresh")
     await self.browser.reload(waitUntil='networkidle0')