Browse Source

[QOL] Flake8 CI and Fixes (#61)

* Add flake8 to travis

* Various flake8 fixes

* dont

* Only test against 2.7 / 3.6

I really don't care about 3.3/3.4/3.5

* Fix usage of unicode
develop
Andrei Zbikowski 8 years ago
committed by GitHub
parent
commit
44689af035
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .flake8
  2. 10
      .travis.yml
  3. 34
      disco/api/client.py
  4. 4
      disco/api/http.py
  5. 6
      disco/bot/bot.py
  6. 7
      disco/bot/command.py
  7. 20
      disco/bot/parser.py
  8. 8
      disco/bot/storage.py
  9. 4
      disco/client.py
  10. 10
      disco/gateway/client.py
  11. 2
      disco/gateway/events.py
  12. 2
      disco/gateway/ipc.py
  13. 18
      disco/gateway/sharder.py
  14. 4
      disco/state.py
  15. 24
      disco/types/__init__.py
  16. 6
      disco/types/base.py
  17. 6
      disco/types/channel.py
  18. 16
      disco/types/guild.py
  19. 2
      disco/types/message.py
  20. 4
      disco/types/user.py
  21. 11
      disco/types/webhook.py
  22. 2
      disco/util/hashmap.py
  23. 1
      disco/util/limiter.py
  24. 2
      disco/util/logging.py
  25. 8
      disco/voice/__init__.py
  26. 8
      disco/voice/client.py
  27. 2
      disco/voice/opus.py
  28. 4
      disco/voice/playable.py
  29. 2
      disco/voice/player.py
  30. 2
      tests/types/embeds.py

3
.flake8

@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
ignore=C408,C815,A003

10
.travis.yml

@ -4,12 +4,12 @@ cache: pip
python: python:
- '2.7' - '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6' - '3.6'
install: install:
- pip install -U pip setuptools pytest - pip install -U pip setuptools
- pip install -U pytest flake8-tuple flake8-quotes flake8-comprehensions flake8-commas flake8-builtins
script: 'python setup.py test' script:
- python setup.py test
- flake8 disco/

34
disco/api/client.py

@ -34,7 +34,7 @@ def _reason_header(value):
class Responses(list): class Responses(list):
def rate_limited_duration(self): def rate_limited_duration(self):
return sum([i.rate_limited_duration for i in self]) return sum(i.rate_limited_duration for i in self)
@property @property
def rate_limited(self): def rate_limited(self):
@ -128,7 +128,7 @@ class APIClient(LoggingClass):
around=around, around=around,
before=before, before=before,
after=after, after=after,
limit=limit limit=limit,
)) ))
return Message.create_map(self.client, r.json()) return Message.create_map(self.client, r.json())
@ -137,8 +137,16 @@ class APIClient(LoggingClass):
r = self.http(Routes.CHANNELS_MESSAGES_GET, dict(channel=channel, message=message)) r = self.http(Routes.CHANNELS_MESSAGES_GET, dict(channel=channel, message=message))
return Message.create(self.client, r.json()) return Message.create(self.client, r.json())
def channels_messages_create(self, channel, content=None, nonce=None, tts=False, def channels_messages_create(
attachment=None, attachments=[], embed=None, sanitize=False): self,
channel,
content=None,
nonce=None,
tts=False,
attachment=None,
attachments=[],
embed=None,
sanitize=False):
payload = { payload = {
'nonce': nonce, 'nonce': nonce,
@ -173,7 +181,7 @@ class APIClient(LoggingClass):
Routes.CHANNELS_MESSAGES_CREATE, Routes.CHANNELS_MESSAGES_CREATE,
dict(channel=channel), dict(channel=channel),
data={'payload_json': json.dumps(payload)}, data={'payload_json': json.dumps(payload)},
files=files files=files,
) )
else: else:
r = self.http(Routes.CHANNELS_MESSAGES_CREATE, dict(channel=channel), json=payload) r = self.http(Routes.CHANNELS_MESSAGES_CREATE, dict(channel=channel), json=payload)
@ -232,7 +240,7 @@ class APIClient(LoggingClass):
def channels_permissions_delete(self, channel, permission, reason=None): def channels_permissions_delete(self, channel, permission, reason=None):
self.http( self.http(
Routes.CHANNELS_PERMISSIONS_DELETE, Routes.CHANNELS_PERMISSIONS_DELETE,
dict(channel=channel, permission=permission), headers=_reason_header(reason) dict(channel=channel, permission=permission), headers=_reason_header(reason),
) )
def channels_invites_list(self, channel): def channels_invites_list(self, channel):
@ -244,7 +252,7 @@ class APIClient(LoggingClass):
'max_age': max_age, 'max_age': max_age,
'max_uses': max_uses, 'max_uses': max_uses,
'temporary': temporary, 'temporary': temporary,
'unique': unique 'unique': unique,
}, headers=_reason_header(reason)) }, headers=_reason_header(reason))
return Invite.create(self.client, r.json()) return Invite.create(self.client, r.json())
@ -285,7 +293,8 @@ class APIClient(LoggingClass):
r = self.http(Routes.GUILDS_CHANNELS_LIST, dict(guild=guild)) r = self.http(Routes.GUILDS_CHANNELS_LIST, dict(guild=guild))
return Channel.create_hash(self.client, 'id', r.json(), guild_id=guild) return Channel.create_hash(self.client, 'id', r.json(), guild_id=guild)
def guilds_channels_create(self, def guilds_channels_create(
self,
guild, guild,
channel_type, channel_type,
name, name,
@ -379,7 +388,9 @@ class APIClient(LoggingClass):
r = self.http(Routes.GUILDS_ROLES_LIST, dict(guild=guild)) r = self.http(Routes.GUILDS_ROLES_LIST, dict(guild=guild))
return Role.create_map(self.client, r.json(), guild_id=guild) return Role.create_map(self.client, r.json(), guild_id=guild)
def guilds_roles_create(self, guild, def guilds_roles_create(
self,
guild,
name=None, name=None,
permissions=None, permissions=None,
color=None, color=None,
@ -404,7 +415,10 @@ class APIClient(LoggingClass):
r = self.http(Routes.GUILDS_ROLES_MODIFY_BATCH, dict(guild=guild), json=roles, headers=_reason_header(reason)) r = self.http(Routes.GUILDS_ROLES_MODIFY_BATCH, dict(guild=guild), json=roles, headers=_reason_header(reason))
return Role.create_map(self.client, r.json(), guild_id=guild) return Role.create_map(self.client, r.json(), guild_id=guild)
def guilds_roles_modify(self, guild, role, def guilds_roles_modify(
self,
guild,
role,
name=None, name=None,
hoist=None, hoist=None,
color=None, color=None,

4
disco/api/http.py

@ -159,7 +159,7 @@ class APIException(Exception):
self.errors = {} self.errors = {}
if self.retries: if self.retries:
self.msg += " after {} retries".format(self.retries) self.msg += ' after {} retries'.format(self.retries)
# Try to decode JSON, and extract params # Try to decode JSON, and extract params
try: try:
@ -298,7 +298,7 @@ class HTTPClient(LoggingClass):
backoff = self.random_backoff() backoff = self.random_backoff()
self.log.warning('Request to `{}` failed with code {}, retrying after {}s ({})'.format( self.log.warning('Request to `{}` failed with code {}, retrying after {}s ({})'.format(
url, r.status_code, backoff, r.content url, r.status_code, backoff, r.content,
)) ))
gevent.sleep(backoff) gevent.sleep(backoff)

6
disco/bot/bot.py

@ -217,7 +217,7 @@ class Bot(LoggingClass):
Called when a plugin is loaded/unloaded to recompute internal state. Called when a plugin is loaded/unloaded to recompute internal state.
""" """
if self.config.commands_group_abbrev: if self.config.commands_group_abbrev:
groups = set(command.group for command in self.commands if command.group) groups = {command.group for command in self.commands if command.group}
self.group_abbrev = self.compute_group_abbrev(groups) self.group_abbrev = self.compute_group_abbrev(groups)
self.compute_command_matches_re() self.compute_command_matches_re()
@ -293,7 +293,7 @@ class Bot(LoggingClass):
mention_rules.get('user', True) and mention_direct, mention_rules.get('user', True) and mention_direct,
mention_rules.get('everyone', False) and mention_everyone, mention_rules.get('everyone', False) and mention_everyone,
mention_rules.get('role', False) and any(mention_roles), mention_rules.get('role', False) and any(mention_roles),
msg.channel.is_dm msg.channel.is_dm,
)): )):
return [] return []
@ -375,7 +375,7 @@ class Bot(LoggingClass):
self.config.commands_require_mention, self.config.commands_require_mention,
self.config.commands_mention_rules, self.config.commands_mention_rules,
self.config.commands_prefix, self.config.commands_prefix,
msg msg,
)) ))
if not len(commands): if not len(commands):

