async def unscramble(cmd: SigmaCommand, message: discord.Message, args: list): if not word_cache: dict_docs = await cmd.db[cmd.db.db_nam ].DictionaryData.find({}).to_list(None) for ddoc in dict_docs: word = ddoc.get('word') if len(word) > 3 and len(word.split(' ')) == 1: word_cache.update({word: ddoc.get('description')}) if message.channel.id not in ongoing_list: ongoing_list.append(message.channel.id) words = list(word_cache.keys()) word_choice = secrets.choice(words) word_description = word_cache.get(word_choice) kud_reward = len(word_choice) scrambled = scramble(word_choice.title()) question_embed = discord.Embed(color=0x3B88C3, title=f'🔣 {scrambled}') await message.channel.send(embed=question_embed) def check_answer(msg): if message.channel.id == msg.channel.id: if msg.content.lower() == word_choice.lower(): correct = True else: correct = False else: correct = False return correct try: answer_message = await cmd.bot.wait_for('message', check=check_answer, timeout=30) await cmd.db.add_currency(answer_message.author, message.guild, kud_reward) author = answer_message.author.display_name currency = cmd.bot.cfg.pref.currency win_title = f'🎉 Correct, {author}, it was {word_choice}. You won {kud_reward} {currency}!' win_embed = discord.Embed(color=0x77B255, title=win_title) await message.channel.send(embed=win_embed) except asyncio.TimeoutError: timeout_title = f'🕙 Time\'s up!' timeout_embed = discord.Embed(color=0x696969, title=timeout_title) timeout_embed.add_field(name=f'It was {word_choice.lower()}.', value=word_description) await message.channel.send(embed=timeout_embed) if message.channel.id in ongoing_list: ongoing_list.remove(message.channel.id) else: ongoing_error = discord.Embed(color=0xBE1931, title='❗ There is one already ongoing.') await message.channel.send(embed=ongoing_error)
async def mangachargame(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if not Ongoing.is_ongoing(cmd.name, pld.msg.channel.id): try: Ongoing.set_ongoing(cmd.name, pld.msg.channel.id) mal_icon = 'https://myanimelist.cdn-dena.com/img/sp/icon/apple-touch-icon-256.png' wait_embed = discord.Embed(color=0x1d439b) wait_embed.set_author(name='Hunting for a good specimen...', icon_url=mal_icon) working_response = await pld.msg.channel.send(embed=wait_embed) if pld.args: if pld.args[0].lower() == 'hint': hint = True else: hint = False else: hint = False ani_order = secrets.randbelow(3) * 50 if ani_order: ani_top_list_url = f'https://myanimelist.net/topmanga.php?limit={ani_order}' else: ani_top_list_url = 'https://myanimelist.net/topmanga.php' async with aiohttp.ClientSession() as session: async with session.get( ani_top_list_url) as ani_top_list_session: ani_top_list_html = await ani_top_list_session.text() ani_top_list_data = html.fromstring(ani_top_list_html) ani_list_objects = ani_top_list_data.cssselect('.ranking-list') ani_choice = secrets.choice(ani_list_objects) ani_url = ani_choice[1][0].attrib['href'] async with aiohttp.ClientSession() as session: async with session.get( f'{ani_url}/characters') as ani_page_session: ani_page_html = await ani_page_session.text() ani_page_data = html.fromstring(ani_page_html) cover_object = ani_page_data.cssselect('.borderClass a')[0][0] manga_cover = cover_object.attrib['data-src'] manga_title = cover_object.attrib['alt'].strip() character_object_list = ani_page_data.cssselect( '.js-scrollfix-bottom-rel')[0] character_list = [] for char_obj_full in character_object_list[5:]: char_obj_full = char_obj_full.cssselect( 'td.borderClass.bgColor2') if len(char_obj_full) != 2: continue char_obj = char_obj_full[0].cssselect('.fw-n')[0] cover_obj = char_obj_full[1].cssselect('.spaceit_pad small')[0] if 'href' in char_obj.attrib: if cover_obj.text_content().strip() == 'Main': character_list.append(char_obj) char_choice = secrets.choice(character_list) char_url = char_choice.attrib['href'] async with aiohttp.ClientSession() as session: async with session.get(char_url) as char_page_session: char_page_html = await char_page_session.text() char_page_data = html.fromstring(char_page_html) char_img_obj = char_page_data.cssselect('.borderClass')[0][0][0][0] char_img = char_img_obj.attrib['data-src'] char_name = ' '.join( char_img_obj.attrib['alt'].strip().split(', ')) kud_reward = None description = None name_split = char_name.split() for name_piece in name_split: if kud_reward is None: kud_reward = len(name_piece) else: if kud_reward >= len(name_piece): kud_reward = len(name_piece) if hint: kud_reward = kud_reward // 2 scrambled_name = scramble(char_name) description = f'Name: {scrambled_name}' reward_mult = streaks.get(pld.msg.channel.id) or 0 kud_reward = int(kud_reward * (1 + (reward_mult * 2.25) / (1.75 + (0.03 * reward_mult)))) try: await working_response.delete() except discord.NotFound: pass question_embed = discord.Embed(color=0x1d439b) if description: question_embed.description = description question_embed.set_image(url=char_img) question_embed.set_author(name=manga_title, icon_url=manga_cover, url=char_img) footer_text = 'You have 30 seconds to guess it.' if reward_mult: footer_text += f' | Streak: {int(reward_mult)}' question_embed.set_footer(text=footer_text) await pld.msg.channel.send(embed=question_embed) def check_answer(msg): """ :type msg: discord.Message :rtype: bool """ if pld.msg.channel.id == msg.channel.id: if msg.content.lower() in char_name.lower().split(): correct = True elif msg.content.lower() == char_name.lower(): correct = True else: correct = False else: correct = False return correct try: answer_message = await cmd.bot.wait_for('message', check=check_answer, timeout=30) await cmd.db.add_resource(answer_message.author.id, 'currency', kud_reward, cmd.name, pld.msg) author = answer_message.author.display_name currency = cmd.bot.cfg.pref.currency streaks.update({pld.msg.channel.id: reward_mult + 1}) win_title = f'🎉 Correct, {author}, it was {char_name}. You won {kud_reward} {currency}!' win_embed = discord.Embed(color=0x77B255, title=win_title) await pld.msg.channel.send(embed=win_embed) except asyncio.TimeoutError: if pld.msg.channel.id in streaks: streaks.pop(pld.msg.channel.id) timeout_title = f'🕙 Time\'s up! It was {char_name} from {manga_title}...' timeout_embed = discord.Embed(color=0x696969, title=timeout_title) await pld.msg.channel.send(embed=timeout_embed) except (IndexError, KeyError): grab_error = GenericResponse( 'I failed to grab a character, try again.').error() await pld.msg.channel.send(embed=grab_error) if Ongoing.is_ongoing(cmd.name, pld.msg.channel.id): Ongoing.del_ongoing(cmd.name, pld.msg.channel.id) else: ongoing_error = GenericResponse( 'There is already one ongoing.').error() await pld.msg.channel.send(embed=ongoing_error)
async def mangachargame(cmd: SigmaCommand, message: discord.Message, args: list): if message.channel.id not in ongoing_list: try: ongoing_list.append(message.channel.id) mal_icon = 'https://myanimelist.cdn-dena.com/img/sp/icon/apple-touch-icon-256.png' wait_embed = discord.Embed(color=0x1d439b) wait_embed.set_author(name='Hunting for a good specimen...', icon_url=mal_icon) working_response = await message.channel.send(embed=wait_embed) if args: if args[0].lower() == 'hint': hint = True else: hint = False else: hint = False ani_order = secrets.randbelow(3) * 50 if ani_order: ani_top_list_url = f'https://myanimelist.net/topmanga.php?limit={ani_order}' else: ani_top_list_url = 'https://myanimelist.net/topmanga.php' async with aiohttp.ClientSession() as session: async with session.get( ani_top_list_url) as ani_top_list_session: ani_top_list_html = await ani_top_list_session.text() ani_top_list_data = html.fromstring(ani_top_list_html) ani_list_objects = ani_top_list_data.cssselect('.ranking-list') ani_choice = secrets.choice(ani_list_objects) ani_url = ani_choice[1][0].attrib['href'] async with aiohttp.ClientSession() as session: async with session.get( f'{ani_url}/characters') as ani_page_session: ani_page_html = await ani_page_session.text() ani_page_data = html.fromstring(ani_page_html) cover_object = ani_page_data.cssselect('.ac')[0] anime_cover = cover_object.attrib['src'] anime_title = cover_object.attrib['alt'].strip() character_object_list = ani_page_data.cssselect('.borderClass') character_list = [] for char_obj in character_object_list: if 'href' in char_obj[0].attrib: if char_obj[1].text_content().strip() == 'Main': character_list.append(char_obj) char_choice = secrets.choice(character_list) char_url = char_choice[0].attrib['href'] async with aiohttp.ClientSession() as session: async with session.get(char_url) as char_page_session: char_page_html = await char_page_session.text() char_page_data = html.fromstring(char_page_html) char_img_obj = char_page_data.cssselect('.borderClass')[0][0][0][0] char_img = char_img_obj.attrib['src'] char_name = ' '.join( char_img_obj.attrib['alt'].strip().split(', ')) await working_response.delete() question_embed = discord.Embed(color=0x1d439b) question_embed.set_image(url=char_img) question_embed.set_footer(text='You have 30 seconds to guess it.') question_embed.set_author(name=anime_title, icon_url=anime_cover, url=char_img) kud_reward = None name_split = char_name.split() for name_piece in name_split: if kud_reward is None: kud_reward = len(name_piece) else: if kud_reward >= len(name_piece): kud_reward = len(name_piece) if hint: kud_reward = kud_reward // 2 scrambled_name = scramble(char_name) question_embed.description = f'Name: {scrambled_name}' await message.channel.send(embed=question_embed) def check_answer(msg): if message.channel.id == msg.channel.id: if msg.content.lower() in char_name.lower().split(): correct = True elif msg.content.lower() == char_name.lower(): correct = True else: correct = False else: correct = False return correct try: answer_message = await cmd.bot.wait_for('message', check=check_answer, timeout=30) reward_mult = streaks.get(message.channel.id) or 0 kud_reward = int(kud_reward * (1 + (reward_mult * 0.35))) await cmd.db.add_currency(answer_message.author, message.guild, kud_reward) author = answer_message.author.display_name currency = cmd.bot.cfg.pref.currency streaks.update({message.channel.id: reward_mult + 1}) win_title = f'🎉 Correct, {author}, it was {char_name}. You won {kud_reward} {currency}!' win_embed = discord.Embed(color=0x77B255, title=win_title) await message.channel.send(embed=win_embed) except asyncio.TimeoutError: if message.channel.id in streaks: streaks.pop(message.channel.id) timeout_title = f'🕙 Time\'s up! It was {char_name} from {anime_title}...' timeout_embed = discord.Embed(color=0x696969, title=timeout_title) await message.channel.send(embed=timeout_embed) except (IndexError, KeyError): grab_error = discord.Embed( color=0xBE1931, title='❗ I failed to grab a character, try again.') await message.channel.send(embed=grab_error) if message.channel.id in ongoing_list: ongoing_list.remove(message.channel.id) else: ongoing_error = discord.Embed(color=0xBE1931, title='❗ There is already one ongoing.') await message.channel.send(embed=ongoing_error)
async def vnchargame(cmd: SigmaCommand, message: discord.Message, args: list): if message.channel.id not in ongoing_list: try: ongoing_list.append(message.channel.id) vndb_icon = 'https://i.imgur.com/YrK5tQF.png' wait_embed = discord.Embed(color=0x1d439b) wait_embed.set_author(name='Hunting for a good specimen...', icon_url=vndb_icon) working_response = await message.channel.send(embed=wait_embed) if args: if args[0].lower() == 'hint': hint = True else: hint = False else: hint = False vn_url_list = [] vn_top_list_url = f'https://vndb.org/v/all?q=;fil=tagspoil-0;rfil=;o=d;s=pop;p=1' async with aiohttp.ClientSession() as session: async with session.get(vn_top_list_url) as vn_top_list_session: vn_top_list_html = await vn_top_list_session.text() vn_top_list_data = html.fromstring(vn_top_list_html) list_items = vn_top_list_data.cssselect('.tc1') for list_item in list_items: if 'href' in list_item[0].attrib: vn_url = list_item[0].attrib['href'] if vn_url.startswith('/v') and not vn_url.startswith('/v/'): vn_url = f'https://vndb.org{vn_url}' vn_url_list.append(vn_url) vn_url_choice = secrets.choice(vn_url_list) async with aiohttp.ClientSession() as session: async with session.get(f'{vn_url_choice}/chars') as vn_details_page_session: vn_details_page_html = await vn_details_page_session.text() vn_details_page = html.fromstring(vn_details_page_html) vn_title = vn_details_page.cssselect('.stripe')[0][0][1].text_content().strip() vn_image = vn_details_page.cssselect('.vnimg')[0][0][0].attrib['src'] character_objects = vn_details_page.cssselect('.chardetails')[:8] character = secrets.choice(character_objects) char_img = character[0][0].attrib['src'] char_name = character[1][0][0][0][0].text.strip() await working_response.delete() question_embed = discord.Embed(color=0x225588) question_embed.set_image(url=char_img) question_embed.set_footer(text='You have 30 seconds to guess it.') question_embed.set_author(name=vn_title, icon_url=vn_image, url=char_img) kud_reward = None name_split = char_name.split() for name_piece in name_split: if kud_reward is None: kud_reward = len(name_piece) else: if kud_reward >= len(name_piece): kud_reward = len(name_piece) if hint: kud_reward = kud_reward // 2 scrambled_name = scramble(char_name) question_embed.description = f'Name: {scrambled_name}' await message.channel.send(embed=question_embed) def check_answer(msg): if message.channel.id == msg.channel.id: if msg.content.lower() in char_name.lower().split(): correct = True elif msg.content.lower() == char_name.lower(): correct = True else: correct = False else: correct = False return correct try: answer_message = await cmd.bot.wait_for('message', check=check_answer, timeout=30) reward_mult = streaks.get(message.channel.id) or 0 kud_reward = int(kud_reward * (1 + (reward_mult * 0.35))) await cmd.db.add_currency(answer_message.author, message.guild, kud_reward) author = answer_message.author.display_name currency = cmd.bot.cfg.pref.currency streaks.update({message.channel.id: reward_mult + 1}) win_title = f'🎉 Correct, {author}, it was {char_name}. You won {kud_reward} {currency}!' win_embed = discord.Embed(color=0x77B255, title=win_title) await message.channel.send(embed=win_embed) except asyncio.TimeoutError: if message.channel.id in streaks: streaks.pop(message.channel.id) timeout_title = f'🕙 Time\'s up! It was {char_name} from {vn_title}...' timeout_embed = discord.Embed(color=0x696969, title=timeout_title) await message.channel.send(embed=timeout_embed) except (IndexError, KeyError): grab_error = discord.Embed(color=0xBE1931, title='❗ I failed to grab a character, try again.') await message.channel.send(embed=grab_error) if message.channel.id in ongoing_list: ongoing_list.remove(message.channel.id) else: ongoing_error = discord.Embed(color=0xBE1931, title='❗ There is already one ongoing.') await message.channel.send(embed=ongoing_error)
async def vnchargame(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if not Ongoing.is_ongoing(cmd.name, pld.msg.channel.id): try: Ongoing.set_ongoing(cmd.name, pld.msg.channel.id) vndb_icon = 'https://i.imgur.com/YrK5tQF.png' wait_embed = discord.Embed(color=0x1d439b) wait_embed.set_author(name='Hunting for a good specimen...', icon_url=vndb_icon) working_response = await pld.msg.channel.send(embed=wait_embed) if pld.args: if pld.args[0].lower() == 'hint': hint = True else: hint = False else: hint = False vn_url_list = [] vn_top_list_url = 'https://vndb.org/v/all?q=;fil=tagspoil-0;rfil=;o=d;s=pop;p=1' async with aiohttp.ClientSession() as session: async with session.get(vn_top_list_url) as vn_top_list_session: vn_top_list_html = await vn_top_list_session.text() vn_top_list_data = html.fromstring(vn_top_list_html) list_items = vn_top_list_data.cssselect('.tc1') for list_item in list_items: if 'href' in list_item[0].attrib: vn_url = list_item[0].attrib['href'] if vn_url.startswith( '/v') and not vn_url.startswith('/v/'): vn_url = f'https://vndb.org{vn_url}' vn_url_list.append(vn_url) vn_url_choice = secrets.choice(vn_url_list) async with aiohttp.ClientSession() as session: async with session.get( f'{vn_url_choice}/chars') as vn_details_page_session: vn_details_page_html = await vn_details_page_session.text() vn_details_page = html.fromstring(vn_details_page_html) vn_title = vn_details_page.cssselect( '.stripe')[0][0][1].text_content().strip() vn_image = vn_details_page.cssselect( '.vnimg')[0][0][0][0].attrib['src'] character_objects = vn_details_page.cssselect('.chardetails')[:8] character = secrets.choice(character_objects) char_img = character[0][0][0][0].attrib['src'] char_name = character[1][0][0][0][0].text.strip() kud_reward = None description = None name_split = char_name.split() for name_piece in name_split: if kud_reward is None: kud_reward = len(name_piece) else: if kud_reward >= len(name_piece): kud_reward = len(name_piece) if hint: kud_reward = kud_reward // 2 scrambled_name = scramble(char_name) description = f'Name: {scrambled_name}' reward_mult = streaks.get(pld.msg.channel.id) or 0 kud_reward = int(kud_reward * (1 + (reward_mult * 2.25) / (1.75 + (0.03 * reward_mult)))) try: await working_response.delete() except discord.NotFound: pass question_embed = discord.Embed(color=0x225588) if description: question_embed.description = description question_embed.set_image(url=char_img) question_embed.set_author(name=vn_title, icon_url=vn_image, url=char_img) footer_text = 'You have 30 seconds to guess it.' if reward_mult: footer_text += f' | Streak: {int(reward_mult)}' question_embed.set_footer(text=footer_text) await pld.msg.channel.send(embed=question_embed) def check_answer(msg): """ :type msg: discord.Message :rtype: bool """ if pld.msg.channel.id == msg.channel.id: if msg.content.lower() in char_name.lower().split(): correct = True elif msg.content.lower() == char_name.lower(): correct = True else: correct = False else: correct = False return correct try: answer_message = await cmd.bot.wait_for('message', check=check_answer, timeout=30) await cmd.db.add_resource(answer_message.author.id, 'currency', kud_reward, cmd.name, pld.msg) author = answer_message.author.display_name currency = cmd.bot.cfg.pref.currency streaks.update({pld.msg.channel.id: reward_mult + 1}) win_title = f'🎉 Correct, {author}, it was {char_name}. You won {kud_reward} {currency}!' win_embed = discord.Embed(color=0x77B255, title=win_title) await pld.msg.channel.send(embed=win_embed) except asyncio.TimeoutError: if pld.msg.channel.id in streaks: streaks.pop(pld.msg.channel.id) timeout_title = f'🕙 Time\'s up! It was {char_name} from {vn_title}...' timeout_embed = discord.Embed(color=0x696969, title=timeout_title) await pld.msg.channel.send(embed=timeout_embed) except (IndexError, KeyError): grab_error = GenericResponse( 'I failed to grab a character, try again.').error() await pld.msg.channel.send(embed=grab_error) if Ongoing.is_ongoing(cmd.name, pld.msg.channel.id): Ongoing.del_ongoing(cmd.name, pld.msg.channel.id) else: ongoing_error = GenericResponse( 'There is already one ongoing.').error() await pld.msg.channel.send(embed=ongoing_error)
async def unscramblegame(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ cache_key = 'unscramble_word_cache' word_cache = await cmd.db.cache.get_cache(cache_key) or {} if not word_cache: dict_docs = await cmd.db[cmd.db.db_nam ].DictionaryData.find({}).to_list(None) for ddoc in dict_docs: word = ddoc.get('word') if len(word) > 3 and len(word.split(' ')) == 1: word_cache.update({word: ddoc.get('description')}) await cmd.db.cache.set_cache(cache_key, word_cache) if not is_ongoing(cmd.name, pld.msg.channel.id): set_ongoing(cmd.name, pld.msg.channel.id) words = list(word_cache.keys()) word_choice = secrets.choice(words) word_description = word_cache.get(word_choice) kud_reward = len(word_choice) scrambled = scramble(word_choice.title()) question_embed = discord.Embed(color=0x3B88C3, title=f'🔣 {scrambled}') await pld.msg.channel.send(embed=question_embed) def check_answer(msg): """ Checks if the answer message is correct. :param msg: The message to check. :type msg: discord.Message :return: :rtype: """ if pld.msg.channel.id == msg.channel.id: if msg.content.lower() == word_choice.lower(): correct = True else: correct = False else: correct = False return correct try: answer_message = await cmd.bot.wait_for('message', check=check_answer, timeout=30) await cmd.db.add_resource(answer_message.author.id, 'currency', kud_reward, cmd.name, pld.msg) author = answer_message.author.display_name currency = cmd.bot.cfg.pref.currency win_title = f'🎉 Correct, {author}, it was {word_choice}. You won {kud_reward} {currency}!' win_embed = discord.Embed(color=0x77B255, title=win_title) await pld.msg.channel.send(embed=win_embed) except asyncio.TimeoutError: timeout_title = '🕙 Time\'s up!' timeout_embed = discord.Embed(color=0x696969, title=timeout_title) timeout_embed.add_field(name=f'It was {word_choice.lower()}.', value=word_description) await pld.msg.channel.send(embed=timeout_embed) if is_ongoing(cmd.name, pld.msg.channel.id): del_ongoing(cmd.name, pld.msg.channel.id) else: ongoing_error = error('There is one already ongoing.') await pld.msg.channel.send(embed=ongoing_error)