async def add(ctx, *, arg): '''Add elements separated by commas. You can add a link after the name and before any separating comma to include it on the list''' try: global df df = sf.load_df(ctx) input = sf.arg2input(arg) added = [] ignored = [] for i in input: links = [] for m in re.finditer('https?://[^\s\n]*', i): links.append(i[m.start():m.end()]) if links: i = i[:i.find('http') - 1].strip().capitalize() if i.upper() not in [n.upper() for n in df['Title'].to_list()]: netflix_path = '' if nflx_scraper: netflix_path = bot.search(i) df.loc[df.index.size] = [i.capitalize()] + [ctx.author] + [ ' '.join(links) ] + [netflix_path] added.append(i) elif links: curr_links = [ link for link in df.loc[df['Title'] == i, 'Link'].to_string( index=0).split(sep=' ') if link ] [ curr_links.append(link) for link in links if link not in curr_links ] df.loc[df['Title'] == i, 'Link'] = ' '.join(curr_links) added.append(i) else: ignored.append(i) print('added') sf.save_df(df, ctx) await sf.edit_msg(df, ctx) response = '' if added: await sf.get_elements(ctx, added, vote=0, embed_title='Added') response = 'added to list' #response=response+'I added the following entries: %s\n' % added if ignored: response = 'I ignored the double entries: %s\n' % ignored await ctx.send(response) if not response: await ctx.send('Sorry, I cant come up with a response to that') return except Exception as e: print(e) print('An error ocurred adding entries to the list') await ctx.send('Error Adding to entry to the list') return
async def show(ctx): '''Sends the list as embeds to the channel''' try: embed_list = sf.df2embed(sf.load_df(ctx)) for embed in embed_list: await ctx.channel.send(embed=embed) return except Exception as e: print(e) print('The message could not be send') await ctx.send('The message could not be sent. List can not be shown') return
async def addlink(ctx, *, arg): '''Adds a link to an existing element from the list. Usage: addlink <index|name> <links>''' try: global df input = sf.arg2input(arg) df = sf.load_df(ctx) added_link = [] not_found = [] for i in input: links = [] for m in re.finditer('https?://[^\s\n]*', i): links.append(i[m.start():m.end()]) if links: i = i[:i.find('http') - 1].strip() if sf.is_number(i): if int(i) in df.index: added_link.append(str(df.loc[int(i), 'Title'])) df.loc[int(i), 'Link'] = str( df.loc[int(i), 'Link']) + ' ' + ' '.join(links) else: not_found.append(i) elif i.upper() in [n.upper() for n in df['Title'].to_list()]: bool_arr = df.loc[:, 'Title'].str.match(i, case=False) index = bool_arr[bool_arr == True].index df.loc[int(index[0]), 'Link'] = str( df.loc[int(index[0]), 'Link']) + ' ' + ' '.join(links) added_link.append(i) else: not_found.append(i) print('links added') sf.save_df(df, ctx) await sf.edit_msg(df, ctx) print('edited') response = '' if added_link: response = response + 'I added the link(s) for the following entries: %s\n' % added_link if not_found: response = response + 'I could not find the following entries: %s\n' % not_found if not response: 'Sorry, I cant come up with a response to that' print(response) await ctx.send(response) return except Exception as e: print(e) print('An error ocurred adding the link to the entry') await ctx.send('Error adding link to entry') return
async def searchNFLX(ctx): '''Not Working! Search the corresponding NETFLIX link for the movie|serie titles''' try: if nflx_scraper: global df df = sf.load_df(ctx) for i in df.index: df.loc[i, 'Netflix'] = bot.search(df.loc[i, 'Title']) sf.save_df(df, ctx) await sf.edit_msg(df, ctx) return 'Netflix links have been added' else: return 'Netflix search is deactivated in the code' except Exception as e: print(e) print('An error ocurred adding netflix links') return 'Error adding Netflix links'
async def sort(ctx): '''Sorts all elements alphabetically''' try: global df df = sf.load_df(ctx) df = df.sort_values('Title').reset_index(drop=True) sf.save_df(df, ctx) await sf.edit_msg(df, ctx) await show(ctx) await ctx.send('List has been sorted') return except Exception as e: print(e) print('An error ocurred sorting the entries on the list') await ctx.send('Error sorting list') return
async def remove(ctx, *, arg): '''Removes one or more elements from the list. Titles separated by commas. When only using the index of the elements, only a blankspace is needed to separate elements.''' try: global df input = sf.arg2input(arg) df = sf.load_df(ctx) removed = [] not_found = [] for i in input: if sf.is_number(i): if int(i) in df.index: removed.append(str(df.loc[int(i), 'Title'])) df = df.drop(int(i)) else: not_found.append(i) elif i.upper() in [n.upper() for n in df['Title'].to_list()]: bool_arr = df.loc[:, 'Title'].str.match(i, case=False) df = df.drop(bool_arr[bool_arr == True].index) removed.append(i) else: not_found.append(i) df = df.reset_index(drop=1) print('removed') sf.save_df(df, ctx) await sf.edit_msg(df, ctx) print('edited') response = '' if removed: response = response + 'I removed the following entries: %s\n' % removed if not_found: response = response + 'I could not find the following entries: %s\n' % not_found if not response: 'Sorry, I cant come up with a response to that' print(response) await ctx.send(response) return except Exception as e: print(e) print('An error ocurred removing entries from the list') await ctx.send('Error removing entry from the list') return
async def get_random(ctx, reroll: typing.Optional[int] = 0): '''Return a random element from the list. By clicking on the reaction you can reroll the random result.''' try: global df df = sf.load_df(ctx) r = randrange(len(df)) embed = sf.line2embed(df, r) if not reroll: msg = await ctx.channel.send(embed=embed, nonce=11) await msg.add_reaction(chr(128257)) else: await ctx.edit(embed=embed, nonce=11) #output=str(df.loc[r,'Title']) + ' (by ' + str(df.loc[r,'AddedBy']) + ')' #response='Random result:\n```%s```' % output response = '** **' print(response) return except Exception as e: print(e) print('An error ocurred getting a random entry from the list') return 'Error getting a random entry from the list'
async def get(ctx, *, arg): '''This returns the elements specified and separated by a comma. If only using the index of the elements, only a separating blankspace is needed''' input = sf.arg2input(arg) await sf.get_elements(ctx, input, vote=0) return
async def getv(ctx, *, arg): '''Same as the 'get' command, but includes a reaction for each element to allow voting.''' input = sf.arg2input(arg) await sf.get_elements(ctx, input, vote=1) return