7
disco/bot/command.py

@ -163,7 +163,8 @@ class Command(object):
def get_docstring(self): def get_docstring(self):
return (self.func.__doc__ or '').format(**self.context) return (self.func.__doc__ or '').format(**self.context)
def update(self, def update(
self,
args=None, args=None,
level=None, level=None,
aliases=None, aliases=None,
@ -266,7 +267,7 @@ class Command(object):
group = self.group + ' ' group = self.group + ' '
return ('^{}({})' if grouped else '^{}(?:{})').format( return ('^{}({})' if grouped else '^{}(?:{})').format(
group, group,
'|'.join(self.triggers) '|'.join(self.triggers),
) + (ARGS_REGEX if grouped else ARGS_UNGROUPED_REGEX) ) + (ARGS_REGEX if grouped else ARGS_UNGROUPED_REGEX)
def execute(self, event): def execute(self, event):
@ -287,7 +288,7 @@ class Command(object):
event.name, event.name,
self.args.required_length, self.args.required_length,
self.raw_args, self.raw_args,
len(event.args) len(event.args),
)) ))
try: try:

20
disco/bot/parser.py

@ -5,11 +5,20 @@ import copy
# Regex which splits out argument parts # Regex which splits out argument parts
PARTS_RE = re.compile('(\<|\[|\{)((?:\w+|\:|\||\.\.\.| (?:[0-9]+))+)(?:\>|\]|\})') PARTS_RE = re.compile('(\<|\[|\{)((?:\w+|\:|\||\.\.\.| (?:[0-9]+))+)(?:\>|\]|\})')
BOOL_OPTS = {'yes': True, 'no': False, 'true': True, 'False': False, '1': True, '0': False} BOOL_OPTS = {
'yes': True,
'no': False,
'true': True,
'False': False,
'1': True,
'0': False,
'on': True,
'off': False,
}
# Mapping of types # Mapping of types
TYPE_MAP = { TYPE_MAP = {
'str': lambda ctx, data: str(data) if six.PY3 else unicode(data), 'str': lambda ctx, data: six.text_type(data),
'int': lambda ctx, data: int(data), 'int': lambda ctx, data: int(data),
'float': lambda ctx, data: float(data), 'float': lambda ctx, data: float(data),
'snowflake': lambda ctx, data: int(data), 'snowflake': lambda ctx, data: int(data),
@ -21,6 +30,7 @@ def to_bool(ctx, data):
return BOOL_OPTS[data] return BOOL_OPTS[data]
raise TypeError raise TypeError
TYPE_MAP['bool'] = to_bool TYPE_MAP['bool'] = to_bool
@ -190,9 +200,9 @@ class ArgumentSet(object):
for idx, r in enumerate(raw): for idx, r in enumerate(raw):
try: try:
raw[idx] = self.convert(ctx, arg.types, r) raw[idx] = self.convert(ctx, arg.types, r)
except: except Exception:
raise ArgumentError(u'cannot convert `{}` to `{}`'.format( raise ArgumentError(u'cannot convert `{}` to `{}`'.format(
r, ', '.join(arg.types) r, ', '.join(arg.types),
)) ))
if arg.count == 1: if arg.count == 1:
@ -217,4 +227,4 @@ class ArgumentSet(object):
""" """
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)

8
disco/bot/storage.py

@ -70,20 +70,20 @@ class Storage(object):
def guild(self, key): def guild(self, key):
return ContextAwareProxy( return ContextAwareProxy(
lambda: self['_g{}:{}'.format(self._ctx['guild'].id, key)] lambda: self['_g{}:{}'.format(self._ctx['guild'].id, key)],
) )
def channel(self, key): def channel(self, key):
return ContextAwareProxy( return ContextAwareProxy(
lambda: self['_c{}:{}'.format(self._ctx['channel'].id, key)] lambda: self['_c{}:{}'.format(self._ctx['channel'].id, key)],
) )
def plugin(self, key): def plugin(self, key):
return ContextAwareProxy( return ContextAwareProxy(
lambda: self['_p{}:{}'.format(self._ctx['plugin'].name, key)] lambda: self['_p{}:{}'.format(self._ctx['plugin'].name, key)],
) )
def user(self, key): def user(self, key):
return ContextAwareProxy( return ContextAwareProxy(
lambda: self['_u{}:{}'.format(self._ctx['user'].id, key)] lambda: self['_u{}:{}'.format(self._ctx['user'].id, key)],
) )

4
disco/client.py

@ -40,7 +40,7 @@ class ClientConfig(Config):
should be either 'json' or 'etf'. should be either 'json' or 'etf'.
""" """
token = "" token = ''
shard_id = 0 shard_id = 0
shard_count = 1 shard_count = 1
max_reconnects = 5 max_reconnects = 5
@ -100,7 +100,7 @@ class Client(LoggingClass):
'client': self, 'client': self,
'state': self.state, 'state': self.state,
'api': self.api, 'api': self.api,
'gw': self.gw 'gw': self.gw,
} }
self.manhole = DiscoBackdoorServer(self.config.manhole_bind, self.manhole = DiscoBackdoorServer(self.config.manhole_bind,

10
disco/gateway/client.py

@ -136,7 +136,7 @@ class GatewayClient(LoggingClass):
self.ws.emitter.on('on_close', self.on_close) self.ws.emitter.on('on_close', self.on_close)
self.ws.emitter.on('on_message', self.on_message) self.ws.emitter.on('on_message', self.on_message)
self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) self.ws.run_forever(sslopt={'cert_reqs': ssl.CERT_NONE})
def on_message(self, msg): def on_message(self, msg):
if self.zlib_stream_enabled: if self.zlib_stream_enabled:
@ -157,11 +157,11 @@ class GatewayClient(LoggingClass):
# Detect zlib and decompress # Detect zlib and decompress
is_erlpack = ((six.PY2 and ord(msg[0]) == 131) or (six.PY3 and msg[0] == 131)) is_erlpack = ((six.PY2 and ord(msg[0]) == 131) or (six.PY3 and msg[0] == 131))
if msg[0] != '{' and not is_erlpack: if msg[0] != '{' and not is_erlpack:
msg = zlib.decompress(msg, 15, TEN_MEGABYTES).decode("utf-8") msg = zlib.decompress(msg, 15, TEN_MEGABYTES).decode('utf-8')
try: try:
data = self.encoder.decode(msg) data = self.encoder.decode(msg)
except: except Exception:
self.log.exception('Failed to parse gateway message: ') self.log.exception('Failed to parse gateway message: ')
return return
@ -188,7 +188,7 @@ class GatewayClient(LoggingClass):
self.send(OPCode.RESUME, { self.send(OPCode.RESUME, {
'token': self.client.config.token, 'token': self.client.config.token,
'session_id': self.session_id, 'session_id': self.session_id,
'seq': self.seq 'seq': self.seq,
}) })
else: else:
self.log.info('WS Opened: sending identify payload') self.log.info('WS Opened: sending identify payload')
@ -205,7 +205,7 @@ class GatewayClient(LoggingClass):
'$browser': 'disco', '$browser': 'disco',
'$device': 'disco', '$device': 'disco',
'$referrer': '', '$referrer': '',
} },
}) })
def on_close(self, code, reason): def on_close(self, code, reason):

