当前位置: 首页>>代码示例>>Python>>正文


Python dataIO.save_json方法代码示例

本文整理汇总了Python中cogs.utils.dataIO.dataIO.save_json方法的典型用法代码示例。如果您正苦于以下问题:Python dataIO.save_json方法的具体用法?Python dataIO.save_json怎么用?Python dataIO.save_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cogs.utils.dataIO.dataIO的用法示例。


在下文中一共展示了dataIO.save_json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: replset_print_file

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def replset_print_file(self, ctx, choice=None):
        """write results to a file, optionally opening in subl/atom

        Choices: nothing | subl | subl.exe | atom | atom.exe"""
        author = ctx.message.author
        choices = ['subl', 'subl.exe', 'atom', 'atom.exe']
        if choice not in choices + [None, 'nothing']:
            await send_cmd_help(ctx)
            return
        if choice is None:
            msg = ("You chose to print to file. What would you like to open it with?\n"
                   "Choose between:  {}".format(' | '.join(choices + ['nothing'])))
            choice = await self.user_choice(author, msg, choices)
        msg = "repl overflow will now go to file and "
        if choice not in choices:
            msg += "I won't open it after writing to {}".format(self.output_file)
            choice = None
        else:
            msg += ("the output will be opened with: `{} "
                    "{}`".format(choice, self.output_file))
        self.settings['OPEN_CMD'] = choice
        self.settings["OUTPUT_REDIRECT"] = "file"
        dataIO.save_json("data/repl/settings.json", self.settings)
        await self.bot.say(msg) 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:26,代码来源:repl.py

示例2: check_files

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def check_files():
    default = {"OUTPUT_REDIRECT": "pages", "OPEN_CMD": None,
               "MULTI_MSG_PAGING": False, "PM_PAGES": 20,
               "PAGES_LENGTH": 1500, "REPL_PREFIX": ['`']}
    settings_path = "data/repl/settings.json"

    if not os.path.isfile(settings_path):
        print("Creating default repl settings.json...")
        dataIO.save_json(settings_path, default)
    else:  # consistency check
        current = dataIO.load_json(settings_path)
        if current.keys() != default.keys():
            for key in default.keys():
                if key not in current.keys():
                    current[key] = default[key]
                    print(
                        "Adding " + str(key) + " field to repl settings.json")
            dataIO.save_json(settings_path, current) 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:20,代码来源:repl.py

示例3: check_time

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def check_time(self):
        while True:
            await asyncio.sleep(30)
            json = copy.deepcopy(self.json)
            log.debug('First Timer')
            for server in json:
                server_obj = discord.utils.get(self.bot.servers, id=server)
                role_obj = discord.utils.get(server_obj.roles, name='Punished')
                log.debug('Server Object = {}'.format(server_obj))
                for user in json[server]:
                    user_obj = discord.utils.get(server_obj.members, id=user)
                    log.debug('User Object = {}'.format(user_obj))
                    if json[server][user]['until'] < int(time.time()):
                        log.debug('Expired user ({})'.format(user))
                        await self.bot.remove_roles(user_obj, role_obj)
                        del self.json[server][user]
                        dataIO.save_json(self.location, self.json)
            log.debug('after loops') 
开发者ID:Kowlin,项目名称:refactored-cogs,代码行数:20,代码来源:punish.py

示例4: toggle

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def toggle(self, ctx, toggle: bool):
        """Open or close the buyrole shop

        Use either True or False
        buyroleset toggle true"""
        server = ctx.message.server
        if toggle is True:
            if self.settings_dict[server.id]['toggle'] is True:
                await self.bot.say('The shop is already enabled')
            else:
                self.settings_dict[server.id]['toggle'] = True
                self.save_json()
                await self.bot.say('The shop has been enabled.')
        elif toggle is False:
            if self.settings_dict[server.id]['toggle'] is False:
                await self.bot.say('The shop is already disabled')
            else:
                self.settings_dict[server.id]['toggle'] = False
                self.save_json()
                await self.bot.say('The shop has been disabled')
        else:
            raise Exception('InvalidToggle') 
