Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #443 from ltworf/fixapi
Browse files Browse the repository at this point in the history
Use the new API to open a /query
  • Loading branch information
ltworf authored Nov 14, 2023
2 parents 6fe78dd + 053592d commit 4d10f4e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
is not needed.
Thanks to: Jiri Bohac <[email protected]>
* Ignore chats with deleted users when downloading history
* Remove calls to removed API calls

1.21
* Introduce lsi-send to send files from the shell
Expand Down
32 changes: 18 additions & 14 deletions irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Replies(Enum):
RPL_ENDOFNAMES = 366
ERR_NOSUCHNICK = 401
ERR_NOSUCHCHANNEL = 403
ERR_CANNOTSENDTOCHAN = 404
ERR_UNKNOWNCOMMAND = 421
ERR_FILEERROR = 424
ERR_ERRONEUSNICKNAME = 432
Expand Down Expand Up @@ -297,20 +298,23 @@ async def send_slack_message(self, dest: bytes, msg: bytes, action: bool, re_sen

message = await self._addmagic(msg.decode('utf8'), dest_object)

if isinstance(dest_object, slack.User):
await self.sl_client.send_message_to_user(
dest_object,
message,
action,
re_send_to_irc,
)
else:
await self.sl_client.send_message(
dest_object,
message,
action,
re_send_to_irc
)
try:
if isinstance(dest_object, slack.User):
await self.sl_client.send_message_to_user(
dest_object,
message,
action,
re_send_to_irc,
)
else:
await self.sl_client.send_message(
dest_object,
message,
action,
re_send_to_irc
)
except Exception as e:
await self._sendreply(Replies.ERR_CANNOTSENDTOCHAN, f'Message sending failed: {e}')

async def _listhandler(self, cmd: bytes) -> None:
for c in await self.sl_client.channels(refresh=True):
Expand Down
31 changes: 12 additions & 19 deletions slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,25 +871,18 @@ async def send_message_to_user(self, user: User, msg: str, action: bool, re_send
# channel id is cached
channel_id = self._imcache[user.id]
else:
# Find the channel id
found = False
# Iterate over all the existing conversations
for i in await self.get_ims():
if i.user == user.id:
channel_id = i.id
found = True
break
# A conversation does not exist, create one
if not found:
r = await self.client.api_call(
"im.open",
return_im=True,
user=user.id,
)
response = self.tload(r, Response)
if not response.ok:
raise ResponseException(response.error)
channel_id = r['channel']['id']
# If the conversation is not in cache, reopen it
# It is faster than querying the list of conversations
# anyway
r = await self.client.api_call(
"conversations.open",
prevent_creation=False,
users=user.id,
)
response = self.tload(r, Response)
if not response.ok:
raise ResponseException(response.error)
channel_id = r['channel']['id']

self._imcache[user.id] = channel_id

Expand Down

0 comments on commit 4d10f4e

Please sign in to comment.