2
disco/gateway/events.py

@ -630,7 +630,7 @@ class MessageReactionAdd(GatewayEvent):
self.channel_id, self.channel_id,
self.message_id, self.message_id,
self.emoji.to_string() if self.emoji.id else self.emoji.name, self.emoji.to_string() if self.emoji.id else self.emoji.name,
self.user_id self.user_id,
) )
@property @property

2
disco/gateway/ipc.py

@ -68,7 +68,7 @@ class GIPCProxy(LoggingClass):
try: try:
self.handle(mtype, data) self.handle(mtype, data)
except: except Exception:
self.log.exception('Error in GIPCProxy:') self.log.exception('Error in GIPCProxy:')
def execute(self, func): def execute(self, func):

18
disco/gateway/sharder.py

@ -21,7 +21,7 @@ from disco.util.serializer import dump_function, load_function
def run_shard(config, shard_id, pipe): def run_shard(config, shard_id, pipe):
setup_logging( setup_logging(
level=logging.INFO, level=logging.INFO,
format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(shard_id) format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(shard_id),
) )
config.shard_id = shard_id config.shard_id = shard_id
@ -41,17 +41,23 @@ class ShardHelper(object):
for sid in range(self.count): for sid in range(self.count):
yield sid yield sid
def on(self, id, func): def on(self, sid, func):
if id == self.bot.client.config.shard_id: if sid == self.bot.client.config.shard_id:
result = gevent.event.AsyncResult() result = gevent.event.AsyncResult()
result.set(func(self.bot)) result.set(func(self.bot))
return result return result
return self.bot.sharder.call(('run_on', ), id, dump_function(func)) return self.bot.sharder.call(('run_on', ), sid, dump_function(func))
def all(self, func, timeout=None): def all(self, func, timeout=None):
pool = gevent.pool.Pool(self.count) pool = gevent.pool.Pool(self.count)
return dict(zip(range(self.count), pool.imap(lambda i: self.on(i, func).wait(timeout=timeout), range(self.count)))) return dict(zip(
range(self.count),
pool.imap(
lambda i: self.on(i, func).wait(timeout=timeout),
range(self.count),
),
))
def for_id(self, sid, func): def for_id(self, sid, func):
shard = calculate_shard(self.count, sid) shard = calculate_shard(self.count, sid)
@ -79,7 +85,7 @@ class AutoSharder(object):
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,
format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(id) format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(id),
) )
@staticmethod @staticmethod

