fetchdata: add .fetchdata and make bot start send data files

This commit is contained in:
Ave Ozkal 2018-12-27 14:44:09 +03:00
parent 6dedd74e97
commit 5521b4aa58
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
2 changed files with 15 additions and 5 deletions

View file

@ -37,6 +37,9 @@ def get_prefix(bot, message):
return commands.when_mentioned_or(*prefixes)(bot, message)
wanted_jsons = ["data/restrictions.json",
"data/userlog.json"]
initial_extensions = ['cogs.common',
'cogs.admin',
'cogs.basic',
@ -58,6 +61,7 @@ bot = commands.Bot(command_prefix=get_prefix,
bot.log = log
bot.config = config
bot.script_name = script_name
bot.wanted_jsons = wanted_jsons
if __name__ == '__main__':
for extension in initial_extensions:
@ -83,7 +87,9 @@ async def on_ready():
log_channel = guild.get_channel(config.log_channel)
msg = f"{bot.user.name} has started! "\
f"{guild.name} has {guild.member_count} members!"
await log_channel.send(msg)
config_files = [discord.File(fpath) for fpath in wanted_jsons]
await log_channel.send(msg, files=config_files)
await bot.change_presence(activity=discord.Game(name=game_name))
@ -170,9 +176,6 @@ async def on_message(message):
if not os.path.exists("data"):
os.makedirs("data")
wanted_jsons = ["data/restrictions.json",
"data/userlog.json"]
for wanted_json in wanted_jsons:
if not os.path.exists(wanted_json):
with open(wanted_json, "w") as f:

View file

@ -39,10 +39,17 @@ class Admin:
@commands.command()
async def fetchlog(self, ctx):
"""Returns log"""
await ctx.send("This is currently broken.")
await ctx.send("Here's the current log file:",
file=discord.File(f"{self.bot.script_name}.log"))
@commands.guild_only()
@commands.check(check_if_bot_manager)
@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)
@commands.guild_only()
@commands.check(check_if_bot_manager)
@commands.command(name='eval')