Some minor 'eval' command changes in misc.
This commit is contained in:
parent
8ae7a6970c
commit
508dc04eac
|
@ -10,40 +10,37 @@ import gzip
|
|||
|
||||
import requests
|
||||
|
||||
from bot import command, parser
|
||||
import bot
|
||||
|
||||
# public python GAE api url. thanks sopel
|
||||
PY_APP_URL = 'https://tumbolia-sopel.appspot.com/py/'
|
||||
PY_APP_URL = 'https://tumbolia-sopel.appspot.com/py/{}'
|
||||
# requests session
|
||||
#req_ses = requests.Session()
|
||||
|
||||
# function that sends eval request. runs in separate thread
|
||||
def do_eval( evstr ):
|
||||
rstr = 'Error.'
|
||||
@bot.command( 'eval' )
|
||||
async def cmd_eval( b, p, c ):
|
||||
""" Evaluates Python code. Trust me, it's safe. """
|
||||
evstr = urllib.parse.quote( ' '.join( p ) )
|
||||
|
||||
try:
|
||||
res = requests.get( PY_APP_URL + evstr, timeout=3.0 )
|
||||
res = await b._loop.run_in_executor( None,
|
||||
functools.partial( requests.get, PY_APP_URL.format( evstr ), timeout=3.0 ) )
|
||||
|
||||
rstr = res.text.rstrip().lstrip()
|
||||
|
||||
if not res.ok: rstr = 'Server error ' + str(res.status_code)+'.'
|
||||
if rstr == '': rstr = 'No response.'
|
||||
|
||||
except: rstr = random.random() < 0.25 and 'I\'ll do it later.' or 'Response timed out.'
|
||||
|
||||
return rstr
|
||||
|
||||
@command( 'eval' )
|
||||
async def cmd_eval( b, p, c ):
|
||||
""" Evaluates Python code. Trust me, it's safe. """
|
||||
evstr = urllib.parse.quote( ' '.join( p ) )
|
||||
# do the actual request in a separate thread
|
||||
rstr = await b._loop.run_in_executor( None, functools.partial( do_eval, evstr ) ) #do_eval, evstr, c )
|
||||
except requests.RequestException as e:
|
||||
rstr = random.random() < 0.25 and 'I\'ll do it later.' or 'Exception during request.'
|
||||
if not isinstance( e, requests.Timeout ):
|
||||
rstr += ' ({})'.format( str(e) )
|
||||
else: rstr += ' (Request timed out.)'
|
||||
|
||||
c['con'].say_to( c['dst'], '> {}'.format( rstr ) )
|
||||
|
||||
# parser test
|
||||
@parser()
|
||||
@bot.parser()
|
||||
def parse_misc( c, d, n, m ):
|
||||
if m.split()[0].lower() == '!botlist' or m.split()[0].lower() == '!rollcall':
|
||||
pfx = ';' # HAX
|
||||
|
@ -51,7 +48,7 @@ def parse_misc( c, d, n, m ):
|
|||
'Source: https://tildegit.org/slipyx/dustbot | Prefix: \'{}\'. | '
|
||||
'Commands: See \'{}list\'.').format( c.cfg['usr']['owner'],pfx,pfx ) )
|
||||
|
||||
@command( 'rfk' )
|
||||
@bot.command( 'rfk' )
|
||||
async def cmd_rfk( b, p, c ):
|
||||
""" Try to find kitten! """
|
||||
nki = ''
|
||||
|
|
Loading…
Reference in New Issue