4
disco/state.py

@ -90,7 +90,7 @@ class State(object):
'Ready', 'GuildCreate', 'GuildUpdate', 'GuildDelete', 'GuildMemberAdd', 'GuildMemberRemove', 'Ready', 'GuildCreate', 'GuildUpdate', 'GuildDelete', 'GuildMemberAdd', 'GuildMemberRemove',
'GuildMemberUpdate', 'GuildMembersChunk', 'GuildRoleCreate', 'GuildRoleUpdate', 'GuildRoleDelete', 'GuildMemberUpdate', 'GuildMembersChunk', 'GuildRoleCreate', 'GuildRoleUpdate', 'GuildRoleDelete',
'GuildEmojisUpdate', 'ChannelCreate', 'ChannelUpdate', 'ChannelDelete', 'VoiceStateUpdate', 'MessageCreate', 'GuildEmojisUpdate', 'ChannelCreate', 'ChannelUpdate', 'ChannelDelete', 'VoiceStateUpdate', 'MessageCreate',
'PresenceUpdate' 'PresenceUpdate',
] ]
def __init__(self, client, config): def __init__(self, client, config):
@ -202,7 +202,7 @@ class State(object):
'channels', 'channels',
'members', 'members',
'voice_states', 'voice_states',
'presences' 'presences',
]) ])
def on_guild_delete(self, event): def on_guild_delete(self, event):

