Changed saving method to check if json can dump the content, before truncating the file
This commit is contained in:
parent
a9267f106e
commit
706dedb980
11
bot.py
11
bot.py
|
@ -57,15 +57,14 @@ async def on_command_error(error, ctx):
|
|||
elif isinstance(error, commands.CheckFailure):
|
||||
fmt = "You can't tell me what to do!"
|
||||
await bot.send_message(ctx.message.channel, fmt)
|
||||
# elif isinstance(error, commands.CommandInvokeError):
|
||||
# f = open("/home/phxntx5/public_html/Bonfire/error_log", 'w')
|
||||
# print('In {0.command.qualified_name}:'.format(ctx), file=f)
|
||||
# traceback.print_tb(error.original.__traceback__, file=f)
|
||||
# print('{0.__class__.__name__}: {0}'.format(error.original), file=f)
|
||||
else:
|
||||
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
|
||||
await bot.send_message(ctx.message.channel, fmt.format(type(error).__name__, error))
|
||||
|
||||
with open("/home/phxntx5/public_html/Bonfire/error_log", 'w') as f:
|
||||
print('In {0.command.qualified_name}:'.format(ctx), file=f)
|
||||
traceback.print_tb(error.original.__traceback__, file=f)
|
||||
print('{0.__class__.__name__}: {0}'.format(error.original), file=f)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for e in extensions:
|
||||
|
|
|
@ -22,19 +22,19 @@ def saveContent(key: str, content):
|
|||
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
|
||||
data = json.load(jf)
|
||||
jf.seek(0)
|
||||
newData = dict(data)
|
||||
newData[key] = content
|
||||
jf.truncate()
|
||||
data[key] = content
|
||||
try:
|
||||
json.dump(newData, jf, indent=4)
|
||||
json.dumps(data)
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
jf.truncate()
|
||||
json.dump(data, jf, indent=4)
|
||||
|
||||
|
||||
def getContent(key: str):
|
||||
try:
|
||||
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
|
||||
data = json.load(jf)
|
||||
return data[key]
|
||||
return json.load(jf)[key]
|
||||
except KeyError:
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue