Skip to content

Commit

Permalink
added automatic monthly backup system
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jan 20, 2024
1 parent e5fd074 commit 9e1fcb9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 26 deletions.
25 changes: 24 additions & 1 deletion bruhbot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from datetime import date
from datetime import date, datetime
import json
import os
import random
Expand Down Expand Up @@ -49,6 +49,22 @@ def plural(num: int):
await asyncio.sleep(3600)


async def auto_backup():
with open(f"{here}\\bruhbot\\data.json", "r+") as f:
data = json.load(f)
now = date.today()
print(now)
last = datetime.strptime(data["lastbackup"], "%Y-%m-%d")
rdelta = relativedelta(now, last)
if rdelta.months >= 1:
ResponseBackup.run()
data["lastbackup"] = now.strftime("%Y-%m-%d")
f.seek(0)
json.dump(data, f, indent=4)
else:
return


async def send_dm(user: discord.User, content: discord.Embed):
dm = await user.create_dm()
await dm.send(embed=content)
Expand Down Expand Up @@ -95,6 +111,7 @@ async def send_image(ctx, response: str):
async def on_ready():
servers = list(bot.guilds)
print(f"{bot.user.name}(ID:{bot.user.id}) connected to {str(len(servers))} servers")
await auto_backup()
await check_age()


Expand Down Expand Up @@ -951,6 +968,12 @@ async def time(ctx):
@commands.is_owner()
async def backup(ctx):
ResponseBackup.run()
with open(f"{here}\\bruhbot\\data.json", "r+") as f:
data = json.load(f)
now = date.today()
data["lastbackup"] = now.strftime("%Y-%m-%d")
f.seek(0)
json.dump(data, f, indent=4)
await ctx.send("Response list saved to backup.")


Expand Down
Binary file modified bruhbot/cogs/Names/__pycache__/names.cpython-38.opt-1.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion bruhbot/cogs/Names/names.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
"Buckachino",
"Penile",
"Brumbpo",
"Cremrold"
"Cremrold",
"Chad"
],
"lastnames": [
"McDichael",
Expand Down
Binary file modified bruhbot/cogs/OPBR/__pycache__/OPBR.cpython-38.opt-1.pyc
Binary file not shown.
49 changes: 25 additions & 24 deletions bruhbot/data.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"addr": {
"description": "```Syntax: $addr [phrase/image name]```\n**Add Responses.**\nAdds a new response to the list.\nImages support custom names."
},
"delr": {
"description": "```Syntax: $delr```\n**Delete responses.**\nDisplays a menu that allows a user to delete a specific response."
},
"rlist": {
"description": "```Syntax: $rlist```\n**Show response list.**\nDisplays the list of possible responses."
},
"age": {
"description": "```Syntax: $age```\n**Check bot age.**\nReturns number of years/months/days since creation."
},
"forza": {
"name": "Check Forza season",
"description": "```Syntax: $forza```\n**Check current Forza season**\nReturns the current season for both Horizon 4 and Horizon 5\n\n**__Subcommands__**\n**time** Displays the time until the next season"
},
"response": {
"name": "__**Response**__",
"description": "**addr** Add a new response to the list.\n**delr** Remove a response from the list.\n**rlist** View the list of current responses."
},
"extra": {
"name": "__**Extra Stuff**__",
"description": "**age** Returns the current age of the bot."
}
"lastbackup": "2024-01-19",
"addr": {
"description": "```Syntax: $addr [phrase/image name]```\n**Add Responses.**\nAdds a new response to the list.\nImages support custom names."
},
"delr": {
"description": "```Syntax: $delr```\n**Delete responses.**\nDisplays a menu that allows a user to delete a specific response."
},
"rlist": {
"description": "```Syntax: $rlist```\n**Show response list.**\nDisplays the list of possible responses."
},
"age": {
"description": "```Syntax: $age```\n**Check bot age.**\nReturns number of years/months/days since creation."
},
"forza": {
"name": "Check Forza season",
"description": "```Syntax: $forza```\n**Check current Forza season**\nReturns the current season for both Horizon 4 and Horizon 5\n\n**__Subcommands__**\n**time** Displays the time until the next season"
},
"response": {
"name": "__**Response**__",
"description": "**addr** Add a new response to the list.\n**delr** Remove a response from the list.\n**rlist** View the list of current responses."
},
"extra": {
"name": "__**Extra Stuff**__",
"description": "**age** Returns the current age of the bot."
}
}

0 comments on commit 9e1fcb9

Please sign in to comment.