24
disco/types/__init__.py

@ -1,6 +1,18 @@
from disco.types.base import UNSET from disco.types.base import UNSET # noqa: F401
from disco.types.channel import Channel from disco.types.channel import Channel # noqa: F401
from disco.types.guild import Guild, GuildMember, Role from disco.types.guild import Guild, GuildMember, Role # noqa: F401
from disco.types.user import User from disco.types.user import User # noqa: F401
from disco.types.message import Message from disco.types.message import Message # noqa: F401
from disco.types.voice import VoiceState from disco.types.voice import VoiceState # noqa: F401
# TODO: deprecate this entire file
__all__ = {
'UNSET',
'Channel',
'Guild',
'GuildMember',
'Role',
'User',
'Message',
'VoiceState',
}

6
disco/types/base.py

@ -11,7 +11,7 @@ from disco.util.hashmap import HashMap
DATETIME_FORMATS = [ DATETIME_FORMATS = [
'%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S.%f',
'%Y-%m-%dT%H:%M:%S' '%Y-%m-%dT%H:%M:%S',
] ]
@ -373,7 +373,7 @@ class Model(six.with_metaclass(ModelMeta, Chainable)):
if isinstance(getattr(type(self), name), property): if isinstance(getattr(type(self), name), property):
try: try:
delattr(self, name) delattr(self, name)
except: except Exception:
pass pass
def to_dict(self, ignore=None): def to_dict(self, ignore=None):
@ -411,7 +411,7 @@ class Model(six.with_metaclass(ModelMeta, Chainable)):
for k, v in six.iteritems(data): for k, v in six.iteritems(data):
try: try:
setattr(item, k, v) setattr(item, k, v)
except: except Exception:
pass pass

