我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用__main__.send_cmd_help()。
def karma(self, ctx): """Checks a user's karma, requires @ mention Example: !karma @Red""" if len(ctx.message.mentions) != 1: await send_cmd_help(ctx) return member = ctx.message.mentions[0] if self.scores.get(member.id, 0) != 0: member_dict = self.scores[member.id] await self.bot.say(member.name + " has " + str(member_dict["score"]) + " points!") reasons = self._fmt_reasons(member_dict.get("reasons", [])) if reasons: await self.bot.send_message(ctx.message.author, reasons) else: await self.bot.say(member.name + " has no karma!")
def modset(self, ctx): """Manages server administration settings.""" if ctx.invoked_subcommand is None: server = ctx.message.server await send_cmd_help(ctx) roles = settings.get_server(server).copy() _settings = {**self.settings[server.id], **roles} if "delete_delay" not in _settings: _settings["delete_delay"] = -1 msg = ("Admin role: {ADMIN_ROLE}\n" "Mod role: {MOD_ROLE}\n" "Mod-log: {mod-log}\n" "Delete repeats: {delete_repeats}\n" "Ban mention spam: {ban_mention_spam}\n" "Delete delay: {delete_delay}\n" "".format(**_settings)) await self.bot.say(box(msg))
def modlog(self, ctx, channel : discord.Channel=None): """Sets a channel as mod log Leaving the channel parameter empty will deactivate it""" server = ctx.message.server if channel: self.settings[server.id]["mod-log"] = channel.id await self.bot.say("Mod events will be sent to {}" "".format(channel.mention)) else: if self.settings[server.id]["mod-log"] is None: await send_cmd_help(ctx) return self.settings[server.id]["mod-log"] = None await self.bot.say("Mod log deactivated.") dataIO.save_json("data/mod/settings.json", self.settings)
def banmentionspam(self, ctx, max_mentions : int=False): """Enables auto ban for messages mentioning X different people Accepted values: 5 or superior""" server = ctx.message.server if max_mentions: if max_mentions < 5: max_mentions = 5 self.settings[server.id]["ban_mention_spam"] = max_mentions await self.bot.say("Autoban for mention spam enabled. " "Anyone mentioning {} or more different people " "in a single message will be autobanned." "".format(max_mentions)) else: if self.settings[server.id]["ban_mention_spam"] is False: await send_cmd_help(ctx) return self.settings[server.id]["ban_mention_spam"] = False await self.bot.say("Autoban for mention spam disabled.") dataIO.save_json("data/mod/settings.json", self.settings)
def filter_add(self, ctx, *words: str): """Adds words to the filter Use double quotes to add sentences Examples: filter add word1 word2 word3 filter add \"This is a sentence\"""" if words == (): await send_cmd_help(ctx) return server = ctx.message.server added = 0 if server.id not in self.filter.keys(): self.filter[server.id] = [] for w in words: if w.lower() not in self.filter[server.id] and w != "": self.filter[server.id].append(w.lower()) added += 1 if added: dataIO.save_json("data/mod/filter.json", self.filter) await self.bot.say("Words added to filter.") else: await self.bot.say("Words already in the filter.")
def filter_remove(self, ctx, *words: str): """Remove words from the filter Use double quotes to remove sentences Examples: filter remove word1 word2 word3 filter remove \"This is a sentence\"""" if words == (): await send_cmd_help(ctx) return server = ctx.message.server removed = 0 if server.id not in self.filter.keys(): await self.bot.say("There are no filtered words in this server.") return for w in words: if w.lower() in self.filter[server.id]: self.filter[server.id].remove(w.lower()) removed += 1 if removed: dataIO.save_json("data/mod/filter.json", self.filter) await self.bot.say("Words removed from filter.") else: await self.bot.say("Those words weren't in the filter.")
def welcomeset(self, ctx): """Sets welcome module settings""" server = ctx.message.server if server.id not in self.settings: self.settings[server.id] = deepcopy(default_settings) self.settings[server.id]["CHANNEL"] = server.default_channel.id dataIO.save_json(settings_path, self.settings) if ctx.invoked_subcommand is None: await send_cmd_help(ctx) msg = "```" msg += "Random GREETING: {}\n".format(rand_choice(self.settings[server.id]["GREETING"])) msg += "CHANNEL: #{}\n".format(self.get_welcome_channel(server)) msg += "ON: {}\n".format(self.settings[server.id]["ON"]) msg += "WHISPER: {}\n".format(self.settings[server.id]["WHISPER"]) msg += "BOTS_MSG: {}\n".format(self.settings[server.id]["BOTS_MSG"]) msg += "BOTS_ROLE: {}\n".format(self.settings[server.id]["BOTS_ROLE"]) msg += "```" await self.bot.say(msg)
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)
def trickleset(self, ctx): """Changes economy trickle settings Trickle amount: base amount + (# active users - 1) x multiplier + bonus pot Every active user gets the trickle amount. It is not distributed between active users. """ server = ctx.message.server settings = self.settings.setdefault(server.id, deepcopy(DEFAULT_SETTINGS)) if ctx.invoked_subcommand is None: await send_cmd_help(ctx) msg = "```" for k, v in settings.items(): if k == 'CHANNELS': v = ['#' + c.name if c else 'deleted-channel' for c in (server.get_channel(cid) for cid in v)] v = ', '.join(v) v = {True: 'On', False: 'Off'}.get(v, v) msg += str(k) + ": " + str(v) + "\n" msg += "```" await self.bot.say(msg)
def bouncerset_roles(self, ctx, before_after: str, role: discord.Role=None): """For first parameter use before or after. For roles with space with them, use \"double quotes\" Before: role assigned to users when they join the server but don't accept the rules yet, will be stripped after accepting the rules. Can be left empty. After: Role assigned after accepting the rules """ server = ctx.message.server valid_options = ["before", "after"] selection = before_after.lower() if selection not in valid_options: await send_cmd_help(ctx) return if selection == "before": await self.bot.say("Role assigned at join will be: {}".format(role)) self.settings[server.id]["role_before"] = role.id elif role is not None: await self.bot.say("Role assigned after accepting rules will be: {}".format(role)) self.settings[server.id]["role_after"] = role.id else: self.bot.say("After role can't be empty") return dataIO.save_json('data/bouncer/settings.json', self.settings)
def mention(self, ctx, *, mention_type : str): """Sets mentions for stream alerts Types: everyone, here, none""" server = ctx.message.server mention_type = mention_type.lower() if mention_type in ("everyone", "here"): self.settings[server.id]["MENTION"] = "@" + mention_type await self.bot.say("When a stream is online @\u200b{} will be " "mentioned.".format(mention_type)) elif mention_type == "none": self.settings[server.id]["MENTION"] = "" await self.bot.say("Mentions disabled.") else: await self.bot.send_cmd_help(ctx) dataIO.save_json("data/streams/settings.json", self.settings)
def _filter(self, ctx): """Adds/removes words from filter Use double quotes to add/remove sentences Using this command with no subcommands will send the list of the server's filtered words.""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx) server = ctx.message.server author = ctx.message.author if server.id in self.filter: if self.filter[server.id]: words = ", ".join(self.filter[server.id]) words = "Filtered in this server:\n\n" + words try: for page in pagify(words, delims=[" ", "\n"], shorten_by=8): await self.bot.send_message(author, page) except discord.Forbidden: await self.bot.say("I can't send direct messages to you.")
def _warnset(self, ctx): if ctx.message.server.id not in self.riceCog2: self.riceCog2[ctx.message.server.id] = {} if ctx.invoked_subcommand is None: await send_cmd_help(ctx) server = ctx.message.server try: msg = self.riceCog2[server.id]["warn_message"] except: msg = default_warn try: kick = self.riceCog2[server.id]["kick_message"] except: kick = default_kick try: _max = self.riceCog2[server.id]["max"] except: _max = default_max message = "```\n" message += "Warn Message - {}\n" message += "Kick Message - {}\n" message += "Warn Limit - {}\n" message += "```" await self.bot.say(message.format(msg, kick, _max))
def _googlesettings(self, ctx, maxresults: int=0): """Set the amount of results appearing""" if not self.maxresults: # If statement incase someone removes it or sets it to 0 self.maxresults = 3 if maxresults == 0: message = box( "Current max search result is {}".format(self.maxresults)) await send_cmd_help(ctx) elif maxresults > 10: await self.bot.say('`Cannot set max search results higher then 10`') return elif maxresults < 1: await self.bot.say('`Cannot set max search results lower then 0`') return else: self.maxresults = maxresults self.settings['MAXRESULTS'] = self.maxresults dataIO.save_json('data/google/settings.json', self.settings) message = '`Changed max search results to {} `'.format( self.maxresults) await self.bot.say(message)
def radioharu(self, ctx): """Radio Haru""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx) await self.bot.say("https://radioharu.pw/")
def googl(self, ctx): """Googl""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def webserver(self, ctx): """Webserver""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def notebook(self, ctx): """Notebook""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def dio(self, ctx): """Discord.io""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def setcookie(self, ctx): """Cookie settings group command""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def lottery(self, ctx): """Lottery Group Command""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def setlottery(self, ctx): """Lottery Settings""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def setrussian(self, ctx): """Russian Roulette Settings""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def shop(self, ctx): """Shop Commands. Use !help Shop for other command groups""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def pending(self, ctx): """Pending list commands""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def coupon(self, ctx): """Coupon commands""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def mal(self, ctx): """MAL Search Commands""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def pokemon(self, ctx): """This is the list of Pokémon queries you can perform.""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def _raffle(self, ctx): """Raffle Commands""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def heist(self, ctx): """General heist related commands""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def setheist(self, ctx): """Set different options in the heist config""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def dtable(self, ctx): """Shows a list under this group commands.""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def race(self, ctx): """Race cog's group command""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def setrace(self, ctx): """Race cog's settings group command""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def setcasino(self, ctx): """Configures Casino Options""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def announce(self, ctx): """Manages video announcing""" if ctx.invoked_subcommand is None: await send_cmd_help()
def settings(self, ctx): """Manages settings for video announcing""" guild = ctx.message.guild channel = ctx.message.channel settings = self.ids[guild.id] if ctx.invoked_subcommand is None: msg = "```" for k, v in settings.items(): msg += "{}: {}\n".format(k, v) msg += "```" await send_cmd_help(ctx) await ctx.send(msg)
def _qeset(self, ctx): if ctx.invoked_subcommand is None: await send_cmd_help(ctx) await self.bot.say("```\nDEFAULT COLOUR: {}\n```".format(self.data["default_colour"]))
def qembed(self, ctx, text, color=None): """Used to make a quick embed {server} is ctx.message.server {author} is ctx.message.author {channel} is ctx.message.channel {message} is ctx.message {ctx} is ctx """ if color is None: embed_color = self.colours[self.data["default_colour"]]() elif color.lower() not in self.colours: if color.startswith('#'): color = color[1:] try: if validhex(int(color, 16)): embed_color = discord.Color(int(color, 16)) except ValueError: await send_cmd_help(ctx) return if not validhex(int(color, 16)): await send_cmd_help(ctx) return else: embed_color = self.colours[color]() embed = discord.Embed(description=text.format(server=ctx.message.server, author=ctx.message.author, channel=ctx.message.channel, message=ctx.message, ctx=ctx), color=embed_color) await self.bot.say(embed=embed)
def colorrole(self, ctx, color): """Creates a colored role for you! Example [p]colorrole #8C5200 Hex pls.""" if not color.startswith("#"): await send_cmd_help(ctx) return colorhex = color[1:] color_role = await self.bot.create_role(server=ctx.message.server, name=color, colour=discord.Colour(value=int(colorhex, 16))) await self.bot.add_roles(ctx.message.author, color_role) await self.bot.say("Done!")
def _adkillr(self, ctx): """Manages the settings for Adkillr.""" serverid = ctx.message.server.id if ctx.invoked_subcommand is None: await send_cmd_help(ctx) if serverid not in self.adkillr: self.adkillr[serverid] = {'toggle': True, 'message': '{0.mention} don\'t send links!', 'filters': []} dataIO.save_json("data/adkillr/adkillr.json", self.adkillr)
def _server(self, ctx): """Server info commands.""" if ctx.invoked_subcommand is None: await send_cmd_help(ctx)
def ftpset(self, ctx): """Manage all ftpstats settings""" if not ctx.invoked_subcommand: await send_cmd_help(ctx)
def _airhornsong(self, ctx): """Some air horn songs.""" if not ctx.invoked_subcommand: await send_cmd_help(ctx)
def _from(self, ctx): """Convert a coded something to text.""" if not ctx.invoked_subcommand: await send_cmd_help(ctx)