开发者ID:Kowlin,项目名称:refactored-cogs,代码行数:24,代码来源:buyrole.py

示例5: uniquegroup

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def uniquegroup(self, ctx, role: discord.Role, groupid: int):
        """Set a role to a unique group ID,
        This means that a user cannot have more then one role from the same group.

        Any role sharing the same ID will be considered a group.
        GroupID 0 will not be considered unique and can share other roles."""
        server = ctx.message.server
        if role.id not in self.settings_dict[server.id]['roles']:
            await self.bot.say('This role ins\'t in the buyrole list')
        elif groupid < 0:
            await self.bot.say('The group ID cannot be negative.')
        else:
            # Set the uniquegroup ID here, logic will remain in a subfunction of buyrole
            self.settings_dict[server.id]['roles'][role.id]['uniquegroup'] = groupid
            self.save_json()
            if groupid == 0:
                await self.bot.say('Unique Group ID set. {} isn\'t considered unique.'.format(role.name))
            else:
                await self.bot.say('Unique Group ID set. {} will now be unique in group ID {}'.format(role.name, groupid)) 
开发者ID:Kowlin,项目名称:refactored-cogs,代码行数:21,代码来源:buyrole.py

示例6: emptychannels

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def emptychannels(self, ctx, number: int):
        """Set the number of empty dynamic channels.
        These channels will always be topped up by the bot."""
        server = ctx.message.server
        if self.settings[server.id]['count'] > number:
            self.settings[server.id]['count'] = number
            self.save_json()
            await self._delete_channels(server)
            await self.bot.say('The new channel count is set. Deleting empty dynamic channels')
        elif self.settings[server.id]['count'] < number:
            self.settings[server.id]['count'] = number
            self.save_json()
            await self.bot.say('The new channel count is set. Adding new empty dynamic channels')
            await self._create_channels(server)
        else:
            await self.bot.say('The requested channel count is the same as the current one. Nothing changed.') 
开发者ID:Kowlin,项目名称:refactored-cogs,代码行数:18,代码来源:dynamicvoice.py

示例7: _delete_channels

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def _delete_channels(self, server):
        """Delete dynamic voice channels"""
        if len(self.settings[server.id]['channels']) > self.settings[server.id]['count']:
            count = len(self.settings[server.id]['channels']) - self.settings[server.id]['count']
            for i in range(count):
                await asyncio.sleep(0.25)
                try:
                    channel = discord.utils.get(server.channels, id=self.settings[server.id]['channels'][0])
                    await self.bot.delete_channel(channel)
                except:
                    pass
                del self.settings[server.id]['channels'][0]
            self.save_json()
        else:
            for c in self.settings[server.id]['channels']:
                try:
                    channel = discord.utils.get(server.channels, id=c)
                    await self.bot.delete_channel(channel)
                except:
                    pass
                self.settings[server.id]['channels'].remove(c)
            self.save_json() 
开发者ID:Kowlin,项目名称:refactored-cogs,代码行数:24,代码来源:dynamicvoice.py

示例8: set_channel

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def set_channel(self, ctx, on_off: bool, channel: discord.Channel = None):
        """
        Sets channel logging on or off (channel optional)

        To enable or disable all channels at once, use `logset server`.
        """
        if channel is None:
            channel = ctx.message.channel

        server = channel.server

        if server.id not in self.settings:
            self.settings[server.id] = {}

        self.settings[server.id][channel.id] = on_off

        if on_off:
            await self.bot.say('Logging enabled for %s' % channel.mention)
        else:
            await self.bot.say('Logging disabled for %s' % channel.mention)

        self.save_json() 
开发者ID:calebj,项目名称:calebj-cogs,代码行数:24,代码来源:activitylog.py

示例9: set_voice

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def set_voice(self, ctx, on_off: bool):
        """
        Sets logging on or off for ALL voice channel events
        """
        server = ctx.message.server

        if server.id not in self.settings:
            self.settings[server.id] = {}
        self.settings[server.id]['voice'] = on_off

        if on_off:
            await self.bot.say('Voice event logging enabled for %s' % server)
        else:
            await self.bot.say('Voice event logging disabled for %s' % server)

        self.save_json() 