6
disco/types/channel.py

@ -24,7 +24,7 @@ ChannelType = Enum(
PermissionOverwriteType = Enum( PermissionOverwriteType = Enum(
ROLE='role', ROLE='role',
MEMBER='member' MEMBER='member',
) )
@ -69,7 +69,7 @@ class PermissionOverwrite(ChannelSubType):
type=ptype, type=ptype,
allow=allow, allow=allow,
deny=deny, deny=deny,
channel_id=channel.id channel_id=channel.id,
).save() ).save()
@property @property
@ -139,7 +139,7 @@ class Channel(SlottedModel, Permissible):
self.attach(six.itervalues(self.overwrites), {'channel_id': self.id, 'channel': self}) self.attach(six.itervalues(self.overwrites), {'channel_id': self.id, 'channel': self})
def __str__(self): def __str__(self):
return u'#{}'.format(self.name) if self.name else unicode(self.id) return u'#{}'.format(self.name) if self.name else six.text_type(self.id)
def __repr__(self): def __repr__(self):
return u'<Channel {} ({})>'.format(self.id, self) return u'<Channel {} ({})>'.format(self.id, self)

16
disco/types/guild.py

@ -9,7 +9,7 @@ from disco.util.paginator import Paginator
from disco.util.snowflake import to_snowflake from disco.util.snowflake import to_snowflake
from disco.types.base import ( from disco.types.base import (
SlottedModel, Field, ListField, AutoDictField, DictField, snowflake, text, enum, datetime, SlottedModel, Field, ListField, AutoDictField, DictField, snowflake, text, enum, datetime,
cached_property cached_property,
) )
from disco.types.user import User from disco.types.user import User
from disco.types.voice import VoiceState from disco.types.voice import VoiceState
@ -29,7 +29,7 @@ VerificationLevel = Enum(
ExplicitContentFilterLevel = Enum( ExplicitContentFilterLevel = Enum(
NONE=0, NONE=0,
WITHOUT_ROLES=1, WITHOUT_ROLES=1,
ALL=2 ALL=2,
) )
DefaultMessageNotificationsLevel = Enum( DefaultMessageNotificationsLevel = Enum(
@ -449,9 +449,9 @@ class Guild(SlottedModel, Permissible):
return self.client.api.guilds_channels_create(self.id, *args, **kwargs) return self.client.api.guilds_channels_create(self.id, *args, **kwargs)
def create_category(self, name, permission_overwrites=[], position=None, reason=None): def create_category(self, name, permission_overwrites=[], position=None, reason=None):
''' """
Creates a category within the guild. Creates a category within the guild.
''' """
return self.client.api.guilds_channels_create( return self.client.api.guilds_channels_create(
self.id, ChannelType.GUILD_CATEGORY, name=name, permission_overwrites=permission_overwrites, self.id, ChannelType.GUILD_CATEGORY, name=name, permission_overwrites=permission_overwrites,
position=position, reason=reason, position=position, reason=reason,
@ -465,9 +465,9 @@ class Guild(SlottedModel, Permissible):
nsfw=None, nsfw=None,
position=None, position=None,
reason=None): reason=None):
''' """
Creates a text channel within the guild. Creates a text channel within the guild.
''' """
return self.client.api.guilds_channels_create( return self.client.api.guilds_channels_create(
self.id, ChannelType.GUILD_TEXT, name=name, permission_overwrites=permission_overwrites, self.id, ChannelType.GUILD_TEXT, name=name, permission_overwrites=permission_overwrites,
parent_id=parent_id, nsfw=nsfw, position=position, reason=reason, parent_id=parent_id, nsfw=nsfw, position=position, reason=reason,
@ -482,9 +482,9 @@ class Guild(SlottedModel, Permissible):
user_limit=None, user_limit=None,
position=None, position=None,
reason=None): reason=None):
''' """
Creates a voice channel within the guild. Creates a voice channel within the guild.
''' """
return self.client.api.guilds_channels_create( return self.client.api.guilds_channels_create(
self.id, ChannelType.GUILD_VOICE, name=name, permission_overwrites=permission_overwrites, self.id, ChannelType.GUILD_VOICE, name=name, permission_overwrites=permission_overwrites,
parent_id=parent_id, bitrate=bitrate, user_limit=user_limit, position=position, reason=None) parent_id=parent_id, bitrate=bitrate, user_limit=user_limit, position=position, reason=None)

2
disco/types/message.py

@ -8,7 +8,7 @@ from holster.enum import Enum
from disco.types.base import ( from disco.types.base import (
SlottedModel, Field, ListField, AutoDictField, snowflake, text, SlottedModel, Field, ListField, AutoDictField, snowflake, text,
datetime, enum, cached_property datetime, enum, cached_property,
) )
from disco.util.paginator import Paginator from disco.util.paginator import Paginator
from disco.util.snowflake import to_snowflake from disco.util.snowflake import to_snowflake

4
disco/types/user.py

@ -30,7 +30,7 @@ class User(SlottedModel, with_equality('id'), with_hash('id')):
self.id, self.id,
self.avatar, self.avatar,
fmt, fmt,
size size,
) )
@property @property
@ -65,7 +65,7 @@ Status = Enum(
'IDLE', 'IDLE',
'DND', 'DND',
'INVISIBLE', 'INVISIBLE',
'OFFLINE' 'OFFLINE',
) )

