mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Add outputfunc to add roles through the bot.
This commit is contained in:
parent
3532fffca4
commit
61083ed9b5
2 changed files with 24 additions and 2 deletions
|
|
@ -649,6 +649,10 @@ class DiscordBot(Bot):
|
|||
"""
|
||||
super().msg(nickname=(new_nickname, guild_id, user_id))
|
||||
|
||||
def assign_role(self, role_id, guild_id, user_id, **kwargs):
|
||||
|
||||
pass
|
||||
|
||||
def direct_msg(self, message, sender, **kwargs):
|
||||
"""
|
||||
Called when the Discord bot receives a direct message on Discord.
|
||||
|
|
|
|||
|
|
@ -352,9 +352,19 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
|||
"""
|
||||
url = f"{DISCORD_API_BASE_URL}/{url}"
|
||||
body = FileBodyProducer(BytesIO(json.dumps(data).encode("utf-8")))
|
||||
is_patch_request = kwargs.pop('patch', False)
|
||||
is_patch_request = kwargs.pop("patch", False)
|
||||
is_put_request = kwargs.pop("put", False)
|
||||
request_type = "POST"
|
||||
|
||||
if is_patch_request:
|
||||
request_type = b"PATCH"
|
||||
elif is_put_request:
|
||||
request_type = b"PUT"
|
||||
else:
|
||||
request_type = b"POST"
|
||||
|
||||
d = _AGENT.request(
|
||||
b"PATCH" if is_patch_request else b"POST",
|
||||
request_type,
|
||||
url.encode("utf-8"),
|
||||
Headers(
|
||||
{
|
||||
|
|
@ -371,6 +381,9 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
|||
d = readBody(response)
|
||||
d.addCallback(self.post_response)
|
||||
return d
|
||||
elif response.code == 204:
|
||||
d = readBody(response)
|
||||
d.addCallback(self.post_response)
|
||||
elif should_retry(response.code):
|
||||
delay(300, self._post_json, url, data, **kwargs)
|
||||
|
||||
|
|
@ -499,6 +512,11 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS):
|
|||
data.update(kwargs)
|
||||
self._post_json(f"guilds/{guild_id}/members/{user_id}", data, patch=True)
|
||||
|
||||
def send_role(self, role_id, guild_id, user_id, **kwargs):
|
||||
|
||||
data = kwargs
|
||||
self._post_json(f"guilds/{guild_id}/members/{user_id}/roles/{role_id}", put=True)
|
||||
|
||||
def send_default(self, *args, **kwargs):
|
||||
"""
|
||||
Ignore other outputfuncs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue