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) return commands.when_mentioned_or(*prefixes)(bot, message)
wanted_jsons = ["data/restrictions.json",
"data/userlog.json"]
initial_extensions = ['cogs.common', initial_extensions = ['cogs.common',
'cogs.admin', 'cogs.admin',
'cogs.basic', 'cogs.basic',
@ -58,6 +61,7 @@ bot = commands.Bot(command_prefix=get_prefix,
bot.log = log bot.log = log
bot.config = config bot.config = config
bot.script_name = script_name bot.script_name = script_name
bot.wanted_jsons = wanted_jsons
if __name__ == '__main__': if __name__ == '__main__':
for extension in initial_extensions: for extension in initial_extensions:
@ -83,7 +87,9 @@ async def on_ready():
log_channel = guild.get_channel(config.log_channel) log_channel = guild.get_channel(config.log_channel)
msg = f"{bot.user.name} has started! "\ msg = f"{bot.user.name} has started! "\
f"{guild.name} has {guild.member_count} members!" 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)) 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"): if not os.path.exists("data"):
os.makedirs("data") os.makedirs("data")
wanted_jsons = ["data/restrictions.json",
"data/userlog.json"]
for wanted_json in wanted_jsons: for wanted_json in wanted_jsons:
if not os.path.exists(wanted_json): if not os.path.exists(wanted_json):
with open(wanted_json, "w") as f: with open(wanted_json, "w") as f:

View file

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