11
disco/types/webhook.py

@ -49,7 +49,16 @@ class Webhook(SlottedModel):
else: else:
return self.client.api.webhooks_modify(self.id, name, avatar) return self.client.api.webhooks_modify(self.id, name, avatar)
def execute(self, content=None, username=None, avatar_url=None, tts=False, fobj=None, embeds=[], wait=False, client=None): def execute(
self,
content=None,
username=None,
avatar_url=None,
tts=False,
fobj=None,
embeds=[],
wait=False,
client=None):
# TODO: support file stuff properly # TODO: support file stuff properly
client = client or self.client.api client = client or self.client.api

2
disco/util/hashmap.py

@ -29,7 +29,7 @@ class HashMap(dict):
def select(self, *args, **kwargs): def select(self, *args, **kwargs):
if kwargs: if kwargs:
args += tuple([kwargs]) args += tuple(kwargs)
for obj in self.values(): for obj in self.values():
for check in args: for check in args:

1
disco/util/limiter.py

@ -1,4 +1,3 @@
import time
import gevent import gevent

2
disco/util/logging.py

@ -5,7 +5,7 @@ import logging
LEVEL_OVERRIDES = { LEVEL_OVERRIDES = {
'requests': logging.WARNING 'requests': logging.WARNING,
} }
LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s' LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'

