Guest User

Untitled

a guest
Sep 2nd, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1.     def jsonisp(self, url):
  2.         return requests.get(url).json()
  3.  
  4.     @commands.command()
  5.     @commands.cooldown(1, 30, commands.BucketType.user)
  6.     async def geoquiz(self, ctx):
  7.         wait = await ctx.send(' | Porfavor espera... se te esta generando el test...')
  8.         data, topic = self.jsonisp("https://restcountries.eu/rest/v2/"), random.choice(['capital', 'region', 'subregion', 'population', 'demonym', 'nativeName'])
  9.         chosen_nation_num = random.randint(0, len(data))
  10.         chosen_nation, wrongs = data[chosen_nation_num], []
  11.         data.remove(data[chosen_nation_num])
  12.         correct = str(chosen_nation[topic])
  13.         for i in range(0, 4):
  14.             integer = random.randint(0, len(data))
  15.             wrongs.append(str(data[integer][str(topic)]))
  16.             data.remove(data[integer])
  17.         emot, static_emot, corr_order_num = list('🇦🇧🇨🇩'), list('🇦🇧🇨🇩'), random.randint(0, 3)
  18.         corr_order = emot[corr_order_num]
  19.         emot[corr_order_num], question, guy = '0', '', ctx.author
  20.         for emote in emot:
  21.             if emote!='0':
  22.                 added = random.choice(wrongs)
  23.                 question += emote + ' ' + added + '\n'
  24.                 wrongs.remove(added)
  25.             else:
  26.                 question += corr_order + ' ' + correct + '\n'
  27.         trans = Translator()
  28.         translated_topic = trans.translate(topic, src='en', dest='es')
  29.         translated_nation = trans.translate(chosen_nation['name'], src='en', dest='es')
  30.         translated_question = trans.translate(question, src='en', dest='es')
  31.         translated_corr_order = trans.translate(corr_order, src='en', dest='es')
  32.  
  33.         embed = discord.Embed(title='Test de geografia: '+str(translated_topic.text), description=':nerd: Haz click en la reaccion! **Tienes 20 segundos.**\n\nQue '+str(translated_topic.text)+' pertenece a '+str(translated_nation.text)+'?\n\n'+str(translated_question.text), colour=color)
  34.         await wait.edit(content='', embed=embed)
  35.         for i in range(0, len(static_emot)):
  36.             await wait.add_reaction(static_emot[i])
  37.         def check(reaction, user):
  38.             return user == guy
  39.         try:
  40.             reaction, user = await self.bot.wait_for('reaction_add', timeout=20.0, check=check)
  41.         except asyncio.TimeoutError:
  42.             await wait.add_reaction('😔')
  43.         if str(reaction.emoji)==str(corr_order):
  44.             await wait.edit(content='', embed=discord.Embed(title="¡Correcto!", description=' | <@'+str(guy.id)+'>, felizidades! Estas correcto. :partying_face:\n\nY se te han añadido diamantes a tu cuenta', colour=color))
  45.             diamantes_dados = random.randint(10, 30)
  46.             user = ctx.author
  47.             with open("mainbank.json", "r") as f:
  48.                 users = json.load(f)
  49.             users[str(user.id)]["wallet"] += diamantes_dados
  50.             with open("mainbank.json", "w") as f:
  51.                 json.dump(users, f)            
  52.         else:
  53.             await wait.edit(content='', embed=discord.Embed(title="¡Incorrecto!", description=' | <@'+str(guy.id)+f'>, Estas **incorrecto**. La respuesta era {translated_corr_order.text}', colour=color))
  54.  
Add Comment
Please, Sign In to add comment