def event_in_progress(guild, value, mode): try: guild_t = origin.get_region(guild) path1 = c.GUILD_PATH['kc_tracker.json'].format(guild) path2 = c.GUILD_PATH['kc_tracker_g.ini'] LIST1 = json_manager.get_ini_list(path2, 'CONSTANT1', 'NAME') LIST2 = json_manager.get_ini_list(path2, 'CONSTANT2', 'PRE') DATA1 = json_manager.get_data(path1) COUNTER = 0 for data in DATA1: CHECK = True USERNAME = data['user_rsn'] USERNAME = USERNAME.replace(' ', '%20') while CHECK: USER = hiscores_kc.Hiscores2V(USERNAME, LIST1, LIST2) if USER.getKc(value['event_name']): while CHECK: CHECK = False if data[value['event_name']]: current = server_timer.get_current_time( guild_t) USER_STATS = USER.getKc(value['event_name']) target_keys = [ '{}_current'.format(value['event_name']) ] target_values = [int(USER_STATS['kc'])] json_manager.update(path1, 'user_rsn', data['user_rsn'], target_keys, target_values) client_message = 'Guild id: {} | Guild time: {} | Event: {} | Mode: {} | Rsn: {} | Registration KC: {} | Current KC: {} | Status: {}'.format( guild, current.strftime('%H:%M'), value['event_name'], mode, data['user_rsn'], data[value['event_name']], USER_STATS['kc'], 'KC update') console_interface.console_message( 'KC update', client_message) logger.log_event( guild, 'kc_tracker', c.CLIENT_MESSAGES['kc_tracker_update'], client_message) else: if COUNTER >= 10: CHECK = False COUNTER = 0 else: COUNTER += 1 except Exception as error: exception.error(error)
def event_start(self, guild, value, mode): try: guild_t = origin.get_region(guild) path1 = c.GUILD_PATH['kc_tracker.json'].format(guild) path2 = c.GUILD_PATH['kc_rates.json'].format(guild) path2 = c.GUILD_PATH['kc_tracker_g.ini'] DATA1 = json_manager.get_data(path1) DATA2 = json_manager.get_data(path2) LIST1 = json_manager.get_ini_list(path3, 'CONSTANT1', 'NAME') LIST2 = json_manager.get_ini_list(path3, 'CONSTANT2', 'PRE') current = server_timer.get_current_time(guild_t) COUNTER = 0 USER = None for data in DATA1: CHECK = True USERNAME = data['user_rsn'] USERNAME = USERNAME.replace(' ', '%20') while CHECK: USER = hiscores_kc.Hiscores2V(USERNAME, LIST1, LIST2) if USER.status != 404: if USER.getKc(value['event_name']): while CHECK: CHECK = False if data[value['event_name']]: USER_STATS = USER.getKc( value['event_name']) target_keys = [ '{}_current'.format( value['event_name']) ] target_values = [int(USER_STATS['kc'])] json_manager.update( path1, 'user_rsn', data['user_rsn'], target_keys, target_values) client_message = 'Guild id: {} | Guild time: {} | Event: {} | Mode: {} | Rsn: {} | Registration KC: {} | Current_KC: {} | Status: {}'.format( guild, current.strftime('%H:%M'), value['event_name'], mode, data['user_rsn'], data[value['event_name']], USER_STATS['kc'], 'KC update') console_interface.console_message( 'KC update', client_message) logger.log_event( guild, 'kc_tracker', c.CLIENT_MESSAGES['kc_tracker_update'], client_message) else: if COUNTER >= 10: CHECK = False COUNTER = 0 else: COUNTER += 1 for value2 in DATA2: for key, value3 in value.items(): if key == value['event_name']: if (data['{}_current'.format(value['event_name'])] - data[value['event_name']] ) >= value2[value['event_name']] and value[ 'date_start'] == current.strftime( '%m.%d' ) and value['time_start'] == current.hour: self.reset(value['event_name'], USER, data, current, guild) else: pass if (data['{}_current'.format(value['event_name'])] - data[value['event_name']] ) >= value2[value['event_name']] * 2 and value[ 'date_start'] == current.strftime( '%m.%d') and value[ 'time_start'] + 1 == current.hour: self.reset(value['event_name'], USER, data, current, guild) else: pass if (data['{}_current'.format(value['event_name'])] - data[value['event_name']] ) >= value2[value['event_name']] * 3 and value[ 'date_start'] == current.strftime( '%m.%d') and value[ 'time_start'] + 2 == current.hour: self.reset(value['event_name'], USER, data, current, guild) else: pass if (data['{}_current'.format(value['event_name'])] - data[value['event_name']] ) >= value2[value['event_name']] * 4 and value[ 'date_start'] == current.strftime( '%m.%d') and value[ 'time_start'] + 3 == current.hour: self.reset(value['event_name'], USER, data, current, guild) else: pass if (data['{}_current'.format(value['event_name'])] - data[value['event_name']] ) >= value2[value['event_name']] * 5 and value[ 'date_start'] == current.strftime( '%m.%d') and value[ 'time_start'] + 4 == current.hour: self.reset(value['event_name'], USER, data, current, guild) else: pass if (data['{}_current'.format(value['event_name'])] - data[value['event_name']] ) >= value2['time_start'] + 5 == current.hour: self.reset(value['event_name'], USER, data, current, guild) else: pass except Exception as error: exception.error(error)
async def fun_kcupdate(self, ctx): try: guild_l = await origin.get_language(ctx.guild.id) guild_t = await origin.get_region(ctx.guild.id) path1 = c.GUILD_PATH['kc_tracker.json'].format(ctx.guild.id) path2 = c.GUILD_PATH['event.json'].format(ctx.guild.id) LIST1 = await json_manager.get_data(path1) LIST2 = await json_manager.get_data(path2) LIST3 = self.NAME LIST4 = self.PRE CHECK = True user = self.client.get_user(ctx.author.id) guild_current = await server_timer.get_current_time(guild_t) STATUS1 = False STATUS2 = False EVENT_NAME = [] SAFE_CHECK = 0 MEMBER = None userName = '' for value in LIST1: if value['user_id'] == ctx.author.id: STATUS1 = True userName = value['user_rsn'] MEMBER = value if STATUS1: for value2 in LIST2: if value2['type'] == 3 or value2['type'] == 4: STATUS2 = True EVENT_NAME.append(value2['event_name']) if STATUS2: while CHECK: USERNAME = userName.replace(' ', '%20') USER = hiscores_kc.Hiscores2V(USERNAME, LIST3, LIST4) if USER.status != 404: if USER.getKc(EVENT_NAME[0]): CHECK = False stats_data = USER.getKc(EVENT_NAME[0]) for value in EVENT_NAME: await json_manager.update(path1, 'user_id', ctx.author.id, '{}_current'.format(value), int(stats_data['kc'])) client_message = 'Guild id: {} | Event: {} | RSN: {} | Registration KC: {} | Current KC: {} | Guild time: {} | Status: {}'.format(ctx.guild.id, value, userName, MEMBER[value], stats_data['kc'], guild_current.strftime('%H:%M'), 'KC self update') await console_interface.console_message('KC self update', client_message) await user.send(l.kc_tracker[guild_l]['msg_success_4']) else: SAFE_CHECK += 1 if SAFE_CHECK >= 10: CHECK = False await user.send(l.kc_tracker[guild_l]['msg_error_3']) else: CHECK = False await user.send(l.kc_tracker[guild_l]['msg_error_4'].format(userName)) else: await user.send(l.kc_tracker[guild_l]['msg_2']) else: await user.send(l.kc_tracker[guild_l]['msg_error_5']) except Exception as error: await exception.error(error)
async def fun_kc(self, ctx): try: STATUS = False STRING = str(ctx.message.content).split() path = c.GUILD_PATH['rsn.json'].format(ctx.guild.id) DATA = await json_manager.get_json(path) if len(STRING) >= 2: RSN = None if DATA: for data in DATA: if data['user_id'] == ctx.author.id: STATUS = True RSN_LIST = data['rsn'] RSN_LIST.reverse() RSN = RSN_LIST[0] if STATUS: path1 = c.PRIVATE_PATH['maNothing_KC_mod.ini'] ini = await ini_manager.get_ini(path1) LIST1 = await json_manager.get_ini_list( path1, 'CONSTANT1', 'NAME') LIST3 = await json_manager.get_ini_list( path1, 'CONSTANT1', 'PRE') LIST2 = await json_manager.get_ini_list( path1, 'CONSTANT2', 'PNG') RSN = RSN.replace(' ', '%20') self.hiscores2V = hiscores_kc.Hiscores2V( RSN, LIST1, LIST3) RSN = RSN.replace('%20', ' ') BOSS_NAME = '' for text in STRING[1:]: BOSS_NAME += '{} '.format(text) BOSS_NAME = BOSS_NAME.rstrip() boss = self.hiscores2V.getKc(BOSS_NAME) if boss: await origin.get_locale() INFO_PANEL_IMAGE = ini['CONSTANT2']['INFO_PANEL'] FONT_PATH = ini['CONSTANT2']['FONT'] INFO_PANEL_OBJECT = None for index, name in enumerate(LIST1): if name == boss['boss']: INFO_PANEL_OBJECT = LIST2[index] with Image.open(INFO_PANEL_IMAGE).convert( 'RGBA') as im: with Image.open(INFO_PANEL_OBJECT).convert( 'RGBA') as im2: size1 = im.size size2 = im2.size y = int(size1[1] / 2) - int(size2[1] / 2) im.paste(im2, (18, y), im2) draw = ImageDraw.Draw(im) font = ImageFont.truetype(FONT_PATH, 16) draw.text((85, y + 6), 'MANO RSN: ', (165, 165, 165), font=font) draw.text((85, y + 20), 'BOSAS: ', (165, 165, 165), font=font) draw.text((85, y + 33), 'KC: ', (165, 165, 165), font=font) draw.text((85, y + 46), 'RANKAS: ', (165, 165, 165), font=font) draw.text((145, y + 6), '{}'.format(RSN), (255, 255, 255), font=font) draw.text((128, y + 20), '{}'.format(boss['boss']), (255, 255, 255), font=font) draw.text((108, y + 33), '{}'.format( locale.format_string( '%d', int(boss['kc']), grouping=True)), (255, 255, 255), font=font) draw.text((135, y + 46), '{}'.format( locale.format_string( '%d', int(boss['rank']), grouping=True)), (255, 255, 255), font=font) TEMP_FILE = '{}_{}_{}.png'.format( RSN, boss['boss'], boss['kc']) im.save(TEMP_FILE, 'PNG') rank = open(TEMP_FILE, 'rb') await ctx.send(file=discord.File(rank)) rank.close() await file_manager.delete_file(TEMP_FILE) else: await ctx.send( '\🔴 *Patikra nepavyko. Bosas pavadinimu {} nerastas sistemoje. Norint pasižiūrėti bosų sąrašą, rašykite komandą* `.bosslist`' .format(BOSS_NAME)) else: await ctx.send( '\🔴 *Patikra nepavyko. Jūsų RSN nerastas sistemoje. Prašome užregistruoti RSN ir bandykite dar kartą. Komanda* `.rsn`' ) else: await ctx.send( '\🔴 *Patikra nepavyko. Jūsų RSN nerastas sistemoje. Prašome užregistruoti RSN ir bandykite dar kartą. Komanda* `.rsn`' ) else: await ctx.send('\🟢 *Pavyzdys* _**.kc Vorkath**_') except Exception as error: await exception.error(error)
async def fun_akc(self, ctx): try: guild_l = await origin.get_language(ctx.guild.id) STRING = str(ctx.message.content).split(' ') if len(STRING) >= 2: path = c.CLIENT_PATH['guild'] + str(ctx.guild.id) + c.CLIENT_JSON['server'] path1 = c.GUILD_PATH['kc_tracker.json'].format(ctx.guild.id) path2 = c.GUILD_PATH['event.json'].format(ctx.guild.id) server_config = await json_manager.get_json(path) LIST1 = await json_manager.get_data(path1) LIST2 = await json_manager.get_data(path2) LIST3 = self.NAME LIST4 = self.PRE CHECK = True user = self.client.get_user(ctx.author.id) STATUS1 = False STATUS2 = False EVENT_NAME = [] EVENT_NAME2 = None EVENT_LIST_DATA = [] SAFE_CHECK = 0 userName = '' for name in STRING[1:]: userName += '{} '.format(name) userName = userName.replace('_', ' ') userName = userName.rstrip() for value in LIST1: if value['user_id'] == ctx.author.id or value['user_rsn'] == userName: STATUS1 = True if not STATUS1: for value2 in LIST2: if value2['type'] >= 3: STATUS2 = True EVENT_NAME.append(value2['event_name']) SUM = value2['participants'] + 1 EVENT_LIST_DATA.append({'id': value2['id'], 'type': value2['type'], 'sum': SUM}) if STATUS2: while CHECK: USERNAME = userName.replace(' ', '%20') USER = hiscores_kc.Hiscores2V(USERNAME, LIST3, LIST4) USERNAME = USERNAME.replace('%20', ' ') if USER.status != 404: if USER.getKc(EVENT_NAME[0]): CHECK = False stats_data = USER.getKc(EVENT_NAME[0]) json_string = {'user_id': ctx.author.id, 'user_username': ctx.author.mention, 'user_rsn': userName} for value in EVENT_NAME: json_string.update({value: int(stats_data['kc'])}) json_string.update({'{}_current'.format(value): int(stats_data['kc'])}) await json_manager.create(path1, json_string) for event_data in EVENT_LIST_DATA: await json_manager.update(path2, 'id', event_data['id'], 'participants', event_data['sum']) path4 = c.GUILD_PATH['{}.ini'.format(self.name)].format(ctx.guild.id) role_id = await ini_manager.get_data('SECTION1', 'EVENT_ROLE', path4) role = await discord_manager.get_role(self.client, ctx.guild.id, int(role_id)) if role: user = await discord_manager.get_member(self.client, ctx.guild.id, ctx.author.id) await user.add_roles(role, reason='{}'.format(c.DISCORD_MESSAGES['event_role_added']), atomic=True) await ctx.send(l.kc_tracker[guild_l]['msg_1'].format(USERNAME, server_config['events'])) else: SAFE_CHECK += 1 if SAFE_CHECK >= 10: CHECK = False await user.send(l.kc_tracker[guild_l]['msg_error_1']) else: CHECK = False await user.send(l.kc_tracker[guild_l]['msg_error_1']) else: await user.send(l.kc_tracker[guild_l]['msg_2']) else: EVENT_STATUS = False MEMBER_DATA = None for MEMBER in LIST1: if ctx.author.id == MEMBER['user_id']: MEMBER_DATA = MEMBER for EVENT in LIST2: for key, value in MEMBER_DATA.items(): if (EVENT['type'] == 3 or EVENT['type'] == 4) and key == EVENT['event_name']: EVENT_STATUS = True for index2, event_name in enumerate(LIST4): if event_name == EVENT['event_name']: EVENT_NAME2 = LIST3[index2] if not EVENT_STATUS and (EVENT['type'] == 3 or EVENT['type'] == 4): EVENT_STATUS = False CHECK = True while CHECK: USERNAME = userName.replace(' ', '%20') USER = hiscores_kc.Hiscores2V(USERNAME, LIST3, LIST4) if USER.status != 404: if USER.getKc(EVENT['event_name']): USER_STATS = USER.getKc(EVENT['event_name']) CHECK = False target_keys = ['{}'.format(EVENT['event_name']), '{}_current'.format(EVENT['event_name'])] target_values = [int(USER_STATS['kc']), int(USER_STATS['kc'])] await json_manager.update(path1, 'user_id', ctx.author.id, target_keys, target_values) await user.send(l.kc_tracker[guild_l]['msg_6'].format(EVENT_NAME2)) for value2 in LIST2: if value2['type'] >= 3: EVENT_NAME.append(value2['event_name']) SUM = value2['participants'] + 1 EVENT_LIST_DATA.append({'id': value2['id'], 'type': value2['type'], 'sum': SUM}) for event_data in EVENT_LIST_DATA: await json_manager.update(path2, 'id', event_data['id'], 'participants', event_data['sum']) else: SAFE_CHECK += 1 if SAFE_CHECK >= 10: CHECK = False await user.send(l.kc_tracker[guild_l]['msg_error_1']) else: CHECK = False await user.send(l.kc_tracker[guild_l]['msg_error_1']) else: EVENT_STATUS = False await user.send(l.kc_tracker[guild_l]['msg_7']) else: await ctx.send(l.kc_tracker[guild_l]['msg_badformat_2'].format(ctx.author.mention)) except Exception as error: await exception.error(error)