async def handle_answer(self, message: types.Message) -> None: word = message.text.lower() # Check if answer is invalid if not word.startswith(self.current_word[-1]): await message.reply( f"_{word.capitalize()}_ does not start with _{self.current_word[-1].upper()}_." ) return if not isinstance( self, EliminationGame ): # No minimum letters limit for elimination game modes if len(word) < self.min_letters_limit: await message.reply( f"_{word.capitalize()}_ has less than {self.min_letters_limit} letters." ) return if word in self.used_words: await message.reply(f"_{word.capitalize()}_ has been used.") return if not check_word_existence(word): await message.reply( f"_{word.capitalize()}_ is not in my list of words.") return if not await self.additional_answer_checkers(word, message): return self.post_turn_processing(word) await self.send_post_turn_message(word)
async def handle_answer(self, message: types.Message) -> None: word = message.text.lower() # Starting letter if self.game_mode is ChosenFirstLetterGame: if not word.startswith(self.current_word[0]): await message.reply( f"_{word.capitalize()}_ does not start with _{self.current_word[0].upper()}_." ) return elif not word.startswith(self.current_word[-1]): await message.reply( f"_{word.capitalize()}_ does not start with _{self.current_word[-1].upper()}_." ) return if word in self.used_words: await message.reply(f"_{word.capitalize()}_ has been used.") return if not check_word_existence(word): await message.reply( f"_{word.capitalize()}_ is not in my list of words.") return if not await self.additional_answer_checkers(word, message): return self.post_turn_processing(word) await self.send_post_turn_message(word)
async def cmd_reqaddword(message: types.Message) -> None: if message.forward_from: return words_to_add = [ w for w in set(message.get_args().lower().split()) if all(c in ascii_lowercase for c in w) ] if not words_to_add: await message.reply( "Function: Request addition of new words. Check @on9wcwa for new words.\n" "Please check the spelling of words before requesting so I can process your requests faster.\n" "Proper nouns are not accepted.\n" "Usage: `/reqaddword wordone wordtwo ...`") return existing = [] rejected = [] rejected_with_reason = [] for w in words_to_add[:]: # Iterate through a copy so removal of elements is possible if check_word_existence(w): existing.append("_" + w.capitalize() + "_") words_to_add.remove(w) async with pool.acquire() as conn: rej = await conn.fetch( "SELECT word, reason FROM wordlist WHERE NOT accepted;") for word, reason in rej: if word not in words_to_add: continue words_to_add.remove(word) word = "_" + word.capitalize() + "_" if reason: rejected_with_reason.append((word, reason)) else: rejected.append(word) text = "" if words_to_add: text += f"Submitted {', '.join(['_' + w.capitalize() + '_' for w in words_to_add])} for approval.\n" await send_admin_group( message.from_user.get_mention( name=message.from_user.full_name + (" \u2b50\ufe0f" if await has_star(message.from_user.id) else ""), as_html=True, ) + " is requesting the addition of " + ", ".join(["<i>" + w.capitalize() + "</i>" for w in words_to_add]) + " to the word list. #reqaddword", parse_mode=types.ParseMode.HTML, ) if existing: text += f"{', '.join(existing)} {'is' if len(existing) == 1 else 'are'} already in the word list.\n" if rejected: text += f"{', '.join(rejected)} {'was' if len(rejected) == 1 else 'were'} rejected.\n" for word, reason in rejected_with_reason: text += f"{word} was rejected due to {reason}.\n" await message.reply(text.rstrip())
async def cmd_addwords(message: types.Message) -> None: words_to_add = [ w for w in set(message.get_args().lower().split()) if all(c in ascii_lowercase for c in w) ] if not words_to_add: return existing = [] rejected = [] rejected_with_reason = [] for w in words_to_add[:]: if check_word_existence(w): existing.append("_" + w.capitalize() + "_") words_to_add.remove(w) async with pool.acquire() as conn: rej = await conn.fetch( "SELECT word, reason FROM wordlist WHERE NOT accepted;") for word, reason in rej: if word not in words_to_add: continue words_to_add.remove(word) word = "_" + word.capitalize() + "_" if reason: rejected_with_reason.append((word, reason)) else: rejected.append(word) text = "" if words_to_add: async with pool.acquire() as conn: await conn.executemany( "INSERT INTO wordlist (word, accepted) VALUES ($1, true)", [(w, ) for w in words_to_add], ) text += f"Added {', '.join(['_' + w.capitalize() + '_' for w in words_to_add])} to the word list.\n" if existing: text += f"{', '.join(existing)} {'is' if len(existing) == 1 else 'are'} already in the word list.\n" if rejected: text += f"{', '.join(rejected)} {'was' if len(rejected) == 1 else 'were'} rejected.\n" for word, reason in rejected_with_reason: text += f"{word} was rejected due to {reason}.\n" msg = await message.reply(text.rstrip()) if not words_to_add: return await update_words() await msg.edit_text(msg.md_text + "\n\nWord list updated.") await bot.send_message( WORD_ADDITION_CHANNEL_ID, f"Added {', '.join(['_' + w.capitalize() + '_' for w in words_to_add])} to the word list.", disable_notification=True, )
async def cmd_exists(message: types.Message) -> None: word = message.text.partition(" ")[2].lower() if not word or not all(c in ascii_lowercase for c in word): # No proper argument given rmsg = message.reply_to_message if rmsg and rmsg.text and all(c in ascii_lowercase for c in rmsg.text.lower()): word = rmsg.text.lower() else: await message.reply( "Function: Check if a word is in my dictionary. " "Use /reqaddword if you want to request addition of new words.\n" "Usage: `/exists word`" ) return if check_word_existence(word): await message.reply(f"_{word.capitalize()}_ is *in* my dictionary.") else: await message.reply(f"_{word.capitalize()}_ is *not in* my dictionary.")