Right now, feeding yak_scraper a command like $help ../../ results in no output. This is probably fine, but it would be good to trigger an explicit failure whenever $help tries to open a non-existent file or non-file object.
I think the easiest way to do this would be to append something like .txt to all help file names, ans then modify the servefiles function to be something like this:
async def servefiles(hf,hd,ow,m):
target=await dmchan(m.author.id)
if ow=='':
fname=LOCALDIR+re.sub('^.*[^\w]', '', hf)+'.txt'
else:
fname=LOCALDIR+'/'+hd+'/'+re.sub('^.*[^\w]', '', ow)+'.txt'
if os.path.exists(fname):
with open(fname) as f:
s=f.read()
await splitsend(target,s,False)
else:
s="Sorry, no help exists for that"
await splitsend(target,s,False)
I just wrote that extemporaneously, so it may very well not work, but I think should give you an idea about what I'm thinking of. Since there's no file named .txt in either of the help directories, this will guarantee that we'll error out when handed an invalid string that can't be easily translated to a valid one.
Right now, feeding
yak_scraper
a command like$help ../../
results in no output. This is probably fine, but it would be good to trigger an explicit failure whenever$help
tries to open a non-existent file or non-file object.I think the easiest way to do this would be to append something like
.txt
to all help file names, ans then modify theservefiles
function to be something like this:I just wrote that extemporaneously, so it may very well not work, but I think should give you an idea about what I'm thinking of. Since there's no file named
.txt
in either of the help directories, this will guarantee that we'll error out when handed an invalid string that can't be easily translated to a valid one.