8
disco/voice/__init__.py

@ -1,3 +1,5 @@
from disco.voice.client import * from disco.voice.client import * # noqa: F401,F403
from disco.voice.player import * from disco.voice.player import * # noqa: F401,F403
from disco.voice.playable import * from disco.voice.playable import * # noqa: F401,F403
# TODO: deprecate this file

8
disco/voice/client.py

@ -205,8 +205,8 @@ class VoiceClient(LoggingClass):
'data': { 'data': {
'port': port, 'port': port,
'address': ip, 'address': ip,
'mode': 'xsalsa20_poly1305' 'mode': 'xsalsa20_poly1305',
} },
}) })
def on_voice_sdp(self, sdp): def on_voice_sdp(self, sdp):
@ -245,7 +245,7 @@ class VoiceClient(LoggingClass):
try: try:
data = self.encoder.decode(msg) data = self.encoder.decode(msg)
self.packets.emit(VoiceOPCode[data['op']], data['d']) self.packets.emit(VoiceOPCode[data['op']], data['d'])
except: except Exception:
self.log.exception('Failed to parse voice gateway message: ') self.log.exception('Failed to parse voice gateway message: ')
def on_error(self, err): def on_error(self, err):
@ -256,7 +256,7 @@ class VoiceClient(LoggingClass):
'server_id': self.channel.guild_id, 'server_id': self.channel.guild_id,
'user_id': self.client.state.me.id, 'user_id': self.client.state.me.id,
'session_id': self.client.gw.session_id, 'session_id': self.client.gw.session_id,
'token': self.token 'token': self.token,
}) })
def on_close(self, code, error): def on_close(self, code, error):

2
disco/voice/opus.py

@ -62,7 +62,7 @@ class BaseOpus(LoggingClass):
Application = Enum( Application = Enum(
AUDIO=2049, AUDIO=2049,
VOIP=2048, VOIP=2048,
LOWDELAY=2051 LOWDELAY=2051,
) )

4
disco/voice/playable.py

@ -13,7 +13,7 @@ from disco.voice.opus import OpusEncoder
try: try:
from cStringIO import cStringIO as BufferedIO from cStringIO import cStringIO as BufferedIO
except: except ImportError:
if six.PY2: if six.PY2:
from StringIO import StringIO as BufferedIO from StringIO import StringIO as BufferedIO
else: else:
@ -139,7 +139,7 @@ class FFmpegInput(BaseInput, AbstractOpus):
'-ar', str(self.sampling_rate), '-ar', str(self.sampling_rate),
'-ac', str(self.channels), '-ac', str(self.channels),
'-loglevel', 'warning', '-loglevel', 'warning',
'pipe:1' 'pipe:1',
] ]
self._proc = subprocess.Popen(args, stdin=None, stdout=subprocess.PIPE) self._proc = subprocess.Popen(args, stdin=None, stdout=subprocess.PIPE)
return self._proc return self._proc

2
disco/voice/player.py

@ -16,7 +16,7 @@ class Player(object):
'STOP_PLAY', 'STOP_PLAY',
'PAUSE_PLAY', 'PAUSE_PLAY',
'RESUME_PLAY', 'RESUME_PLAY',
'DISCONNECT' 'DISCONNECT',
) )
def __init__(self, client, queue=None): def __init__(self, client, queue=None):

2
tests/types/embeds.py

@ -1,6 +1,5 @@
from unittest import TestCase from unittest import TestCase
from datetime import datetime
from disco.types.message import MessageEmbed from disco.types.message import MessageEmbed
@ -29,4 +28,3 @@ class TestEmbeds(TestCase):
self.assertEqual(obj['title'], 'Test Title') self.assertEqual(obj['title'], 'Test Title')
self.assertEqual(obj['description'], 'Test Description') self.assertEqual(obj['description'], 'Test Description')
self.assertEqual(obj['url'], 'https://test.url/') self.assertEqual(obj['url'], 'https://test.url/')

Loading…
Cancel
Save