Browse Source

period at end of every docstring first line, ca -> can (#9)

pull/10/head
Michael 9 years ago
committed by Andrei Zbikowski
parent
commit
d8d1df0ac4
  1. 8
      disco/api/ratelimit.py
  2. 6
      disco/bot/bot.py
  3. 12
      disco/bot/command.py
  4. 14
      disco/bot/parser.py
  5. 28
      disco/bot/plugin.py
  6. 6
      disco/client.py
  7. 2
      disco/state.py
  8. 24
      disco/types/channel.py
  9. 10
      disco/types/guild.py
  10. 2
      disco/types/invite.py
  11. 8
      disco/types/message.py
  12. 2
      disco/util/token.py

8
disco/api/ratelimit.py

@ -44,7 +44,7 @@ class RouteState(LoggingClass):
@property @property
def chilled(self): def chilled(self):
""" """
Whether this route is currently being cooldown (aka waiting until reset_time) Whether this route is currently being cooldown (aka waiting until reset_time).
""" """
return self.event is not None return self.event is not None
@ -74,7 +74,7 @@ class RouteState(LoggingClass):
def wait(self, timeout=None): def wait(self, timeout=None):
""" """
Waits until this route is no longer under a cooldown Waits until this route is no longer under a cooldown.
Parameters Parameters
---------- ----------
@ -85,13 +85,13 @@ class RouteState(LoggingClass):
Returns Returns
------- -------
bool bool
False if the timeout period expired before the cooldown was finished False if the timeout period expired before the cooldown was finished.
""" """
return self.event.wait(timeout) return self.event.wait(timeout)
def cooldown(self): def cooldown(self):
""" """
Waits for the current route to be cooled-down (aka waiting until reset time) Waits for the current route to be cooled-down (aka waiting until reset time).
""" """
if self.reset_time - time.time() < 0: if self.reset_time - time.time() < 0:
raise Exception('Cannot cooldown for negative time period; check clock sync') raise Exception('Cannot cooldown for negative time period; check clock sync')

6
disco/bot/bot.py

@ -177,7 +177,7 @@ class Bot(object):
@property @property
def commands(self): def commands(self):
""" """
Generator of all commands this bots plugins have defined Generator of all commands this bots plugins have defined.
""" """
for plugin in six.itervalues(self.plugins): for plugin in six.itervalues(self.plugins):
for command in six.itervalues(plugin.commands): for command in six.itervalues(plugin.commands):
@ -194,7 +194,7 @@ class Bot(object):
def compute_group_abbrev(self): def compute_group_abbrev(self):
""" """
Computes all possible abbreviations for a command grouping Computes all possible abbreviations for a command grouping.
""" """
self.group_abbrev = {} self.group_abbrev = {}
groups = set(command.group for command in self.commands if command.group) groups = set(command.group for command in self.commands if command.group)
@ -417,7 +417,7 @@ class Bot(object):
def run_forever(self): def run_forever(self):
""" """
Runs this bots core loop forever Runs this bots core loop forever.
""" """
self.client.run_forever() self.client.run_forever()

12
disco/bot/command.py

@ -48,28 +48,28 @@ class CommandEvent(object):
@cached_property @cached_property
def member(self): def member(self):
""" """
Guild member (if relevant) for the user that created the message Guild member (if relevant) for the user that created the message.
""" """
return self.guild.get_member(self.author) return self.guild.get_member(self.author)
@property @property
def channel(self): def channel(self):
""" """
Channel the message was created in Channel the message was created in.
""" """
return self.msg.channel return self.msg.channel
@property @property
def guild(self): def guild(self):
""" """
Guild (if relevant) the message was created in Guild (if relevant) the message was created in.
""" """
return self.msg.guild return self.msg.guild
@property @property
def author(self): def author(self):
""" """
Author of the message Author of the message.
""" """
return self.msg.author return self.msg.author
@ -159,14 +159,14 @@ class Command(object):
@cached_property @cached_property
def compiled_regex(self): def compiled_regex(self):
""" """
A compiled version of this command's regex A compiled version of this command's regex.
""" """
return re.compile(self.regex) return re.compile(self.regex)
@property @property
def regex(self): def regex(self):
""" """
The regex string that defines/triggers this command The regex string that defines/triggers this command.
""" """
if self.is_regex: if self.is_regex:
return REGEX_FMT.format('|'.join(self.triggers)) return REGEX_FMT.format('|'.join(self.triggers))

14
disco/bot/parser.py

@ -47,13 +47,13 @@ class Argument(object):
@property @property
def true_count(self): def true_count(self):
""" """
The true number of raw arguments this argument takes The true number of raw arguments this argument takes.
""" """
return self.count or 1 return self.count or 1
def parse(self, raw): def parse(self, raw):
""" """
Attempts to parse arguments from their raw form Attempts to parse arguments from their raw form.
""" """
prefix, part = raw prefix, part = raw
@ -78,7 +78,7 @@ class Argument(object):
class ArgumentSet(object): class ArgumentSet(object):
""" """
A set of :class:`Argument` instances which forms a larger argument specification A set of :class:`Argument` instances which forms a larger argument specification.
Attributes Attributes
---------- ----------
@ -95,7 +95,7 @@ class ArgumentSet(object):
@classmethod @classmethod
def from_string(cls, line, custom_types=None): def from_string(cls, line, custom_types=None):
""" """
Creates a new :class:`ArgumentSet` from a given argument string specification Creates a new :class:`ArgumentSet` from a given argument string specification.
""" """
args = cls(custom_types=custom_types) args = cls(custom_types=custom_types)
@ -131,7 +131,7 @@ class ArgumentSet(object):
def append(self, arg): def append(self, arg):
""" """
Add a new :class:`Argument` to this argument specification/set Add a new :class:`Argument` to this argument specification/set.
""" """
if self.args and not self.args[-1].required and arg.required: if self.args and not self.args[-1].required and arg.required:
raise Exception('Required argument cannot come after an optional argument') raise Exception('Required argument cannot come after an optional argument')
@ -178,13 +178,13 @@ class ArgumentSet(object):
@property @property
def length(self): def length(self):
""" """
The number of arguments in this set/specification The number of arguments in this set/specification.
""" """
return len(self.args) return len(self.args)
@property @property
def required_length(self): def required_length(self):
""" """
The number of required arguments to compile this set/specificaiton The number of required arguments to compile this set/specificaiton.
""" """
return sum([i.true_count for i in self.args if i.required]) return sum([i.true_count for i in self.args if i.required])

28
disco/bot/plugin.py

@ -43,7 +43,7 @@ class PluginDeco(object):
@classmethod @classmethod
def listen(cls, *args, **kwargs): def listen(cls, *args, **kwargs):
""" """
Binds the function to listen for a given event name Binds the function to listen for a given event name.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'listener', 'type': 'listener',
@ -55,7 +55,7 @@ class PluginDeco(object):
@classmethod @classmethod
def listen_packet(cls, *args, **kwargs): def listen_packet(cls, *args, **kwargs):
""" """
Binds the function to listen for a given gateway op code Binds the function to listen for a given gateway op code.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'listener', 'type': 'listener',
@ -67,7 +67,7 @@ class PluginDeco(object):
@classmethod @classmethod
def command(cls, *args, **kwargs): def command(cls, *args, **kwargs):
""" """
Creates a new command attached to the function Creates a new command attached to the function.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'command', 'type': 'command',
@ -78,7 +78,7 @@ class PluginDeco(object):
@classmethod @classmethod
def pre_command(cls): def pre_command(cls):
""" """
Runs a function before a command is triggered Runs a function before a command is triggered.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'pre_command', 'type': 'pre_command',
@ -87,7 +87,7 @@ class PluginDeco(object):
@classmethod @classmethod
def post_command(cls): def post_command(cls):
""" """
Runs a function after a command is triggered Runs a function after a command is triggered.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'post_command', 'type': 'post_command',
@ -96,7 +96,7 @@ class PluginDeco(object):
@classmethod @classmethod
def pre_listener(cls): def pre_listener(cls):
""" """
Runs a function before a listener is triggered Runs a function before a listener is triggered.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'pre_listener', 'type': 'pre_listener',
@ -105,7 +105,7 @@ class PluginDeco(object):
@classmethod @classmethod
def post_listener(cls): def post_listener(cls):
""" """
Runs a function after a listener is triggered Runs a function after a listener is triggered.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'post_listener', 'type': 'post_listener',
@ -114,7 +114,7 @@ class PluginDeco(object):
@classmethod @classmethod
def schedule(cls, *args, **kwargs): def schedule(cls, *args, **kwargs):
""" """
Runs a function repeatedly, waiting for a specified interval Runs a function repeatedly, waiting for a specified interval.
""" """
return cls.add_meta_deco({ return cls.add_meta_deco({
'type': 'schedule', 'type': 'schedule',
@ -212,7 +212,7 @@ class Plugin(LoggingClass, PluginDeco):
def execute(self, event): def execute(self, event):
""" """
Executes a CommandEvent this plugin owns Executes a CommandEvent this plugin owns.
""" """
if not event.command.oob: if not event.command.oob:
self.greenlets.add(gevent.getcurrent()) self.greenlets.add(gevent.getcurrent())
@ -226,7 +226,7 @@ class Plugin(LoggingClass, PluginDeco):
def register_trigger(self, typ, when, func): def register_trigger(self, typ, when, func):
""" """
Registers a trigger Registers a trigger.
""" """
getattr(self, '_' + when)[typ].append(func) getattr(self, '_' + when)[typ].append(func)
@ -258,7 +258,7 @@ class Plugin(LoggingClass, PluginDeco):
def register_listener(self, func, what, desc, **kwargs): def register_listener(self, func, what, desc, **kwargs):
""" """
Registers a listener Registers a listener.
Parameters Parameters
---------- ----------
@ -282,7 +282,7 @@ class Plugin(LoggingClass, PluginDeco):
def register_command(self, func, *args, **kwargs): def register_command(self, func, *args, **kwargs):
""" """
Registers a command Registers a command.
Parameters Parameters
---------- ----------
@ -331,13 +331,13 @@ class Plugin(LoggingClass, PluginDeco):
def load(self, ctx): def load(self, ctx):
""" """
Called when the plugin is loaded Called when the plugin is loaded.
""" """
pass pass
def unload(self, ctx): def unload(self, ctx):
""" """
Called when the plugin is unloaded Called when the plugin is unloaded.
""" """
for greenlet in self.greenlets: for greenlet in self.greenlets:
greenlet.kill() greenlet.kill()

6
disco/client.py

@ -20,7 +20,7 @@ class ClientConfig(Config):
Attributes Attributes
---------- ----------
token : str token : str
Discord authentication token, ca be validated using the Discord authentication token, can be validated using the
:func:`disco.util.token.is_valid_token` function. :func:`disco.util.token.is_valid_token` function.
shard_id : int shard_id : int
The shard ID for the current client instance. The shard ID for the current client instance.
@ -123,12 +123,12 @@ class Client(LoggingClass):
def run(self): def run(self):
""" """
Run the client (e.g. the :class:`GatewayClient`) in a new greenlet Run the client (e.g. the :class:`GatewayClient`) in a new greenlet.
""" """
return gevent.spawn(self.gw.run) return gevent.spawn(self.gw.run)
def run_forever(self): def run_forever(self):
""" """
Run the client (e.g. the :class:`GatewayClient`) in the current greenlet Run the client (e.g. the :class:`GatewayClient`) in the current greenlet.
""" """
return self.gw.run() return self.gw.run()

2
disco/state.py

@ -117,7 +117,7 @@ class State(object):
def unbind(self): def unbind(self):
""" """
Unbinds all bound event listeners for this state object Unbinds all bound event listeners for this state object.
""" """
map(lambda k: k.unbind(), self.listeners) map(lambda k: k.unbind(), self.listeners)
self.listeners = [] self.listeners = []

24
disco/types/channel.py

@ -33,7 +33,7 @@ class ChannelSubType(SlottedModel):
class PermissionOverwrite(ChannelSubType): class PermissionOverwrite(ChannelSubType):
""" """
A PermissionOverwrite for a :class:`Channel` A PermissionOverwrite for a :class:`Channel`.
Attributes Attributes
---------- ----------
@ -81,7 +81,7 @@ class PermissionOverwrite(ChannelSubType):
class Channel(SlottedModel, Permissible): class Channel(SlottedModel, Permissible):
""" """
Represents a Discord Channel Represents a Discord Channel.
Attributes Attributes
---------- ----------
@ -125,7 +125,7 @@ class Channel(SlottedModel, Permissible):
def get_permissions(self, user): def get_permissions(self, user):
""" """
Get the permissions a user has in the channel Get the permissions a user has in the channel.
Returns Returns
------- -------
@ -154,42 +154,42 @@ class Channel(SlottedModel, Permissible):
@property @property
def is_guild(self): def is_guild(self):
""" """
Whether this channel belongs to a guild Whether this channel belongs to a guild.
""" """
return self.type in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE) return self.type in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE)
@property @property
def is_dm(self): def is_dm(self):
""" """
Whether this channel is a DM (does not belong to a guild) Whether this channel is a DM (does not belong to a guild).
""" """
return self.type in (ChannelType.DM, ChannelType.GROUP_DM) return self.type in (ChannelType.DM, ChannelType.GROUP_DM)
@property @property
def is_voice(self): def is_voice(self):
""" """
Whether this channel supports voice Whether this channel supports voice.
""" """
return self.type in (ChannelType.GUILD_VOICE, ChannelType.GROUP_DM) return self.type in (ChannelType.GUILD_VOICE, ChannelType.GROUP_DM)
@property @property
def messages(self): def messages(self):
""" """
a default :class:`MessageIterator` for the channel a default :class:`MessageIterator` for the channel.
""" """
return self.messages_iter() return self.messages_iter()
@cached_property @cached_property
def guild(self): def guild(self):
""" """
Guild this channel belongs to (if relevant) Guild this channel belongs to (if relevant).
""" """
return self.client.state.guilds.get(self.guild_id) return self.client.state.guilds.get(self.guild_id)
def messages_iter(self, **kwargs): def messages_iter(self, **kwargs):
""" """
Creates a new :class:`MessageIterator` for the channel with the given Creates a new :class:`MessageIterator` for the channel with the given
keyword arguments keyword arguments.
""" """
return MessageIterator(self.client, self, **kwargs) return MessageIterator(self.client, self, **kwargs)
@ -232,7 +232,7 @@ class Channel(SlottedModel, Permissible):
def send_message(self, content, nonce=None, tts=False): def send_message(self, content, nonce=None, tts=False):
""" """
Send a message in this channel Send a message in this channel.
Parameters Parameters
---------- ----------
@ -252,7 +252,7 @@ class Channel(SlottedModel, Permissible):
def connect(self, *args, **kwargs): def connect(self, *args, **kwargs):
""" """
Connect to this channel over voice Connect to this channel over voice.
""" """
assert self.is_voice, 'Channel must support voice to connect' assert self.is_voice, 'Channel must support voice to connect'
vc = VoiceClient(self) vc = VoiceClient(self)
@ -351,7 +351,7 @@ class MessageIterator(object):
def fill(self): def fill(self):
""" """
Fills the internal buffer up with :class:`disco.types.message.Message` objects from the API Fills the internal buffer up with :class:`disco.types.message.Message` objects from the API.
""" """
self._buffer = self.client.api.channels_messages_list( self._buffer = self.client.api.channels_messages_list(
self.channel.id, self.channel.id,

10
disco/types/guild.py

@ -27,7 +27,7 @@ VerificationLevel = Enum(
class GuildEmoji(Emoji): class GuildEmoji(Emoji):
""" """
An emoji object An emoji object.
Attributes Attributes
---------- ----------
@ -56,7 +56,7 @@ class GuildEmoji(Emoji):
class Role(SlottedModel): class Role(SlottedModel):
""" """
A role object A role object.
Attributes Attributes
---------- ----------
@ -105,7 +105,7 @@ class Role(SlottedModel):
class GuildMember(SlottedModel): class GuildMember(SlottedModel):
""" """
A GuildMember object A GuildMember object.
Attributes Attributes
---------- ----------
@ -193,7 +193,7 @@ class GuildMember(SlottedModel):
@property @property
def id(self): def id(self):
""" """
Alias to the guild members user id Alias to the guild members user id.
""" """
return self.user.id return self.user.id
@ -208,7 +208,7 @@ class GuildMember(SlottedModel):
class Guild(SlottedModel, Permissible): class Guild(SlottedModel, Permissible):
""" """
A guild object A guild object.
Attributes Attributes
---------- ----------

2
disco/types/invite.py

@ -6,7 +6,7 @@ from disco.types.channel import Channel
class Invite(SlottedModel): class Invite(SlottedModel):
""" """
An invite object An invite object.
Attributes Attributes
---------- ----------

8
disco/types/message.py

@ -88,7 +88,7 @@ class MessageEmbedField(SlottedModel):
class MessageEmbed(SlottedModel): class MessageEmbed(SlottedModel):
""" """
Message embed object Message embed object.
Attributes Attributes
---------- ----------
@ -117,7 +117,7 @@ class MessageEmbed(SlottedModel):
class MessageAttachment(SlottedModel): class MessageAttachment(SlottedModel):
""" """
Message attachment object Message attachment object.
Attributes Attributes
---------- ----------
@ -242,7 +242,7 @@ class Message(SlottedModel):
def reply(self, *args, **kwargs): def reply(self, *args, **kwargs):
""" """
Reply to this message (proxys arguments to Reply to this message (proxys arguments to
:func:`disco.types.channel.Channel.send_message`) :func:`disco.types.channel.Channel.send_message`).
Returns Returns
------- -------
@ -253,7 +253,7 @@ class Message(SlottedModel):
def edit(self, content): def edit(self, content):
""" """
Edit this message Edit this message.
Args Args
---- ----

2
disco/util/token.py

@ -5,6 +5,6 @@ TOKEN_RE = re.compile(r'M\w{23}\.[\w-]{6}\..{27}')
def is_valid_token(token): def is_valid_token(token):
""" """
Validates a Discord authentication token, returning true if valid Validates a Discord authentication token, returning true if valid.
""" """
return bool(TOKEN_RE.match(token)) return bool(TOKEN_RE.match(token))

Loading…
Cancel
Save