def set_mode(mode, config): configurator = Configurator(config) config = configurator.from_yaml() if mode not in AVAILABLE_MODES: return 'Wrong mode name' config['mode'] = mode configurator.dump_yaml(config) return 'I change mode to ' + mode
class CubesScreen(Screen): CELLS_ROW = 12 CELLS_COL = 10 def __init__(self, message, bot): super().__init__(message, bot) self.title = 'Select cube position:' self.load_config() self.generate_cubes() def generate_cubes(self): for i in range(1, self.CELLS_ROW): for j in range(1, self.CELLS_COL): attr_name = 'cube_{0}_{1}'.format(i, j) def cube(call, state): self.set_cube_config(call) es = state['EnhanceScreen'] es.render(call=call) return 'EnhanceScreen', es setattr(self, attr_name, cube) return None def set_cube_config(self, call): data = call.data.split('_')[1:] data = data[::-1] self.config['enhancement']['cube'] = data self.configfile.dump_yaml(self.config) self.bot.answer_callback_query(call.id, 'Set cube {0}'.format(data)) def render(self, call=None): self.markup.keyboard = [] self.markup.row_width = self.CELLS_COL for i in range(1, self.CELLS_ROW): line = [] for j in range(1, self.CELLS_COL): title = '{i}:{j}'.format(i=i, j=j) callback = '{name}.cube_{i}_{j}'.format(name=self.name, i=str(i), j=str(j)) line.append( self.InlineKeyboardButton(title, callback_data=callback)) self.markup.row(*line) if call is None: self.send() else: self.edit(call) def load_config(self): self.configfile = Configurator(self.config['enhancer']) self.config = self.configfile.from_yaml()
class BuffScreen(Screen): # another option for future buttons = ['Buff', 'Logout', 'Spawn', 'Back'] def __init__(self, message, bot): super().__init__(message, bot) self.title = 'Buffer menu:' self.load_config() # Try to move this method do Screen class def load_config(self): self.configfile = Configurator(self.config['buffer']) self.config = self.configfile.from_yaml() def back(self, call, state): screen = 'StartScreen' ss = state[screen] ss.render(call=call) return 'StartScreen', ss def buff(self, call, state): self.config['refresh'] = True self.config['logout'] = True self.config['spawn'] = False self.configfile.dump_yaml(self.config) return self.run_action(call) def logout(self, call, state): self.config['spawn'] = True self.config['logout'] = True self.configfile.dump_yaml(self.config) return self.run_action(call) def spawn(self, call, state): self.config['spawn'] = True self.config['logout'] = False self.configfile.dump_yaml(self.config) return self.run_action(call) def run_action(self, call): self.bot.answer_callback_query(call.id, 'Start ' + call.data) Buffer(self.config).process() return self.name, self
class EnhanceScreen(Screen): buttons = ['Cube', 'Binary', 'Combination', 'Disassamble', 'Back'] def __init__(self, message, bot): super().__init__(message, bot) self.title = 'Enhance menu:' self.load_config() self.generate_cycles() def generate_cycles(self): for i in range(4): cycle_id = i+1 attr_name = 'cycle_{0}'.format(cycle_id) def cycle(call, state): data = call.data.split('_')[1] self.config['mode'] = 'single' self.config['enhancement']['cycles'] = data self.config['enhancement']['cube'] = state['CubesScreen'].config['enhancement']['cube'] self.configfile.dump_yaml(self.config) self.bot.answer_callback_query(call.id, 'Start {0} cycles'.format(data)) Enhancer(self.config).process() return self.name, self setattr(self, attr_name, cycle) return None def render(self, call=None): self.markup.keyboard = [] cycles = [] for i in range(1, 5): title = 'Сycles ' + str(i) callback = '{name}.cycle_{i}'.format(name=self.name, i=str(i)) cycles.append(self.InlineKeyboardButton(title, callback_data=callback)) self.markup.row_width = 4 self.markup.add(*cycles) for b in self.buttons: self.markup.add(self.InlineKeyboardButton(b, callback_data='{name}.{action}'.format(name=self.name, action=b.lower()))) if call is None: self.send() else: self.edit(call) def cube(self, call, state): cs = CubesScreen(self.message, self.bot) cs.render(call=call) return cs.name, cs def binary(self, call, state): self.config['enhancement']['cube'] = state['CubesScreen'].config['enhancement']['cube'] self.config['mode'] = 'binary' self.configfile.dump_yaml(self.config) Enhancer(self.config).process() return self.name, self def combination(self, call, state): cs = CombinationScreen(self.message, self.bot) cs.render(call=call) return cs.name, cs def disassamble(self, call, state): self.config['enhancement']['cube'] = state['CubesScreen'].config['enhancement']['cube'] self.config['mode'] = 'disassamble' Enhancer(self.config).process() return self.name, self def back(self, call, state): screen = 'StartScreen' ss = state[screen] ss.render(call=call) return 'StartScreen', ss def load_config(self): self.configfile = Configurator(self.config['enhancer']) self.config = self.configfile.from_yaml()
class FarmScreen(Screen): def __init__(self, message, bot): super().__init__(message, bot) self.title = 'Famring options:' self.load_config() self._init_buttons() # Try to move this method do Screen class def load_config(self): self.configfile = Configurator(self.config['farming']) self.config = self.configfile.from_yaml() # print(self.config) def back(self, call, state): screen = 'StartScreen' ss = state[screen] ss.render(call=call) return 'StartScreen', ss def stop(self, call, state): Config().disable() return None, None def _init_buttons(self): for b in self.config['presets']: name = 'farm_{0}'.format(b['name']) def handle(call, state): data = call.data.split('_')[1] preset = self._findPreset(data) a = preset['actions'] t = preset['timings'] print('call key', data, a, t) Farming(a, t).run() return None, None setattr(self, name, handle) return None def render(self, call=None): self.markup.keyboard = [] for i in self.config['presets']: title = '{0}'.format(i['name']) callback = '{name}.farm_{executor}'.format(name=self.name, executor=str(title)) self.markup.add( self.InlineKeyboardButton(title, callback_data=callback)) self.markup.add( self.InlineKeyboardButton('STOP', callback_data='{0}.{1}'.format( self.name, 'stop'))) self.markup.add( self.InlineKeyboardButton('BACK', callback_data='{0}.{1}'.format( self.name, 'back'))) if call is None: self.send() else: self.edit(call) def _findPreset(self, name): for p in self.config['presets']: if p['name'] == name: return p return []
class Enhancer: def __init__(self, config): self.config = Configurator(config) self.config = self.config.from_yaml() self.combination_cfg = self.config['combination'] self.config = self.config['enhance'] # enhancement _enhance_move for enhancing, _open_move - for open items def enhancement(self): # firstly get enhancement matrix matrix = self._slice_matrix_by_config() current_item_enhance = [] for line in matrix: for cell in line: current_item_enhance += self._enhance_move(cell).get_flow() return current_item_enhance def _slice_matrix_by_config(self): scope = self.config['scope'] max_x = self.config['max']['horizontal'] first_line = scope['start'] last_line = scope['end'] matrix = self.get_matrix() result = [] first_line_points = matrix[first_line[1] - 1][first_line[0] - 1:max_x] # get first line result.append(first_line_points) body = matrix[first_line[1]:last_line[1] - 1] for b in body: result.append(b) last_line_points = matrix[last_line[1] - 1][:last_line[0]] result.append(last_line_points) return result def _enhance_move(self, cell): return EnhanceFlow(cell, self.config) def enhance(self, flow): loops = [] for i in range(self.config['cycles']): loops += flow() return loops def _get_click(self, _x, _y): values = self.get_matrix() _x -= 1 _y -= 1 return Click(values[_y][_x][0], values[_y][_x][1], process='dclick') def get_matrix(self): values = [] for y in range(self.config['max']['vertical']): values.append([]) for x in range(self.config['max']['horizontal']): delta = self.config['delta'] start_point = self.config['points']['start'] calc_x = delta * x + start_point[0] calc_y = delta * y + start_point[1] values[y].append((calc_x, calc_y)) return values def combination(self): matrix = self.get_matrix() config = self.combination_cfg cell0 = config['cell_0'] cell1 = config['cell_1'] cells = [[cell0[0], cell0[1]], [cell1[0], cell1[1]]] return CombinationFlow(cells, self.combination_cfg).get_flow()
def set_combination_mode(mode, config): configurator = Configurator(config['enhancer']) config = configurator.from_yaml() config['combination']['mode'] = mode configurator.dump_yaml(config)
def set_logout(config): configurator = Configurator(config['buffer']) config = configurator.from_yaml() config['spawn'] = True config['logout'] = True configurator.dump_yaml(config)
def set_buff(params, config): configurator = Configurator(config['buffer']) config = configurator.from_yaml() config['refresh'] = True config['spawn'] = False configurator.dump_yaml(config)
def set_enhance_mode(mode, config): configurator = Configurator(config['enhancer']) config = configurator.from_yaml() config['mode'] = mode configurator.dump_yaml(config)
def set_cycles(params, config): configurator = Configurator(config['enhancer']) config = configurator.from_yaml() config['enhancement']['cycles'] = params configurator.dump_yaml(config)
def set_cube(params, config): configurator = Configurator(config['enhancer']) config = configurator.from_yaml() config['enhancement']['cube'] = [params[0], params[1]] configurator.dump_yaml(config)