Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

Commit

Permalink
make json stuff cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
XuaTheGrate committed Oct 9, 2019
1 parent 644d081 commit 33341d2
Show file tree
Hide file tree
Showing 9 changed files with 2,642 additions and 6,824 deletions.
9,032 changes: 2,521 additions & 6,511 deletions base-demons.json

Large diffs are not rendered by default.

46 changes: 39 additions & 7 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import os
import random
import traceback
from datetime import datetime, timedelta
from datetime import datetime, timedelta, time

import aiohttp
import aioredis
import discord
import motor.motor_asyncio
from discord.ext import commands
from discord.ext import commands, tasks

import config
from cogs.utils import i18n, formats
Expand Down Expand Up @@ -120,11 +120,11 @@ async def confirm(self, message, waiter=None):

class Abyss(commands.AutoShardedBot):
def __init__(self, **kwargs):
self.pipe = kwargs.pop('pipe')
self.cluster_name = kwargs.pop('cluster_name')
self.pipe = kwargs.pop('pipe', None)
self.cluster_name = kwargs.pop('cluster_name', 'beta')
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
super().__init__(commands.when_mentioned_or("$"), **kwargs, loop=loop)
super().__init__(commands.when_mentioned_or("$$"), **kwargs, loop=loop)
self.remove_command("help") # fuck you danny
self.prepared = asyncio.Event()
# `prepared` is to make sure the bot has loaded the database and such
Expand All @@ -143,6 +143,10 @@ def __init__(self, **kwargs):
self.map_handler = MapHandler(self)
self.item_cache = None

if self.cluster_name == 'Alpha':
# ensure this task only runs on the first cluster
self.midnight_helper.start()

logger = logging.getLogger('discord')
# log.setLevel(logging.DEBUG)
handler = BetterRotatingFileHandler(f'logs/Abyss-{self.cluster_name}-discord.log', encoding='utf-8')
Expand All @@ -156,6 +160,33 @@ def __init__(self, **kwargs):
self.prepare_extensions()
self.run()

@tasks.loop(time=time(0, 0, 0))
async def midnight_helper(self):
self.log.info("we reached midnight")
await self.prepared.wait()
cur = False
keys = set()
while cur != 0:
cur, k = await self.redis.scan(cur or 0, match='p_sp_used*', count=1000)
keys.update(k)
for key in keys:
await self.redis.set(key, 0)
self.log.info(f"reset sp of {len(keys)} players")
cur = False
keys.clear()
while cur != 0:
cur, k = await self.redis.scan(cur or 0, match='treasures_found:*', count=1000)
keys.update(k)
for key in keys:
await self.redis.delete(key)
self.log.info(f'reset treasures of {len(keys)} players')

@midnight_helper.after_loop
async def post_midnight_loop_complete(self, *args, **kwargs):
exc = self.midnight_helper.exception()
if exc:
self.send_error(f'>>> Error occured in midnight_helper task\n```py\n{formats.format_exc(exc)}\n```')

async def on_command_error(self, *__, **_):
pass

Expand Down Expand Up @@ -301,8 +332,9 @@ async def on_ready(self):
self.start_date = datetime.utcnow()
self.log.warning("Successfully loaded.")
await self.change_presence(activity=discord.Game(name="$cmds"))
self.pipe.send(1)
self.pipe.close()
if self.pipe:
self.pipe.send(1)
self.pipe.close()

async def on_message(self, message):
if message.author.bot:
Expand Down
11 changes: 7 additions & 4 deletions items/healing.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
"desc": "Heals 10 SP to one ally.",
"heal_type": "sp",
"heal_amount": 10,
"target": "ally"
"target": "ally",
"weight": 5
},
{
"name": "Medicine",
"worth": 150,
"desc": "Heals 50 HP to one ally.",
"heal_type": "hp",
"heal_amount": 50,
"target": "ally"
"target": "ally",
"weight": 5
},
{
"name": "Hiranya",
"worth": 150,
"desc": "Heals all ailments for one ally.",
"heal_type": "ailment",
"heal_amount": "all",
"target": "ally"
"target": "ally",
"weight": 1
}
]
]
58 changes: 15 additions & 43 deletions items/skill_card.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
[
{
"skill": "Agi"
},
{
"skill": "Bufu"
},
{
"skill": "Garu"
},
{
"skill": "Zio"
},
{
"skill": "Frei"
},
{
"skill": "Psi"
},
{
"skill": "Eiha"
},
{
"skill": "Kouha"
},
{
"skill": "Single Shot"
},
{
"skill": "Lunge"
},
{
"skill": "Tarukaja"
},
{
"skill": "Dia"
},
{
"skill": "Dodge Phys"
},
{
"skill": "Dormina"
}
]
{"skill": "Agi"},
{"skill": "Bufu"},
{"skill": "Garu"},
{"skill": "Zio"},
{"skill": "Frei"},
{"skill": "Psi"},
{"skill": "Eiha"},
{"skill": "Kouha"},
{"skill": "Single Shot"},
{"skill": "Lunge"},
{"skill": "Tarukaja"},
{"skill": "Dia"},
{"skill": "Dodge Phys"},
{"skill": "Dormina"}
]
8 changes: 5 additions & 3 deletions items/trash.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"name": "Stick",
"worth": 1,
"desc": "A stick. Not much else to say."
}
]
"desc": "A stick. Not much else to say.",
"weight": 15
},
{"name": "Stone", "worth": 5, "desc": "A stone. Yea...", "weight": 10}
]
2 changes: 1 addition & 1 deletion maps/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"name": "Sample Dungeon",
"mapfile": "maps/sample_dungeon.json"
}
]
]
34 changes: 6 additions & 28 deletions maps/sample_dungeon.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
"desc": "The main floor of the dungeon. Fairly empty.",
"encounters": ["Arsene", "Pixie", "Mandrake"],
"interactions": [
{
"name": "L Door",
"command": "Left Hall",
"type": 0
},
{
"name": "R Door",
"command": "Right Hall",
"type": 0
}
{"name": "L Door", "command": "Left Hall", "type": 0},
{"name": "R Door", "command": "Right Hall", "type": 0}
],
"treasurecount": 3
},
Expand All @@ -23,31 +15,17 @@
"desc": "Hall to the left of the first floor.",
"encounters": ["Arsene", "Pixie", "Mandrake", "Jack-o'-Lantern"],
"interactions": [
{
"name": "Chest",
"command": "SkillCard:Agi",
"type": 1
},
{
"name": "L Door",
"command": "Floor 1",
"type": 0
}
{"name": "Chest", "command": "SkillCard:Agi", "type": 1},
{"name": "L Door", "command": "Floor 1", "type": 0}
],
"treasurecount": 2
},
{
"name": "Right Hall",
"desc": "Hall to the right of the first floor.",
"encounters": ["Arsene", "Pixie", "Mandrake", "Agathion"],
"interactions": [
{
"name": "R Door",
"command": "Floor 1",
"type": 0
}
],
"interactions": [{"name": "R Door", "command": "Floor 1", "type": 0}],
"treasurecount": 1
}
]
}
}
Loading

0 comments on commit 33341d2

Please sign in to comment.