def done(message: Message, discord_object: DiscordBot.DiscordBot): data_message = discord_object.parse_message(message.content) thread_pool = [] if len(data_message) == 4: editable = yield from discord_object.send_message( message.channel, message.author.mention + ' Updating carry sheet...') names = data_message[3] boss_list = data_message[2] local_data = discord_object.locals['register']['oceaniaGuildActivity'][ 'Oceania'] real_names = [] not_found = [] last_index = int(discord_object.locals[COMMAND]['oceaniaCarryQueue'] ['CARRYLOG']['length']) + 1 today = '{} {}'.format(discord_object.get_current_day(), discord_object.get_current_time()) for name in names: try: index = local_data['eznameUpper'].index(name.upper()) name = local_data['Name'][index] if name != "": real_names.append(name) else: real_names.append(name) except ValueError: not_found.append(name) carry_index = local_data['discordID'].index(message.author.id) carry_name = local_data['Name'][carry_index] not_in_boss = {} done_bosses = [] for boss_upper in boss_list: try: boss = PATCH[boss_upper.lower()] for name in real_names: index = None if boss in CRA: sheet = 'CRA' else: sheet = 'OTHER' if name in discord_object.locals[COMMAND][ 'oceaniaCarryQueue'][sheet][boss]: index = discord_object.locals[COMMAND][ 'oceaniaCarryQueue'][sheet][boss].index(name) discord_object.locals[COMMAND]['oceaniaCarryQueue'][ sheet][boss].pop(index) else: if boss in not_in_boss.keys(): not_in_boss[boss].append(name) else: not_in_boss[boss] = [name] if NAMES[boss] not in done_bosses: done_bosses.append(NAMES[boss]) new_list = list( filter( None, discord_object.locals[COMMAND]['oceaniaCarryQueue'] [sheet][boss])) + (len(real_names)) * [''] start = (1, INDEX[boss]) end = (len(new_list), INDEX[boss]) thread1 = Thread( target=discord_object.spreadsheet_accessor.write_range, args=('oceaniaCarryQueue', sheet, start, end, new_list)) thread1.start() thread_pool.append(thread1) comment_list = discord_object.locals[COMMAND][ 'oceaniaCarryQueue'][sheet]['comment_' + boss] if index is not None: original_length = len( discord_object.locals[COMMAND]['oceaniaCarryQueue'] [sheet][boss]) comment_list.pop(index) comments = list(comment_list[:original_length] + len(real_names) * ['']) start = (1, INDEX[boss] + 2) end = (len(comments), INDEX[boss] + 2) thread2 = Thread(target=discord_object. spreadsheet_accessor.write_range, args=('oceaniaCarryQueue', sheet, start, end, comments)) thread2.start() thread_pool.append(thread2) writer = list( filter(None, [today, carry_name, NAMES[boss]] + real_names + not_found)) thread3 = Thread( target=discord_object.spreadsheet_accessor.write_range, args=('oceaniaCarryQueue', 'CARRYLOG', (last_index, 1), (last_index, 3 + len(real_names + not_found)), writer)) thread3.start() thread_pool.append(thread3) discord_object.locals[COMMAND]['oceaniaCarryQueue'][ 'CARRYLOG']['length'] += 1 last_index += 1 except KeyError: continue except UnboundLocalError: continue except Exception as e: raise e if len(done_bosses) > 0: msg = ' Done updating carry queue for {}.\n'.format( ', '.join(done_bosses)) if len(not_in_boss) > 0: temp = 'These names also did not appear in the boss list for the following bosses:\n' for boss in not_in_boss.keys(): temp += '{}: {}\n'.format(NAMES[boss], ', '.join(not_in_boss[boss])) msg += temp if len(not_found) > 0: msg += '\nThese names were not recognized:\n{}'.format( ', '.join(not_found)) else: msg = ' The carry queue was updated for no bosses. ' yield from discord_object.edit_message(editable, message.author.mention + msg) for threads in thread_pool: threads.join()
def confirmed(message: Message, discord_object: DiscordBot.DiscordBot, editable: Message): ss = 'oceaniaGuildActivity' ws = 'Oceania' message_data = discord_object.parse_message(message.content) name = message_data[1] local_id = discord_object.locals[COMMAND][ss][ws]['discordID'] local_names = discord_object.locals[COMMAND][ss][ws]['Capitalized'] local_ez_names = discord_object.locals[COMMAND][ss][ws]['eznameUpper'] last_pos = discord_object.locals[COMMAND][ss][ws]['lastpos'] if len(message_data) == 2: ezname = replace_special_chars(name) if message.author.id not in local_id and name not in local_names and name not in local_ez_names: if name.upper( ) in discord_object.locals[COMMAND][ss][ws]['Capitalized']: index = discord_object.locals[COMMAND][ss][ws][ 'Capitalized'].index(name.upper()) + 2 start = (index, 4) end = (index, 7) data = [ message.author.id, '', ezname, ezname.upper(), discord_object.get_current_day() ] discord_object.spreadsheet_accessor.write_range( ss, ws, start, end, data) discord_object.locals[COMMAND][ss][ws]['discordID'][ index] = message.author.id discord_object.locals[COMMAND][ss][ws]['ezname'][ index] = ezname discord_object.locals[COMMAND][ss][ws]['eznameUpper'][ index] = ezname.upper() yield from discord_object.edit_message( editable, message.author.mention + ' Registration successful.') elif name.upper( ) in discord_object.locals[COMMAND][ss][ws]['eznameUpper']: index = discord_object.locals[COMMAND][ss][ws][ 'eznameUpper'].index(name.upper()) + 2 start = (index, 1) end = (index, 8) data = [ name, name.upper(), '', message.author.id, '', ezname, ezname.upper(), discord_object.get_current_day() ] discord_object.spreadsheet_accessor.write_range( ss, ws, start, end, data) discord_object.locals[COMMAND][ss][ws]['discordID'][ index] = message.author.id discord_object.locals[COMMAND][ss][ws]['Name'][index] = name discord_object.locals[COMMAND][ss][ws]['Capitalized'][ index] = name.upper() discord_object.locals[COMMAND][ss][ws]['ezname'][ index] = ezname discord_object.locals[COMMAND][ss][ws]['eznameUpper'][ index] = ezname.upper() yield from discord_object.edit_message( editable, message.author.mention + ' Registration successful.') else: start = (last_pos, 1) end = (last_pos, 8) data = [ name, name.upper(), '', message.author.id, '', ezname, ezname.upper(), discord_object.get_current_day() ] discord_object.spreadsheet_accessor.write_range( ss, ws, start, end, data) discord_object.locals[COMMAND][ss][ws]['discordID'].append( message.author.id) discord_object.locals[COMMAND][ss][ws]['Name'].append(name) discord_object.locals[COMMAND][ss][ws]['Capitalized'].append( name.upper()) discord_object.locals[COMMAND][ss][ws]['ezname'].append(ezname) discord_object.locals[COMMAND][ss][ws]['eznameUpper'].append( ezname.upper()) discord_object.locals[COMMAND][ss][ws]['lastpos'] += 1 yield from discord_object.edit_message( editable, message.author.mention + ' Registration successful.')