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)
def __init__(self, bot): self.bot = bot self.stream_listener = TwitterStreamListener(bot) utilities.create_file("twitter_feeds", content={"channels": {}}) with open("data/twitter_feeds.json", 'r') as feeds_file: self.feeds_info = json.load(feeds_file) self.task = self.bot.loop.create_task(self.start_twitter_feeds())
def __init__(self, bot): self.bot = bot self.streams_announced = {} self.old_streams_announced = {} utilities.create_file("youtube_streams", content={"channels": {}}) with open("data/youtube_streams.json", 'r') as streams_file: self.streams_info = json.load(streams_file) self.task = self.bot.loop.create_task(self.check_youtube_streams())
def __init__(self, user_id): self.user_id = user_id _initial_data = initial_data.copy() _initial_data["time_started"] = time.time() utilities.create_file("adventure_players/" + user_id, content=_initial_data) with open("data/adventure_players/{}.json".format(user_id), 'r') as player_file: self.data = json.load(player_file)
def __init__(self, bot): self.bot = bot utilities.create_file("stats", content={ "uptime": 0, "restarts": 0, "cogs_reloaded": 0, "commands_executed": 0, "commands_usage": {}, "reaction_responses": 0 }) self.command_not_found = "No command called `{}` found"
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 re import sys import traceback import youtube_dl import clients import credentials from clients import client from modules import conversions from modules import logging from modules import utilities from utilities import checks from utilities import errors from utilities import audio_player utilities.create_file('f', content={"total": 0}) with open("data/f.json", 'r') as f_file: f_counter_info = json.load(f_file) mention_spammers = [] @client.event 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)
def __init__(self, bot): self.bot = bot utilities.create_file("tags", content={"global": {}}) with open("data/tags.json", 'r') as tags_file: self.tags_data = json.load(tags_file)
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) return prefixes if prefixes else '!' # Initialize client + Customize help command custom_help_formatter = CustomHelpFormatter()
def __init__(self, bot): self.bot = bot utilities.create_file("rss_feeds", content = {"channels" : []}) with open("data/rss_feeds.json", 'r') as feeds_file: self.feeds_info = json.load(feeds_file) self.task = self.bot.loop.create_task(self.check_rss_feeds())