Browse Source

robocronp: send data files hourly

This aims to reduce data loss

Also, stopped calling these config files and started calling them data files
main
Ave Ozkal 2 years ago
parent
commit
16f0f65c2a
4 changed files with 24 additions and 10 deletions
  1. +1
    -0
      README.md
  2. +2
    -2
      Robocop.py
  3. +2
    -2
      cogs/admin.py
  4. +19
    -6
      cogs/robocronp.py

+ 1
- 0
README.md 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


+ 2
- 2
Robocop.py 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))


+ 2
- 2
cogs/admin.py 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)


+ 19
- 6
cogs/robocronp.py 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):


Loading…
Cancel
Save