开发者ID:calebj,项目名称:calebj-cogs,代码行数:18,代码来源:activitylog.py

示例10: set_events

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def set_events(self, ctx, on_off: bool):
        """
        Sets logging on or off for server events
        """
        server = ctx.message.server

        if server.id not in self.settings:
            self.settings[server.id] = {}

        self.settings[server.id]['events'] = on_off

        if on_off:
            await self.bot.say('Logging enabled for server events in %s' % server)
        else:
            await self.bot.say('Logging disabled for server events in %s' % server)

        self.save_json() 
开发者ID:calebj,项目名称:calebj-cogs,代码行数:19,代码来源:activitylog.py

示例11: setfeedback_addrole_read

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def setfeedback_addrole_read(self, ctx: Context, role):
        """Set feedback read role."""
        server = ctx.message.server
        r = discord.utils.get(server.roles, name=role)
        if r is None:
            await self.bot.say(
                "{} is not a valid role on this server.".format(
                    role))
            return
        if server.id not in self.settings:
            self.init_server_settings(server)
        if r.id in self.settings[server.id]["read_roles"]:
            return
        self.settings[server.id]["read_roles"].append(r.id)
        dataIO.save_json(JSON, self.settings)
        await self.bot.say(
            "Added {} in list of roles allowed to read feedbacks."
            "".format(role)) 
开发者ID:smlbiobot,项目名称:SML-Cogs,代码行数:20,代码来源:feedback.py

示例12: replset_pagelength

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def replset_pagelength(self, ctx, length: int=1500):
        """Sets the page length when using the [p]replset print pages option

        length must be between 300 and 1700.
        length defaults to 1500"""
        if not (300 <= length <= 1700):
            return await send_cmd_help(ctx)
        old_length = self.settings["PAGES_LENGTH"]
        self.settings["PAGES_LENGTH"] = length
        dataIO.save_json("data/repl/settings.json", self.settings)
        await self.bot.say("each page will now break at {} characters "
                           "(was {})".format(length, old_length)) 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:14,代码来源:repl.py

示例13: replset_prefix

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def replset_prefix(self, ctx, *prefixes):
        """Sets the prefixes repl looks for.

        Defaults to `
        Note: choosing prefixes that don't include ` will mean that
        repl no longer listens for code blocks"""
        if not prefixes:
            prefixes = ('`',)
        prefixes = sorted(prefixes, reverse=True)
        old_prefixes = self.settings["REPL_PREFIX"]
        self.settings["REPL_PREFIX"] = prefixes
        dataIO.save_json("data/repl/settings.json", self.settings)
        await self.bot.say("repl will now respond to {}. Before the prefixes "
                           "were {}".format(prefixes, old_prefixes)) 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:16,代码来源:repl.py

示例14: replset_print_pages

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def replset_print_pages(self, ctx, add_pages: bool=False):
        """navigable pager in the current channel..

        set add_pages to true if you prefer the bot sending a new message for every new page"""
        msg = "repl overflow will now go to pages in the channel and "
        if add_pages:
            msg += "you will be given the option to page via adding new pages"
        else:
            msg += "regular single-message paging will be used"
        self.settings['MULTI_MSG_PAGING'] = add_pages
        self.settings["OUTPUT_REDIRECT"] = "pages"
        dataIO.save_json("data/repl/settings.json", self.settings)
        await self.bot.say(msg) 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:15,代码来源:repl.py

示例15: replset_print_console

# 需要导入模块: from cogs.utils.dataIO import dataIO [as 别名]
# 或者: from cogs.utils.dataIO.dataIO import save_json [as 别名]
def replset_print_console(self, ctx):
        """print results to console"""
        self.settings["OUTPUT_REDIRECT"] = "console"
        dataIO.save_json("data/repl/settings.json", self.settings)
        await self.bot.say("repl overflow will now go to console") 
开发者ID:irdumbs,项目名称:Dumb-Cogs,代码行数:7,代码来源:repl.py


注:本文中的cogs.utils.dataIO.dataIO.save_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。