blueprints.guild: use guild_id = role_id on at-everyone's role

- gateway.websocket: add user_ready function
 - storage: add guild_id by default on member roles
 - storage: add get_role_data
 - schema.sql: change default color from 0 to 1
This commit is contained in:
Luna Mendes 2018-06-23 21:18:19 -03:00
parent 3258dc94d5
commit 2276308c5d
4 changed files with 76 additions and 8 deletions

View File

@ -59,12 +59,10 @@ async def create_guild():
VALUES ($1, $2) VALUES ($1, $2)
""", user_id, guild_id) """, user_id, guild_id)
everyone_role_id = get_snowflake()
await app.db.execute(""" await app.db.execute("""
INSERT INTO roles (id, guild_id, name, position, permissions) INSERT INTO roles (id, guild_id, name, position, permissions)
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4, $5)
""", everyone_role_id, guild_id, '@everyone', 0, 104324161) """, guild_id, guild_id, '@everyone', 0, 104324161)
general_id = get_snowflake() general_id = get_snowflake()

View File

@ -145,19 +145,71 @@ class GatewayWebsocket:
await self.dispatch('GUILD_CREATE', dict(guild)) await self.dispatch('GUILD_CREATE', dict(guild))
async def user_ready(self):
"""Fetch information about users in the READY packet.
This part of the API is completly undocumented.
PLEAS DISCORD DO NOT BAN ME
"""
return {
'relationships': [],
'user_guild_settings': [],
'notes': {},
'friend_suggestion_count': 0,
'presences': [],
'read_state': [],
'experiments': [],
'guild_experiments': [],
'connected_accounts': [],
'user_settings': {
'afk_timeout': 300,
'animate_emoji': True,
'convert_emoticons': False,
'default_guilds_restricted': True,
'detect_platform_accounts': False,
'developer_mode': True,
'enable_tts_command': False,
'explicit_content_filter': 2,
'friend_source_flags': {
'mutual_friends': True
},
'gif_auto_play': True,
'guild_positions': [],
'inline_attachment_media': True,
'inline_embed_media': True,
'locale': 'en-US',
'message_display_compact': False,
'render_embeds': True,
'render_reactions': True,
'restricted_guilds': [],
'show_current_game': True,
'status': 'online',
'theme': 'dark',
'timezone_offset': 420,
},
'analytics_token': 'transbian',
'required_action': 'be gay',
}
async def dispatch_ready(self): async def dispatch_ready(self):
"""Dispatch the READY packet for a connecting account.""" """Dispatch the READY packet for a connecting account."""
guilds = await self._make_guild_list() guilds = await self._make_guild_list()
user = await self.storage.get_user(self.state.user_id, True) user = await self.storage.get_user(self.state.user_id, True)
await self.dispatch('READY', { uready = {}
if not self.state.bot:
# user, fetch info
uready = await self.user_ready()
await self.dispatch('READY', {**{
'v': 6, 'v': 6,
'user': user, 'user': user,
'private_channels': [], 'private_channels': [],
'guilds': guilds, 'guilds': guilds,
'session_id': self.state.session_id, 'session_id': self.state.session_id,
'_trace': ['transbian'] '_trace': ['transbian']
}) }, **uready})
# async dispatch of guilds # async dispatch of guilds
self.ext.loop.create_task(self.guild_dispatch(guilds)) self.ext.loop.create_task(self.guild_dispatch(guilds))

View File

@ -112,7 +112,7 @@ class Storage:
return { return {
'user': await self.get_user(member_id), 'user': await self.get_user(member_id),
'nick': row['nickname'], 'nick': row['nickname'],
'roles': [row[0] for row in members_roles], 'roles': [guild_id] + [row[0] for row in members_roles],
'joined_at': row['joined_at'].isoformat(), 'joined_at': row['joined_at'].isoformat(),
'deaf': row['deafened'], 'deaf': row['deafened'],
'mute': row['muted'], 'mute': row['muted'],
@ -177,7 +177,8 @@ class Storage:
async def get_channel_data(self, guild_id) -> List[Dict]: async def get_channel_data(self, guild_id) -> List[Dict]:
"""Get channel information on a guild""" """Get channel information on a guild"""
channel_basics = await self.db.fetch(""" channel_basics = await self.db.fetch("""
SELECT * FROM guild_channels SELECT id, guild_id::text, parent_id, name, position, nsfw
FROM guild_channels
WHERE guild_id = $1 WHERE guild_id = $1
""", guild_id) """, guild_id)
@ -215,6 +216,21 @@ class Storage:
return channels return channels
async def get_role_data(self, guild_id: int) -> List[Dict[str, Any]]:
roledata = await self.db.fetch("""
SELECT id::text, name, color, hoist, position,
permissions, managed, mentionable
FROM roles
WHERE guild_id = $1
""", guild_id)
roles = []
for row in roledata:
roles.append(dict(row))
return roles
async def get_guild_extra(self, guild_id: int, async def get_guild_extra(self, guild_id: int,
user_id=None, large=None) -> Dict: user_id=None, large=None) -> Dict:
"""Get extra information about a guild.""" """Get extra information about a guild."""
@ -238,12 +254,14 @@ class Storage:
members = await self.get_member_data(guild_id) members = await self.get_member_data(guild_id)
channels = await self.get_channel_data(guild_id) channels = await self.get_channel_data(guild_id)
roles = await self.get_role_data(guild_id)
return {**res, **{ return {**res, **{
'member_count': member_count, 'member_count': member_count,
'members': members, 'members': members,
'voice_states': [], 'voice_states': [],
'channels': channels, 'channels': channels,
'roles': roles,
# TODO: finish those # TODO: finish those
'presences': [], 'presences': [],
}} }}

View File

@ -278,7 +278,7 @@ CREATE TABLE IF NOT EXISTS roles (
guild_id bigint REFERENCES guilds (id) ON DELETE CASCADE, guild_id bigint REFERENCES guilds (id) ON DELETE CASCADE,
name varchar(100) NOT NULL, name varchar(100) NOT NULL,
color int DEFAULT 0, color int DEFAULT 1,
hoist bool DEFAULT false, hoist bool DEFAULT false,
position int NOT NULL, position int NOT NULL,
permissions int NOT NULL, permissions int NOT NULL,