Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telethon import TelegramClient, sync
- from telethon.tl.functions.messages import GetHistoryRequest
- from time import sleep
- from re import findall
- import socks
- botname = 'BastionSiegeBot'
- period = 300 # Время большой паузы
- period_hop = 10 # Промежуток, через который выводятся сообщения во время большой паузы
- message_wait = 1 # Пауза между сообщениями
- people_reserve_percent = 0.5
- api_id =
- api_hash = ""
- phone_number = ""
- nick_name = ""
- proxy = (socks.SOCKS5, "exp1.s5overss.mtpro.xyz", 39610, False, "mtpro_xyz", "mtpro_xyz_bot")
- client = TelegramClient("iv1982", api_id, api_hash, proxy=proxy)
- client.start()
- if not client.is_user_authorized():
- client.send_code_request(phone_number)
- client.sign_in(phone_number, input('Enter the code: '))
- entity = client.get_input_entity(botname)
- status = {'people': 0, 'army': 0, 'gold': 0, 'wood': 0, 'stone': 0, 'food': 0, 'archers': 0, 'trebuchete_workers': 0,
- 'trebuchet_workers_max': 0, 'town_hall_level': 0, 'houses_level': 0, 'houses_people_max': 0,
- 'storage_level': 0, 'storage_workers': 0, 'storage_workers_max': 0, 'barraks_level': 0, 'army_max': 0,
- 'wall_level': 0, 'archers_max': 0, 'wall_durability': 0, 'wall_durability_max': 0, 'sawmill_level': 0,
- 'sawmill_workers': 0, 'sawmill_workers_max': 0, 'mine_level': 0, 'mine_workers': 0, 'mine_workers_max': 0,
- 'farm_level': 0, 'farm_workers': 0, 'farm_workers_max': 0, 'trebuchete_level': 0, 'change': 0, 'wood_max': 0,
- 'stone_max': 0, 'food_max': 0, 'storage_full_price': 0, 'storage_upgrade_gold': 0, 'storage_upgrade_wood': 0,
- 'storage_upgrade_stone': 0, 'town_hall_upgrade_gold': 0, 'town_hall_upgrade_wood': 0,
- 'town_hall_upgrade_stone': 0, 'houses_upgrade_gold': 0, 'houses_upgrade_wood': 0, 'houses_upgrade_stone': 0,
- 'gold_max': 0, 'gold_income': 0, 'people_income': 0}
- def get_message():
- result = client(GetHistoryRequest(
- entity,
- limit=1,
- offset_date=None,
- offset_id=0,
- max_id=0,
- min_id=0,
- add_offset=0,
- hash = 0
- ))
- message = result.messages[0].message
- return message
- def update_status():
- message = get_message()
- split = findall('\w+', message)
- # print('\n Split:', split)
- newstatus = status
- newstatus['change'] = 0
- if len(split) < 6:
- if split[0] == 'Выбери' and split[1] == 'количество':
- return status
- badcount = 1
- while len(split) < 6:
- if badcount > 6:
- print('Break! Split: ', split)
- return status
- print('не найден ответ!: ', split, '\nЖдем ', badcount, ':')
- sleep(5)
- message = get_message()
- split = findall('\w+', message)
- badcount += 1
- if split[0] == nick_name:
- people, armyn, gold, wood, stone, food = 0, 0, 0, 0, 0, 0
- if 'Жители' in split:
- people_index = split.index('Жители')
- people = int(split[people_index + 1])
- if 'Армия' in split:
- army_index = split.index('Армия')
- armyn = int(split[army_index + 1])
- if 'Золото' in split:
- gold_index = split.index('Золото')
- gold = int(split[gold_index + 1])
- if 'Дерево' in split:
- wood_index = split.index('Дерево')
- wood = int(split[wood_index + 1])
- if 'Камень' in split:
- stone_index = split.index('Камень')
- stone = int(split[stone_index + 1])
- if 'Еда' in split:
- food_index = split.index('Еда')
- food = int(split[food_index + 1])
- newstatus = {'people': people, 'army': armyn, 'gold': gold, 'wood': wood, 'stone': stone, 'food': food,
- 'change': 1}
- if split[0] == 'Постройки':
- newstatus = {'town_hall_level': int(split[1]), 'houses_level': int(split[5]), 'people': int(split[6]),
- 'houses_people_max': int(split[7]), 'storage_level': int(split[2]),
- 'storage_workers': int(split[3]), 'storage_workers_max': int(split[4]),
- 'barraks_level': int(split[17]), 'army': int(split[18]), 'army_max': int(split[19]),
- 'wall_level': int(split[20]), 'archers': int(split[21]), 'archers_max': int(split[22]),
- 'sawmill_level': int(split[11]), 'sawmill_workers': int(split[12]),
- 'sawmill_workers_max': int(split[13]), 'mine_level': int(split[14]),
- 'mine_workers': int(split[15]),
- 'mine_workers_max': int(split[16]), 'farm_level': int(split[8]), 'farm_workers': int(split[9]),
- 'farm_workers_max': int(split[10]), 'change': 1}
- if split[0] == 'Победы':
- newstatus = {'change': 1, 'wall_durability': int(split[15]), 'wall_durability_max': int(split[16]),
- 'archers': int(split[17]), 'archers_max': int(split[18]), 'trebuchete_workers': int(split[20]),
- 'trebuchet_workers_max': int(split[21]), 'army': int(split[22]), 'army_max': int(split[23]),
- 'food': int(split[24])}
- if split[0] == 'Склад' and split[1] == 'Уровень':
- move = 0
- if split[20] == 'Улучшить':
- move = -2
- newstatus = {'storage_level': int(split[2]), 'storage_workers': int(split[4]),
- 'storage_workers_max': int(split[5]), 'wood': int(split[7]), 'wood_max': int(split[8]),
- 'stone': int(split[9]), 'stone_max': int(split[10]), 'food': int(split[11]),
- 'food_max': int(split[12]), 'gold': int(split[17]), 'people': int(split[19]),
- 'storage_upgrade_gold': int(split[23 + move]), 'storage_upgrade_wood': int(split[24 + move]),
- 'storage_upgrade_stone': int(split[25 + move])}
- if move == 0:
- newstatus.update(storage_full_price=int(split[21]))
- if split[0] == 'Ратуша' and split[1] == 'Уровень':
- newstatus = {'town_hall_level': int(split[2]), 'gold': int(split[4]), 'gold_max': int(split[6]),
- 'gold_income': int(split[7]), 'town_hall_upgrade_gold': int(split[10]),
- 'town_hall_upgrade_wood': int(split[11]), 'town_hall_upgrade_stone': int(split[12])}
- if split[0] == 'Дома' and split[1] == 'Уровень':
- newstatus = {'houses_level': int(split[2]), 'people': int(split[4]), 'houses_people_max': int(split[5]),
- 'people_income': int(split[6]), 'houses_upgrade_gold': int(split[16]),
- 'houses_upgrade_wood': int(split[17]), 'houses_upgrade_stone': int(split[18])}
- # print('Новый статус', newstatus, '\n')
- return newstatus
- def longwait():
- period_multiplier = period // period_hop
- print('Ждем', period, 'секунд')
- for i in range(0, period_multiplier):
- print('Ждем:', i * period_hop, 'из', period_multiplier * period_hop + period % period_hop)
- sleep(period_hop)
- if period % period_hop:
- sleep(period % period_hop)
- def snd(message):
- print('Отправка сообщения: ', message)
- client.send_message(entity, str(message))
- sleep(message_wait)
- def button(*args):
- print('\n Строка кнопок: ', args)
- btn_text = 'Команда: '
- for btn in args:
- snd(btn)
- status.update(update_status())
- return status
- def forceupdate():
- print('\n\n!Полное обновление!')
- status.update(button('Наверх', 'Постройки', 'Ратуша', 'Назад', 'Склад', 'Назад', 'Дома', 'Наверх', 'Война', 'Наверх'))
- return status
- def buyres():
- print('\n\n!Приобретение ресурсов.')
- status.update(button('Наверх'))
- difwood = status['wood_max'] - status['wood']
- difstone = status['stone_max'] - status['stone']
- diffood = status['food_max'] - status['food']
- difall = difwood + difstone + diffood
- if diffood > int(status['food_max']/2):
- print('Покупка ', diffood, ' еды!')
- if status['gold']/2 > diffood:
- num = diffood
- else:
- num = int(status['gold']/2)
- status.update(button('Заполнить', 'Купить', 'Еда'))
- snd(num)
- status.update(button('Наверх'))
- diffood = status['food_max'] - status['food']
- difall = difwood + difstone + diffood
- if difall * 6 < status['gold']:
- if difwood > 0 or difstone > 0:
- print('Полный склад')
- status.update(button('Постройки', 'Склад', 'Заполнить'))
- else:
- status.update(button('Торговля', 'Купить'))
- resfund = int(status['gold'] / 2)
- if difwood + difstone < resfund:
- buywood = difwood
- buystone = difstone
- else:
- buywood = 0
- buystone = 0
- if difstone > difwood and difstone - difwood < resfund:
- buywood += difstone - difwood
- resfund -= buywood
- elif difstone < difwood and difwood - difstone < resfund:
- buystone += difwood - difstone
- resfund -= buystone
- buywood += int(resfund / 2)
- buystone += int(resfund / 2)
- if buywood > 0:
- print('Покупка ', buywood, ' дерева!')
- status.update(button('Дерево'))
- snd(buywood)
- status.update(button('Назад'))
- if buystone > 0:
- print('Покупка ', buystone, ' камня!')
- status.update(button('Камень'))
- snd(buystone)
- status.update(button('Назад'))
- status.update(button('Наверх'))
- return status
- def build():
- print('\n\n!Модуль строительства.')
- town_hall = 0
- houses = 0
- storage = 0
- if status['wood'] > status['town_hall_upgrade_wood'] and status['stone'] > status['town_hall_upgrade_stone']:
- town_hall = 1
- if status['gold'] > status['town_hall_upgrade_gold']:
- town_hall = 2
- if town_hall == 1:
- print('Улучшаем ратушу, ждем золото')
- return status
- elif status['wood'] > status['houses_upgrade_wood'] and status['stone'] > status['houses_upgrade_stone']:
- houses = 1
- if status['gold'] > status['houses_upgrade_gold']:
- houses = 2
- if houses == 1:
- print('Улучшаем дома, ждем золото')
- return status
- elif status['wood'] > status['storage_upgrade_wood'] and status['stone'] > status['storage_upgrade_stone']:
- storage = 1
- if status['gold'] > status['storage_upgrade_gold']:
- storage = 2
- if storage == 1:
- print('Улучшаем склад, ждем золото')
- return status
- if town_hall == 2 or houses == 2 or storage == 2:
- status.update(button('Наверх', 'Постройки'))
- if town_hall == 2:
- print('Строим ратушу.')
- status.update(button('Ратуша', 'Улучшить', 'Наверх'))
- buyres()
- return status
- elif houses == 2:
- print('Строим дома.')
- status.update(button('Дома', 'Улучшить', 'Наверх'))
- buyres()
- return status
- elif storage == 2:
- print('Строим склад.')
- status.update(button('Склад', 'Улучшить', 'Наверх'))
- buyres()
- return status
- return status
- def army():
- print('\n\n!Модуль армии.')
- status.update(button('Наверх'))
- print('Армия: ', status['army'], ' Максимальная армия: ', status['army_max'], ' Людей: ', status['people'], ' максимум людей: ',
- status['houses_people_max'])
- difarmy = status['army_max'] - status['army']
- peoplespace = int(status['people'] - status['houses_people_max'] * people_reserve_percent)
- if peoplespace > 0 and difarmy > 0:
- if difarmy > peoplespace:
- num = peoplespace
- else:
- num = difarmy
- print('Набираем ', num, ' солдат.')
- status.update(button('Война', 'Обучить', 'Казармы'))
- snd(num)
- status.update(button('Наверх'))
- return status
- loop = 0
- while True:
- if loop % 10 == 0:
- status.update(forceupdate())
- print('Обновленный статус', status, '\n')
- else:
- status.update(button('Наверх'))
- if status['army'] < status['army_max'] and status['people'] > 0:
- status.update(army())
- if status['wood'] < status['wood_max'] or status['stone'] < status['stone_max'] or status['food_max'] - \
- status["food"] > 100000:
- status.update(buyres())
- min_build_gold = min(status['town_hall_upgrade_gold'], status['houses_upgrade_gold'],
- status['storage_upgrade_gold'])
- if status['gold'] > min_build_gold:
- status.update(build())
- client.disconnect()
- longwait()
- client.connect()
- loop += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement