robocronp: send data files hourly

This aims to reduce data loss

Also, stopped calling these config files and started calling them data files
This commit is contained in:
Ave Ozkal 2018-12-29 10:47:08 +03:00
parent f637e646fd
commit 1cc8c9a9ee
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
4 changed files with 24 additions and 10 deletions

View file

@ -103,6 +103,7 @@ Main goal of this project is to get Robocop functionality done, secondary goal i
<p>
[ ] Reduce code repetition on mod_timed.py
[ ] Allow non-hour values on timed bans
the following require me to rethink some of the lockdown code, which I don't feel like

View file

@ -93,8 +93,8 @@ async def on_ready():
msg = f"{bot.user.name} has started! "\
f"{guild.name} has {guild.member_count} members!"
config_files = [discord.File(fpath) for fpath in wanted_jsons]
await log_channel.send(msg, files=config_files)
data_files = [discord.File(fpath) for fpath in wanted_jsons]
await log_channel.send(msg, files=data_files)
await bot.change_presence(activity=discord.Game(name=game_name))

View file

@ -47,8 +47,8 @@ class Admin:
@commands.command()
async def fetchdata(self, ctx):
"""Returns data files"""
config_files = [discord.File(fpath) for fpath in self.bot.wanted_jsons]
await ctx.send("Here you go:", files=config_files)
data_files = [discord.File(fpath) for fpath in self.bot.wanted_jsons]
await ctx.send("Here you go:", files=data_files)
@commands.guild_only()
@commands.check(check_if_bot_manager)

View file

@ -12,7 +12,12 @@ class Robocronp:
def __init__(self, bot):
self.bot = bot
bot.loop.create_task(self.minutely())
# bot.loop.create_task(self.hourly())
bot.loop.create_task(self.hourly())
async def send_data(self):
data_files = [discord.File(fpath) for fpath in self.bot.wanted_jsons]
log_channel = self.bot.get_channel(config.log_channel)
await log_channel.send("Hourly data backups:", files=data_files)
@commands.guild_only()
@commands.check(check_if_staff)
@ -81,11 +86,19 @@ class Robocronp:
pass
await asyncio.sleep(60)
# async def hourly(self):
# await self.bot.wait_until_ready()
# while not self.bot.is_closed():
# # Your stuff goes here
# await asyncio.sleep(3600)
async def hourly(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed():
# Your stuff that should run at boot
# and after that every hour goes here
await asyncio.sleep(3600)
try:
await self.send_data()
except:
# Don't kill cronjobs if something goes wrong.
pass
# Your stuff that should run an hour after boot
# and after that every hour goes here
def setup(bot):