本文整理匯總了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)
示例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)
示例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')
示例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')
示例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))
示例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.')
示例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()
示例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()
示例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()
示例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()
示例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))
示例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))
示例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))
示例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)
示例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")