mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Few changes in Phrases module
This commit is contained in:
parent
45321f4848
commit
73e19b60d4
@ -20,39 +20,42 @@ class Phrases(commands.Cog):
|
|||||||
def bot(self, newBot):
|
def bot(self, newBot):
|
||||||
self.__bot = newBot
|
self.__bot = newBot
|
||||||
|
|
||||||
@commands.command(name='frase', help='Envia uma frase legal no seu PV')
|
@commands.command(name='frase', help='Envia uma frase pica, talvez a braba')
|
||||||
async def send_phrase(self, ctx):
|
async def phrase(self, ctx):
|
||||||
# There is a chance that the phrase will be send for the dev
|
# There is a chance that the phrase will be send for the dev
|
||||||
sended = await self.calculate_rgn(ctx)
|
secret = await self.__calculate_rgn()
|
||||||
if sended:
|
if secret != None:
|
||||||
return
|
await ctx.send(secret)
|
||||||
|
else:
|
||||||
|
phrase = await self.__get_phrase()
|
||||||
|
await ctx.send(phrase)
|
||||||
|
|
||||||
|
async def __calculate_rgn(self):
|
||||||
|
x = rand()
|
||||||
|
if x < 0.15:
|
||||||
|
return config.SECRET_MESSAGE
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def __get_phrase(self):
|
||||||
|
tries = 0
|
||||||
while True:
|
while True:
|
||||||
|
tries += 1
|
||||||
|
if tries > config.MAX_API_PHRASES_TRIES:
|
||||||
|
return 'O banco de dados dos cara tá off, bando de vagabundo, tenta depois aí bicho'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(config.PHRASES_API)
|
||||||
'http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en')
|
|
||||||
data = json.loads(response.content)
|
data = json.loads(response.content)
|
||||||
|
|
||||||
phrase = data['quoteText']
|
phrase = data['quoteText']
|
||||||
author = data['quoteAuthor']
|
author = data['quoteAuthor']
|
||||||
|
|
||||||
text = f'{phrase} \nBy: {author}'
|
text = f'{phrase} \nBy: {author}'
|
||||||
await ctx.send(text)
|
|
||||||
break
|
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
continue
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
await ctx.channel.send('Houve um erro inesperado :/')
|
|
||||||
break
|
|
||||||
|
|
||||||
async def calculate_rgn(self, ctx):
|
return text
|
||||||
x = rand()
|
except Exception as e:
|
||||||
if x < 0.15:
|
continue
|
||||||
await ctx.send(config.SECRET_MESSAGE)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user