-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
빅챗 스프레드 시트 생성 후 GOGO 이모지를 누른 사람들을 일괄 등록하도록 기능 구현 (#89) #90
Open
hepheir
wants to merge
5
commits into
main
Choose a base branch
from
hepheir/issue89
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59e896a
refactor: `MemberManager`에 Singleton 패턴 적용
hepheir d9f50b3
refactor: `strip_multipline` -> `textwrap.dedent`
hepheir 84f9d50
feat: slack client에 특정 메시지에 달린 특정 이모지를 누를 사람 목록을 반환하는 메서드 추가
hepheir f226f26
feat: 빅챗 스프레드 시트 생성 후 GOGO 이모지를 누른 사람들을 일괄 등록하도록 기능 구현 (#89)
hepheir 09eff34
test: 빅챗 스프레드 시트 생성이 완료되기 전 GOGO 이모지를 누른 사람들이 누락되는지 검사하는 테스트 작성 (#89)
hepheir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from implementation.slack_client import Reaction | ||
from implementation.member_finder import MemberManager, MemberNotFound, MemberLackInfo | ||
|
||
|
||
class CreateBigchatSheet: | ||
def __init__(self, event, slack_client, gs_client): | ||
self.text = event["text"] | ||
|
@@ -9,15 +13,41 @@ def run(self): | |
if "새로운 빅챗" not in self.text: | ||
return False | ||
|
||
# TODO: REGEX로 더 깔끔하게 따올 수 있지 않을까? | ||
sheet_name = self.text.split("새로운 빅챗", maxsplit=1)[1].split("\n")[0].strip() | ||
if not sheet_name: | ||
self.slack_client.send_message(msg="시트 이름이 입력되지 않았어. 다시 입력해줘!", ts=self.ts) | ||
return False | ||
|
||
worksheet_id = self.gs_client.create_bigchat_sheet(sheet_name) | ||
sheet_url = self.gs_client.get_url(worksheet_id) | ||
|
||
self.slack_client.send_message( | ||
msg=f"새로운 빅챗, 등록 완료! <{sheet_url}|{sheet_name}> :google_spreadsheets:", | ||
ts=self.ts, | ||
) | ||
|
||
# 빅챗 시트가 생성되기 이전에 등록을 시도한(GOGO 이모지를 누른) | ||
# 인원들이 누락된 것에 대한 사후처리 | ||
channel = self.slack_client.get_channel() | ||
assert channel is not None | ||
reaction = self.slack_client.get_emoji( | ||
channel=channel, | ||
timestamp=self.ts, | ||
) | ||
if reaction is not None: | ||
reaction: Reaction | ||
for user in reaction.users: | ||
error_message = None | ||
try: | ||
member = MemberManager.get_instance().find(user) | ||
except MemberNotFound: | ||
error_message = f"<@{user}>, 네 정보를 찾지 못했어. 운영진에게 연락해줘!" | ||
except MemberLackInfo: | ||
error_message = f"<@{user}>, 네 정보에 누락된 값이 있어. 운영진에게 연락해줘!" | ||
else: | ||
self.gs_client.append_row(worksheet_id, member.transform_for_spreadsheet()) | ||
finally: | ||
if error_message: | ||
self.slack_client.send_message(msg=error_message, ts=self.ts) | ||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용자가 시트에 추가 된 뒤, 슬렉으로 사용자 정보를 보내주는 부분은 가져오지 못했네요. |
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,12 @@ class Emoji(BaseModel): | |
name: str | ||
|
||
|
||
class Reaction(BaseModel): | ||
name: str | ||
users: List[str] | ||
count: int | ||
|
||
|
||
class SlackClient: | ||
def __init__(self, say: Say, web_client: WebClient): | ||
self.say = say | ||
|
@@ -50,6 +56,10 @@ def _messages_to_members(messages, channel): | |
for msg in messages | ||
] | ||
|
||
def get_channel(self) -> Optional[str]: | ||
"""현재 메시지가 발송된 채널을 반환한다.""" | ||
return self.say.channel | ||
|
||
def get_replies( | ||
self, channel: str, thread_ts: str = None, ts: str = None | ||
) -> List[Message]: | ||
|
@@ -88,6 +98,27 @@ def add_emoji(self, channel, ts, emoji_name): | |
return | ||
raise ex | ||
|
||
def get_emoji(self, channel: str, ts: str, emoji_name: str) -> Optional[Reaction]: | ||
"""channel에 있는 ts 시간에 발송된 메시지에 사용자들이 남긴 반응 목록을 가져온다. | ||
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 하면 정확히 "ts 시간에" 남긴 반응만 가져오지 않나요? 밀리세컨드 단위로 찍히는 것 같아서요 |
||
|
||
해당 반응이 존재하지 않는다면 None을 반환한다.""" | ||
response = self.web_client.reactions_get( | ||
channel=channel, | ||
full=True, | ||
timestamp=ts, | ||
) | ||
assert response["ok"] | ||
assert response["type"] == "message" | ||
for reaction in response["message"]["reactions"]: | ||
if reaction["name"] == emoji_name: | ||
return Reaction( | ||
name=reaction["name"], | ||
users=reaction["users"], | ||
count=reaction["count"], | ||
) | ||
else: | ||
return None | ||
|
||
def remove_emoji(self, channel, ts, emoji_name): | ||
try: | ||
self.web_client.reactions_remove( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 라인을 지나간 직후에 생성되는 이모지는 어떻게 되는걸까요? 여전히 하나의 처리되지 못한 이모지로 남게 될까요?