async def on_command(command, ctx): with open("data/stats.json", 'r') as stats_file: stats = json.load(stats_file) stats["commands_executed"] += 1 stats["commands_usage"][command.name] = stats["commands_usage"].get( command.name, 0) + 1 with open("data/stats.json", 'w') as stats_file: json.dump(stats, stats_file, indent=4) utilities.create_folder("data/user_data/{}".format( ctx.message.author.id)) utilities.create_file("user_data/{}/stats".format( ctx.message.author.id), content={ "commands_executed": 0, "points": 0, "respects_paid": 0 }) # TODO: Transfer respects paid data? clean_name = re.sub(r"[\|/\\:\?\*\"<>]", "", ctx.message.author.name) # | / \ : ? * " < > utilities.create_file("user_data/{}/{}".format(ctx.message.author.id, clean_name)) with open("data/user_data/{}/stats.json".format(ctx.message.author.id), "r") as stats_file: stats = json.load(stats_file) stats["commands_executed"] += 1 stats["points"] += 1 with open("data/user_data/{}/stats.json".format(ctx.message.author.id), 'w') as stats_file: json.dump(stats, stats_file, indent=4)
async def on_ready(): # data = await client.http.get(client.http.GATEWAY + "/bot") # print(data) print("Started up Discord {0} ({1})".format(str(client.user), client.user.id)) if os.path.isfile("data/temp/restart_channel.json"): with open("data/temp/restart_channel.json", 'r') as restart_channel_file: restart_data = json.load(restart_channel_file) os.remove("data/temp/restart_channel.json") restart_channel = client.get_channel( restart_data["restart_channel"]) await client.send_embed(restart_channel, ":thumbsup::skin-tone-2: Restarted") for voice_channel in restart_data["voice_channels"]: # asyncio.ensure_future(client.cogs["Audio"].start_player(client.get_channel(voice_channel[1]))) text_channel = client.get_channel(voice_channel[1]) if text_channel: client.cogs["Audio"].players[ text_channel.server.id] = audio_player.AudioPlayer( client, text_channel) await client.join_voice_channel( client.get_channel(voice_channel[0])) ''' for folder in os.listdir("data/server_data"): with open("data/server_data/{}/settings.json".format(folder), 'r') as settings_file: data = json.load(settings_file) data["anti-spam"] = False with open("data/server_data/{}/settings.json".format(folder), 'w') as settings_file: json.dump(data, settings_file, indent = 4) ''' for server in client.servers: utilities.create_folder("data/server_data/{}".format(server.id)) utilities.create_file("server_data/{}/settings".format(server.id), content={ "anti-spam": False, "respond_to_bots": False }) if server.name: clean_name = re.sub(r"[\|/\\:\?\*\"<>]", "", server.name) # | / \ : ? * " < > utilities.create_file("server_data/{}/{}".format( server.id, clean_name)) # TODO: DM if joined new server # TODO: DM if left server await clients.random_game_status() await clients.set_streaming_status(client)
async def on_server_join(server): utilities.create_folder("data/server_data/{}".format(server.id)) utilities.create_file("server_data/{}/settings".format(server.id), content={ "anti-spam": False, "respond_to_bots": False }) me = discord.utils.get(client.get_all_members(), id=clients.owner_id) await client.send_embed(me, None, title="Joined Server", timestamp=server.created_at, thumbnail_url=server.icon_url, fields=(("Name", server.name), ("ID", server.id), ("Owner", str(server.owner)), ("Members", str(server.member_count)), ("Server Region", str(server.region)))) clean_name = re.sub(r"[\|/\\:\?\*\"<>]", "", server.name) # | / \ : ? * " < > utilities.create_file("server_data/{}/{}".format( server.id, clean_name))
async def poke(self, ctx, *, user: str): '''Poke someone''' to_poke = await utilities.get_user(ctx, user) if not to_poke: await self.bot.embed_reply(":no_entry: User not found") elif to_poke == self.bot.user: await self.bot.embed_reply("!poke {}".format( ctx.message.author.mention)) else: utilities.create_folder("data/user_data/{}".format( ctx.message.author.id)) utilities.create_file("user_data/{}/pokes".format( ctx.message.author.id)) with open( "data/user_data/{}/pokes.json".format( ctx.message.author.id), 'r') as pokes_file: pokes_data = json.load(pokes_file) pokes_data[to_poke.id] = pokes_data.get(to_poke.id, 0) + 1 with open( "data/user_data/{}/pokes.json".format( ctx.message.author.id), 'w') as pokes_file: json.dump(pokes_data, pokes_file, indent=4) embed = discord.Embed(color=clients.bot_color) embed.set_author(name=ctx.message.author, icon_url=ctx.message.author.avatar_url or ctx.message.author.default_avatar_url) embed.description = "Poked you for the {} time!".format( clients.inflect_engine.ordinal(pokes_data[to_poke.id])) await self.bot.send_message(to_poke, embed=embed) await self.bot.embed_reply( "You have poked {} for the {} time!".format( to_poke.mention, clients.inflect_engine.ordinal(pokes_data[to_poke.id])), footer_text="In response to: {}".format( ctx.message.clean_content)) await self.bot.attempt_delete_message(ctx.message)
import logging import logging.handlers import sys from modules import utilities utilities.create_folder("data/logs/chat") utilities.create_folder("data/logs/discord") console_logger = logging.getLogger("console") console_logger.setLevel(logging.DEBUG) console_logger_handler = logging.FileHandler(filename="data/logs/console.log", encoding="utf-8", mode='a') console_logger_handler.setFormatter( logging.Formatter("%(asctime)s: %(message)s")) console_logger.addHandler(console_logger_handler) class Logger(object): def __init__(self, log, prefix=""): self.console = sys.__stdout__ self.log = log self.prefix = prefix def write(self, message): self.console.write(message) if not message.isspace(): self.log(self.prefix + message) def flush(self):
# undo the trigger parsing view.index = previous view.previous = previous await super().invoke(ctx) def group(name=None, **attrs): return commands.command(name=name, cls=Group, **attrs) commands.Group = Group commands.group = group # Create Folders utilities.create_folder("data") utilities.create_folder("data/permissions") utilities.create_folder("data/temp") # Custom prefixes utilities.create_file("prefixes") def get_prefix(bot, message): with open("data/prefixes.json", 'r') as prefixes_file: all_prefixes = json.load(prefixes_file) if message.channel.is_private: prefixes = all_prefixes.get(message.channel.id, None) else: prefixes = all_prefixes.get(message.server.id, None)