async def akinator(self, ctx: Context, *, flags: AkinatorFlags): """ Play a game of akinator. """ fm = await ctx.send("Starting game, please wait...") akiclient = Akinator() mode_map = { "default": "en", "animals": "en_animals", "objects": "en_objects" } async with ctx.channel.typing(): game = await akiclient.start_game(language=mode_map[flags.mode], child_mode=flags.child) if akiclient.child_mode is False and ctx.channel.nsfw is False: return await ctx.send( "Child mode can only be disabled in NSFW channels.") embed = discord.Embed(title="Akinator", description=f"{akiclient.step+1}. {game}") view = AkinatorGameView(member=ctx.author, ctx=ctx, client=akiclient, embed=embed) if not fm.edited_at: await fm.delete() view.message = await ctx.send(embed=embed, view=view)
async def aki( self, ctx: commands.Context, language: str.lower = "en", use_buttons: bool = True ): """ Start a game of Akinator! Controls: > ✅ : yes > ❎ : no > ❔ : i don't know > 📉 : probably > 📈 : probably not > 🔙 : back > 🏆 : win > 🗑️ : cancel """ await ctx.trigger_typing() aki = Akinator() child_mode = not channel_is_nsfw(ctx.channel) try: await aki.start_game( language=language.replace(" ", "_"), child_mode=child_mode, client_session=self.session, ) except akinator.InvalidLanguageError: await ctx.send( "Invalid language. Refer here to view valid languages.\n<https://github.com/NinjaSnail1080/akinator.py#functions>" ) except Exception: await ctx.send("I encountered an error while connecting to the Akinator servers.") else: aki_color = discord.Color(0xE8BC90) menu = get_menu(buttons=use_buttons) await menu(aki, aki_color).start(ctx)
async def aki(self, ctx: commands.Context, *, language: str.lower = "en"): """ Start a game of Akinator! Controls: > ✅ : yes > ❎ : no > ❔ : i don't know > 📉 : probably > 📈 : probably not > 🔙 : back > 🏆 : win > 🗑️ : cancel """ await ctx.trigger_typing() aki = Akinator() try: await aki.start_game(language=language.replace(" ", "_")) except akinator.InvalidLanguageError: await ctx.send( "Invalid language. Refer here to view valid languages.\n<https://github.com/NinjaSnail1080/akinator.py#functions>" ) except Exception: await ctx.send("I encountered an error while connecting to the Akinator servers.") else: menu = AkiMenu(aki, await ctx.embed_color()) await menu.start(ctx)
def __init__(self, user: discord.User, channel: discord.TextChannel, bot: Red): self.user = user self.channel = channel self.bot = bot self.akinator = Akinator() self.task = None self.question = None self.prog = 80 self.count = 1
async def akinator(self, ctx): async with ctx.typing(): aki = Akinator() wrapper = AkinatorWrapper() question = await aki.start_game(language='id') embed, components = wrapper.generate_embed( question=question, disable_components=False) game = await ctx.send(embed=embed, components=components) try: while aki.progression <= 80: btn = await game.wait_for('button', self.bot, by=ctx.author, timeout=60) await btn.respond(ninja_mode=True) if btn.custom_id == 'aki_yes': question = await aki.answer('yes') if btn.custom_id == 'aki_maybe': question = await aki.answer('probably') if btn.custom_id == 'aki_idk': question = await aki.answer('idk') if btn.custom_id == 'aki_no': question = await aki.answer('no') if btn.custom_id == 'aki_stop': raise TimeoutError('Player stopped the game') if aki.progression >= 80: break embed, components = wrapper.generate_embed( question=question, disable_components=False) await game.edit(embed=embed, components=components) except TimeoutError as e: message = 'Kamu menekan tombol stop' if str( e ) == 'Player stopped the game' else 'Hasbi terlalu lelah menunggu jawaban kamu' embed = wrapper.generate_error_embed(message=message) except AkiNoQuestions: embed = wrapper.generate_error_embed( message='Udah gak punya pertanyaan lagi maaf, kamu menang deh') async with ctx.typing(): if aki.progression >= 80: await aki.win() guesses = aki.guesses index = 1 embed, _ = wrapper.generate_embed(guess=guesses[index - 1], guessing=True) await game.delete() await ctx.send(embed=embed) await aki.close()
def __init__(self, bot): # all constants is better using self.<variable> rather than declaring it every time a command is invoked self.kks = kakasi() self.bot = bot self.Country = [{"name":"Afghanistan","code":"AF"},{"name":"Aland Islands","code":"AX"},{"name":"Albania","code":"AL"},{"name":"Algeria","code":"DZ"},{"name":"American Samoa","code":"AS"},{"name":"AndorrA","code":"AD"},{"name":"Angola","code":"AO"},{"name":"Anguilla","code":"AI"},{"name":"Antarctica","code":"AQ"},{"name":"Antigua and Barbuda","code":"AG"},{"name":"Argentina","code":"AR"},{"name":"Armenia","code":"AM"},{"name":"Aruba","code":"AW"},{"name":"Australia","code":"AU"},{"name":"Austria","code":"AT"},{"name":"Azerbaijan","code":"AZ"},{"name":"Bahamas","code":"BS"},{"name":"Bahrain","code":"BH"},{"name":"Bangladesh","code":"BD"},{"name":"Barbados","code":"BB"},{"name":"Belarus","code":"BY"},{"name":"Belgium","code":"BE"},{"name":"Belize","code":"BZ"},{"name":"Benin","code":"BJ"},{"name":"Bermuda","code":"BM"},{"name":"Bhutan","code":"BT"},{"name":"Bolivia","code":"BO"},{"name":"Bosnia and Herzegovina","code":"BA"},{"name":"Botswana","code":"BW"},{"name":"Bouvet Island","code":"BV"},{"name":"Brazil","code":"BR"},{"name":"British Indian Ocean Territory","code":"IO"},{"name":"Brunei Darussalam","code":"BN"},{"name":"Bulgaria","code":"BG"},{"name":"Burkina Faso","code":"BF"},{"name":"Burundi","code":"BI"},{"name":"Cambodia","code":"KH"},{"name":"Cameroon","code":"CM"},{"name":"Canada","code":"CA"},{"name":"Cape Verde","code":"CV"},{"name":"Cayman Islands","code":"KY"},{"name":"Central African Republic","code":"CF"},{"name":"Chad","code":"TD"},{"name":"Chile","code":"CL"},{"name":"China","code":"CN"},{"name":"Christmas Island","code":"CX"},{"name":"Cocos (Keeling) Islands","code":"CC"},{"name":"Colombia","code":"CO"},{"name":"Comoros","code":"KM"},{"name":"Congo","code":"CG"},{"name":"Congo, The Democratic Republic of the","code":"CD"},{"name":"Cook Islands","code":"CK"},{"name":"Costa Rica","code":"CR"},{"name":"Cote D'Ivoire","code":"CI"},{"name":"Croatia","code":"HR"},{"name":"Cuba","code":"CU"},{"name":"Cyprus","code":"CY"},{"name":"Czech Republic","code":"CZ"},{"name":"Denmark","code":"DK"},{"name":"Djibouti","code":"DJ"},{"name":"Dominica","code":"DM"},{"name":"Dominican Republic","code":"DO"},{"name":"Ecuador","code":"EC"},{"name":"Egypt","code":"EG"},{"name":"El Salvador","code":"SV"},{"name":"Equatorial Guinea","code":"GQ"},{"name":"Eritrea","code":"ER"},{"name":"Estonia","code":"EE"},{"name":"Ethiopia","code":"ET"},{"name":"Falkland Islands (Malvinas)","code":"FK"},{"name":"Faroe Islands","code":"FO"},{"name":"Fiji","code":"FJ"},{"name":"Finland","code":"FI"},{"name":"France","code":"FR"},{"name":"French Guiana","code":"GF"},{"name":"French Polynesia","code":"PF"},{"name":"French Southern Territories","code":"TF"},{"name":"Gabon","code":"GA"},{"name":"Gambia","code":"GM"},{"name":"Georgia","code":"GE"},{"name":"Germany","code":"DE"},{"name":"Ghana","code":"GH"},{"name":"Gibraltar","code":"GI"},{"name":"Greece","code":"GR"},{"name":"Greenland","code":"GL"},{"name":"Grenada","code":"GD"},{"name":"Guadeloupe","code":"GP"},{"name":"Guam","code":"GU"},{"name":"Guatemala","code":"GT"},{"name":"Guernsey","code":"GG"},{"name":"Guinea","code":"GN"},{"name":"Guinea-Bissau","code":"GW"},{"name":"Guyana","code":"GY"},{"name":"Haiti","code":"HT"},{"name":"Heard Island and Mcdonald Islands","code":"HM"},{"name":"Holy See (Vatican City State)","code":"VA"},{"name":"Honduras","code":"HN"},{"name":"Hong Kong","code":"HK"},{"name":"Hungary","code":"HU"},{"name":"Iceland","code":"IS"},{"name":"India","code":"IN"},{"name":"Indonesia","code":"ID"},{"name":"Iran, Islamic Republic Of","code":"IR"},{"name":"Iraq","code":"IQ"},{"name":"Ireland","code":"IE"},{"name":"Isle of Man","code":"IM"},{"name":"Israel","code":"IL"},{"name":"Italy","code":"IT"},{"name":"Jamaica","code":"JM"},{"name":"Japan","code":"JP"},{"name":"Jersey","code":"JE"},{"name":"Jordan","code":"JO"},{"name":"Kazakhstan","code":"KZ"},{"name":"Kenya","code":"KE"},{"name":"Kiribati","code":"KI"},{"name":"Korea, Democratic People'S Republic of","code":"KP"},{"name":"Korea, Republic of","code":"KR"},{"name":"Kuwait","code":"KW"},{"name":"Kyrgyzstan","code":"KG"},{"name":"Lao People'S Democratic Republic","code":"LA"},{"name":"Latvia","code":"LV"},{"name":"Lebanon","code":"LB"},{"name":"Lesotho","code":"LS"},{"name":"Liberia","code":"LR"},{"name":"Libyan Arab Jamahiriya","code":"LY"},{"name":"Liechtenstein","code":"LI"},{"name":"Lithuania","code":"LT"},{"name":"Luxembourg","code":"LU"},{"name":"Macao","code":"MO"},{"name":"Macedonia, The Former Yugoslav Republic of","code":"MK"},{"name":"Madagascar","code":"MG"},{"name":"Malawi","code":"MW"},{"name":"Malaysia","code":"MY"},{"name":"Maldives","code":"MV"},{"name":"Mali","code":"ML"},{"name":"Malta","code":"MT"},{"name":"Marshall Islands","code":"MH"},{"name":"Martinique","code":"MQ"},{"name":"Mauritania","code":"MR"},{"name":"Mauritius","code":"MU"},{"name":"Mayotte","code":"YT"},{"name":"Mexico","code":"MX"},{"name":"Micronesia, Federated States of","code":"FM"},{"name":"Moldova, Republic of","code":"MD"},{"name":"Monaco","code":"MC"},{"name":"Mongolia","code":"MN"},{"name":"Montserrat","code":"MS"},{"name":"Morocco","code":"MA"},{"name":"Mozambique","code":"MZ"},{"name":"Myanmar","code":"MM"},{"name":"Namibia","code":"NA"},{"name":"Nauru","code":"NR"},{"name":"Nepal","code":"NP"},{"name":"Netherlands","code":"NL"},{"name":"Netherlands Antilles","code":"AN"},{"name":"New Caledonia","code":"NC"},{"name":"New Zealand","code":"NZ"},{"name":"Nicaragua","code":"NI"},{"name":"Niger","code":"NE"},{"name":"Nigeria","code":"NG"},{"name":"Niue","code":"NU"},{"name":"Norfolk Island","code":"NF"},{"name":"Northern Mariana Islands","code":"MP"},{"name":"Norway","code":"NO"},{"name":"Oman","code":"OM"},{"name":"Pakistan","code":"PK"},{"name":"Palau","code":"PW"},{"name":"Palestinian Territory, Occupied","code":"PS"},{"name":"Panama","code":"PA"},{"name":"Papua New Guinea","code":"PG"},{"name":"Paraguay","code":"PY"},{"name":"Peru","code":"PE"},{"name":"Philippines","code":"PH"},{"name":"Pitcairn","code":"PN"},{"name":"Poland","code":"PL"},{"name":"Portugal","code":"PT"},{"name":"Puerto Rico","code":"PR"},{"name":"Qatar","code":"QA"},{"name":"Reunion","code":"RE"},{"name":"Romania","code":"RO"},{"name":"Russian Federation","code":"RU"},{"name":"RWANDA","code":"RW"},{"name":"Saint Helena","code":"SH"},{"name":"Saint Kitts and Nevis","code":"KN"},{"name":"Saint Lucia","code":"LC"},{"name":"Saint Pierre and Miquelon","code":"PM"},{"name":"Saint Vincent and the Grenadines","code":"VC"},{"name":"Samoa","code":"WS"},{"name":"San Marino","code":"SM"},{"name":"Sao Tome and Principe","code":"ST"},{"name":"Saudi Arabia","code":"SA"},{"name":"Senegal","code":"SN"},{"name":"Serbia and Montenegro","code":"CS"},{"name":"Seychelles","code":"SC"},{"name":"Sierra Leone","code":"SL"},{"name":"Singapore","code":"SG"},{"name":"Slovakia","code":"SK"},{"name":"Slovenia","code":"SI"},{"name":"Solomon Islands","code":"SB"},{"name":"Somalia","code":"SO"},{"name":"South Africa","code":"ZA"},{"name":"South Georgia and the South Sandwich Islands","code":"GS"},{"name":"Spain","code":"ES"},{"name":"Sri Lanka","code":"LK"},{"name":"Sudan","code":"SD"},{"name":"Suriname","code":"SR"},{"name":"Svalbard and Jan Mayen","code":"SJ"},{"name":"Swaziland","code":"SZ"},{"name":"Sweden","code":"SE"},{"name":"Switzerland","code":"CH"},{"name":"Syrian Arab Republic","code":"SY"},{"name":"Taiwan, Province of China","code":"TW"},{"name":"Tajikistan","code":"TJ"},{"name":"Tanzania, United Republic of","code":"TZ"},{"name":"Thailand","code":"TH"},{"name":"Timor-Leste","code":"TL"},{"name":"Togo","code":"TG"},{"name":"Tokelau","code":"TK"},{"name":"Tonga","code":"TO"},{"name":"Trinidad and Tobago","code":"TT"},{"name":"Tunisia","code":"TN"},{"name":"Turkey","code":"TR"},{"name":"Turkmenistan","code":"TM"},{"name":"Turks and Caicos Islands","code":"TC"},{"name":"Tuvalu","code":"TV"},{"name":"Uganda","code":"UG"},{"name":"Ukraine","code":"UA"},{"name":"United Arab Emirates","code":"AE"},{"name":"United Kingdom","code":"GB"},{"name":"United States","code":"US"},{"name":"United States Minor Outlying Islands","code":"UM"},{"name":"Uruguay","code":"UY"},{"name":"Uzbekistan","code":"UZ"},{"name":"Vanuatu","code":"VU"},{"name":"Venezuela","code":"VE"},{"name":"Viet Nam","code":"VN"},{"name":"Virgin Islands, British","code":"VG"},{"name":"Virgin Islands, U.S.","code":"VI"},{"name":"Wallis and Futuna","code":"WF"},{"name":"Western Sahara","code":"EH"},{"name":"Yemen","code":"YE"},{"name":"Zambia","code":"ZM"},{"name":"Zimbabwe","code":"ZW"}] self.akiObj = Akinator() self.gameCache = {} self.session = ClientSession() self.sp = _Spotify(auth_manager=SpotifyClientCredentials(client_id=environ["SP_ID"], client_secret=environ["SP_SECRET"])) self.collection = MongoClient(environ["MONGODB_URL"])["Coins"]["Points/others"] self.goodmessages = ["Wow speedy!", "Nice time!", "That was pretty good!", "Wow, you fast at typing!", "You speedy, that's for sure!"] self.badmessages = ["How slow can you type?", "That was slow!", "You need to practice more!", "It's ok i won't tell anybody that your a slow typer"] self.aliaresponses = [ "Ali A Kills Himself", "Ali A Ignores And Hits A 360 Noscope", "Ali A Approves", "Ali A Dosnt Approve" ] self._8ball_responses = [ "It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "World Says Yes!", "Signs point to yes.", "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Dont count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "World Thinks Its Very doubtful.", ] self.hearts = ['💔', '💝', '💚', '💙', '💜'] self.kills = [ "they stole money from your bank", "they ate your cookies", "they tried to steal your phone", "they smelled like poop", "they didn't like you", "they lied to you", "they didnt trust you" ]
async def akinator(self, ctx): """J'ai glissé chef Implémentation directe de https://pypi.org/project/akinator.py Warning: Commande en bêta, non couverte par les tests unitaires. """ # Un jour mettre ça dans des embeds avec les https://fr.akinator.com/ # bundles/elokencesite/images/akitudes_670x1096/<akitude>.png croppées, # <akitude> in ["defi", "serein", "inspiration_legere", # "inspiration_forte", "confiant", "mobile", "leger_decouragement", # "vrai_decouragement", "deception", "triomphe"] await ctx.send("Vous avez demandé à être mis en relation avec " + tools.ital("Akinator : Le Génie du web") + ".\nVeuillez patienter...") async with ctx.typing(): # Connexion aki = Akinator() question = await aki.start_game(language="fr") exit = False while not exit and aki.progression <= 80: mess = await ctx.send(f"({aki.step + 1}) {question}") reponse = await tools.wait_for_react_clic(mess, { "👍": "yes", "🤷": "idk", "👎": "no", "⏭️": "stop" }) if reponse == "stop": exit = True else: async with ctx.typing(): question = await aki.answer(reponse) async with ctx.typing(): await aki.win() mess = await ctx.send( f"Tu penses à {tools.bold(aki.first_guess['name'])} " f"({tools.ital(aki.first_guess['description'])}) !\n" f"J'ai bon ?\n{aki.first_guess['absolute_picture_path']}") if await tools.yes_no(mess): await ctx.send("Yay\nhttps://fr.akinator.com/bundles/elokencesite" "/images/akitudes_670x1096/triomphe.png") else: await ctx.send("Oof\nhttps://fr.akinator.com/bundles/elokencesite" "/images/akitudes_670x1096/deception.png")
async def aki(self, ctx: commands.Context, *, language: str.lower = "en"): """ Start a game of Akinator! Controls: > ✅ : yes > ❎ : no > ❔ : i don't know > 🤔 : probably > 🤷♂️ : probably not > ◀️ : back > 🏆 : win > 🗑️ : cancel """ # Send emoji info embed = discord.Embed( title = "Akinator", description = "**Controls**:\n \ ✅ : yes \n \ ❎ : no \n \ ❔ : i don't know \n \ 🤔 : probably \n \ 🤷♂️ : probably not \n \ ◀️ : back \n \ 🏆 : win \n \ 🗑️ : cancel", color = 0xf34949 ) await ctx.send(embed = embed, delete_after = 20) await ctx.trigger_typing() aki = Akinator() try: await aki.start_game(language = language.replace(" ", "_")) except akinator.InvalidLanguageError: await ctx.send( "Invalid language. Refer here to view valid languages.\ \n<https://github.com/NinjaSnail1080/akinator.py#functions>" ) except Exception: await ctx.send("I encountered an error while connecting to the Akinator servers.") else: menu = AkiMenu(aki) await menu.start(ctx)
async def aki(self, ctx: commands.Context): """ Начни игру в Акинатор! Управление: > ✅ : да > ❎ : нет > ❔ : я не знаю > 📉 : скорее да > 📈 : скорее нет > 🔙 : назад > 🏆 : выиграл > 🗑️ : отменить """ await ctx.trigger_typing() aki = Akinator() try: await aki.start_game(language="ru") except Exception: return await ctx.send( "Я обнаружил ошибку при подключении к серверам Akinator.") menu = AkiMenu(aki, await ctx.embed_color()) await menu.start(ctx)
async def aki(self, ctx: commands.Context): """ Start a game of Akinator! Controls: > ✅ : yes > ❎ : no > ❔ : i don't know > 📉 : probably > 📈 : probably not > 🔙 : back > 🏆 : win > 🗑️ : cancel """ await ctx.trigger_typing() aki = Akinator() try: await aki.start_game() except Exception: return await ctx.send( "I encountered an error while connecting to the Akinator servers." ) menu = AkiMenu(aki, await ctx.embed_color()) await menu.start(ctx)
"""A simple test of the async Akinator class""" from akinator.async_aki import Akinator import akinator import asyncio aki = Akinator() async def main(): try: q = await aki.start_game() except (akinator.AkiServerDown, akinator.AkiTechnicalError): try: q = await aki.start_game("en2") except (akinator.AkiServerDown, akinator.AkiTechnicalError): q = await aki.start_game("en3") while aki.progression <= 80: a = input(q + "\n\t") if a == "b": try: q = await aki.back() except akinator.CantGoBackAnyFurther: pass else: q = await aki.answer(a) await aki.win() correct = input( f"It's {aki.name} ({aki.description})! Was I correct?\n{aki.picture}\n\t"
async def aki(self, ctx: commands.Context): """Play akinator! **Always respond within 30 seconds** Valid question responses: - **Yes**: yes, y, 0 - **No**: no, n, 1 - **I don't know**: i, idk, 2 - **Probably**: probably, p, 3 - **Probably Not**: probably not, pn, 4 - **Stop**: stop, s, 5 - **Back**: back, b, 6 """ await ctx.trigger_typing() index = 1 akinator = Akinator() question = await akinator.start_game(child_mode=True) # Convert the list of tupes of values into a list of all the valid responses akinator_valid_responses = [ response for values in AKINATOR_RESPONSES.values() for response in values ] def check(message: Message): return (message.channel == ctx.channel and message.author == ctx.author and message.content.lower() in akinator_valid_responses) while akinator.progression <= 80: await ctx.trigger_typing() embed = Embed( title=f"{ctx.author.display_name}, Question {index}", color=Color.gold(), timestamp=ctx.message.created_at, ) embed.add_field( name=f"**{question}**", value= "[yes (**y**) / no (**n**) / idk (**i**) / probably (**p**) / probably not (**pn**)]\ \n[back (**b**)]\ \n[stop (**s**)]", ) await ctx.reply(embed=embed) try: answer_message = await self.bot.wait_for("message", check=check, timeout=30) except asyncio.TimeoutError: raise AkiError("You didn't respond in time!") if answer_message.content.lower() in AKINATOR_RESPONSES.get( "stop"): await ctx.reply("Aki stopped!") return if answer_message.content.lower() in AKINATOR_RESPONSES.get( "back"): question = await akinator.back() index -= 1 else: question = await akinator.answer(answer_message.content) index += 1 await akinator.win() embed = Embed(title=akinator.first_guess["name"], color=Color(random.randint(0, 0xFFFFFF))) embed.set_image(url=akinator.first_guess["absolute_picture_path"]) embed.add_field(name="From", value=akinator.first_guess["description"]) embed.set_footer(text="Was I Correct? | y/yes/n/no") await ctx.reply(embed=embed) def confirmation_check(message: Message): return message.channel == ctx.channel and message.author == ctx.author try: confirmation_message = await self.bot.wait_for( "message", check=confirmation_check, timeout=10) response = confirmation_message.content.lower() if response in AKINATOR_RESPONSES.get("yes"): await ctx.reply("I Guessed correct, Once Again") elif response in AKINATOR_RESPONSES.get("no"): await ctx.reply("I have been defeated. You Win.") else: await ctx.reply( "I don't know what that means but I'll take it as a win ") except TimeoutError: raise AkiError("You didn't respond in time!")
def setup(bot): bot.add_cog(Akinator(bot))
from utils.errors import TooLong from utils.checks import gameRunning import discord, io, asyncdagpi, asyncio, datetime, string, random, json, wonderwords, typing from discord.ext import commands from fuzzywuzzy import fuzz from gtts import gTTS from jishaku.functools import executor_function from utils.get import * from utils.functions import * from akinator.async_aki import Akinator from cogs.music import is_vc from cogs.utility import cleanup, make dagpi = asyncdagpi.Client(get_config("DAGPI")) akin = Akinator() @executor_function def do_tts(message): array = io.BytesIO() tts = gTTS(text=message, lang="en") tts.write_to_fp(array) array.seek(0) return array @executor_function def vctts(message, path): res = gTTS(text=message, lang="en") res.save(f"{path.name}/file.wav")
async def _akinator(self, ctx, language='en'): aki = Akinator() nsfw = ctx.channel.is_nsfw() valid = ['✅', '❌', '🔙', '🤷♀️'] def check(reaction, user): return str(reaction.emoji) in valid and user == ctx.message.author async def main(): q = await aki.start_game(language=language, child_mode=nsfw) embed = discord.Embed(title="Akinator Asks", description=q) mess = await ctx.send(embed=embed) await mess.add_reaction('✅') await mess.add_reaction('❌') await mess.add_reaction('🔙') await mess.add_reaction('🤷♀️') while aki.progression <= 80: reaction, user = await self.client.wait_for('reaction_add', timeout=120, check=check) try: if str(reaction.emoji) == '🔙': try: q = await aki.back() except akinator.CantGoBackAnyFurther: pass elif str(reaction.emoji) == '❌': q = 'yes' elif str(reaction.emoji) == '✅': q = 'no' elif str(reaction.emoji) == '🤷♀️': q = 'idk' except Exception as e: ctx.send(e) finally: qe = await aki.answer(q) embed = discord.Embed(title='\r\u200b', description=qe) mess = await ctx.send(embed=embed) await mess.add_reaction('✅') await mess.add_reaction('❌') await mess.add_reaction('🔙') await mess.add_reaction('🤷♀️') await aki.win() first_guess = dict(aki.first_guess) embed = discord.Embed( title= f"It's {first_guess['name']} ({first_guess['description']}!) Was I correct?", image=first_guess['absolute_picture_path']) msg = await ctx.send(embed=embed) await msg.add_reaction('✅') await msg.add_reaction('❌') try: correct, user = await self.client.wait_for('reaction_add', timeout=120, check=check) except asyncio.TimeoutError: pass if str(correct.emoji) == "✅": await ctx.send("Yay\n") else: await ctx.send("Oof\n") loop = asyncio.get_event_loop() #if this doesnt work try loop.run_until_complete(man) or loop.run_until_complete(await man()) loop.run_until_complete(main()) loop.close()
async def new_game(self, user, lang): player: Player = convert_users_to_players(user)[0] game = Akinator() first_question = await game.start_game(language=lang) self.games[player.id] = game return game, first_question
async def __aki(self, ctx): """A command that lets you play a game of Akinator. Choose any character and I will try to guess it!""" aki = Akinator() def check(m): return m.channel == ctx.channel and m.author == ctx.author q = await aki.start_game() progression = 80 while True: embed = discord.Embed(title=q, color=discord.Colour.red()) embed.set_author(name=f'{ctx.author} - Question {aki.step + 1}', icon_url=str( ctx.author.avatar_url_as(format='png'))) embed.set_footer( text= "y = Yes, n = No, idk = I don't know, p = Probably, pn = Probably not, b = back" ) await ctx.send(embed=embed) while True: try: a = await self.bot.wait_for('message', timeout=15, check=check) except asyncio.TimeoutError: await ctx.send( f'{ctx.author.mention}, you took too long to give an answer! Game canceled.' ) return if a.content.lower() in ['back', 'b']: try: a = await aki.back() except akinator.CantGoBackAnyFurther: await ctx.send('You cannot go back any further!') elif a.content.lower() in [ "i don't know", 'idk', 'i', 'i dont know' ]: a = 2 elif a.content.lower() in ['yes', 'y']: a = 0 elif a.content.lower() in ['no', 'n']: a = 1 elif a.content.lower() in ['probably not', 'pn']: a = 4 elif a.content.lower() in ['probably', 'p']: a = 3 else: continue break try: q = await aki.answer(a) except akinator.AkiNoQuestions: await ctx.send( f'I have run out of questions to give you! You stumped me!' ) return if aki.progression >= progression: await aki.win() guess = aki.first_guess embed = discord.Embed(title=guess['name'], color=discord.Colour.red(), description=guess['description'], url=guess['absolute_picture_path']) embed.set_image(url=guess['absolute_picture_path']) embed.set_author(name='Is This Your Character?') await ctx.send(embed=embed) try: correct = await self.bot.wait_for('message', timeout=15, check=check) except asyncio.TimeoutError: correct = 'y' if correct.content.lower() in ['y', 'yes']: await ctx.send( 'Guessed right one more time! I love playing with you!' ) return elif correct.content.lower() in ['n', 'no']: if progression == 80: progression = 90 else: await ctx.send( 'Dang it, you stumped me! Please play again sometime.' ) return else: return