mirror of https://gitlab.com/litecord/litecord.git
Merge branch 'feature/guild-join-messages' into 'master'
Add guild join system message Closes #95 See merge request litecord/litecord!81
This commit is contained in:
commit
2283030fc3
|
|
@ -23,8 +23,9 @@ from quart import current_app as app
|
|||
|
||||
from ..permissions import get_role_perms, get_permissions
|
||||
from ..utils import dict_get, maybe_lazy_guild_dispatch
|
||||
from ..enums import ChannelType
|
||||
from ..enums import ChannelType, MessageType
|
||||
from litecord.pubsub.member import dispatch_member
|
||||
from litecord.system_messages import send_sys_message
|
||||
|
||||
log = Logger(__name__)
|
||||
|
||||
|
|
@ -323,7 +324,17 @@ async def add_member(guild_id: int, user_id: int, *, basic=False):
|
|||
if basic:
|
||||
return
|
||||
|
||||
# TODO: system message for member join
|
||||
system_channel_id = await app.db.fetchval(
|
||||
"""
|
||||
SELECT system_channel_id FROM guilds
|
||||
WHERE id = $1
|
||||
""",
|
||||
guild_id,
|
||||
)
|
||||
if system_channel_id:
|
||||
await send_sys_message(
|
||||
system_channel_id, MessageType.GUILD_MEMBER_JOIN, user_id
|
||||
)
|
||||
|
||||
await app.db.execute(
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -46,6 +46,26 @@ async def _handle_pin_msg(channel_id, _pinned_id, author_id):
|
|||
return new_id
|
||||
|
||||
|
||||
async def _handle_guild_join_msg(channel_id, user_id):
|
||||
"""Handle the system join message."""
|
||||
new_id = app.winter_factory.snowflake()
|
||||
|
||||
await app.db.execute(
|
||||
"""
|
||||
INSERT INTO messages
|
||||
(id, channel_id, guild_id, author_id, content, message_type)
|
||||
VALUES
|
||||
($1, $2, NULL, $3, '', $4)
|
||||
""",
|
||||
new_id,
|
||||
channel_id,
|
||||
user_id,
|
||||
MessageType.GUILD_MEMBER_JOIN.value,
|
||||
)
|
||||
|
||||
return new_id
|
||||
|
||||
|
||||
# TODO: decrease repetition between add and remove handlers
|
||||
async def _handle_recp_add(channel_id, author_id, peer_id):
|
||||
new_id = app.winter_factory.snowflake()
|
||||
|
|
@ -150,8 +170,6 @@ async def send_sys_message(
|
|||
|
||||
Parameters
|
||||
----------
|
||||
app
|
||||
The app instance.
|
||||
channel_id
|
||||
The channel ID to send the system message to.
|
||||
m_type
|
||||
|
|
@ -165,6 +183,7 @@ async def send_sys_message(
|
|||
try:
|
||||
handler = {
|
||||
MessageType.CHANNEL_PINNED_MESSAGE: _handle_pin_msg,
|
||||
MessageType.GUILD_MEMBER_JOIN: _handle_guild_join_msg,
|
||||
# gdm specific
|
||||
MessageType.RECIPIENT_ADD: _handle_recp_add,
|
||||
MessageType.RECIPIENT_REMOVE: _handle_recp_rmv,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
# todo: maybe add more tests lol
|
||||
# :)
|
||||
|
||||
|
||||
async def test_invite_join(test_cli_user):
|
||||
guild = await test_cli_user.create_guild()
|
||||
channel = guild.channels[0]
|
||||
|
||||
resp = await test_cli_user.patch(
|
||||
f"/api/v9/guilds/{guild.id}",
|
||||
json={
|
||||
"system_channel_id": channel["id"],
|
||||
},
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
assert rjson["system_channel_id"] == channel["id"]
|
||||
|
||||
resp = await test_cli_user.post(
|
||||
f'/api/v9/channels/{channel["id"]}/invites', json={}
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
invite_code = rjson["code"]
|
||||
assert rjson["channel"]["id"] == channel["id"]
|
||||
assert rjson["guild"]["id"] == str(guild.id)
|
||||
|
||||
user = await test_cli_user.create_user()
|
||||
|
||||
resp = await test_cli_user.post(
|
||||
f"/api/v9/invites/{invite_code}", headers={"Authorization": user.token}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
Loading…
Reference in New Issue