Skip to content

Commit

Permalink
Merge pull request #7232 from Charcoal-SE/Mak-add-attribution-for-MS-…
Browse files Browse the repository at this point in the history
…forwarded-reply-comments

Add inline attribution for chat replies which are forwarded to MS as comments

autopull
  • Loading branch information
makyen committed Aug 21, 2022
2 parents 6a6281a + a384211 commit 28d6e8e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions chatcommunicate.py
Expand Up @@ -641,7 +641,14 @@ def dispatch_command(msg):
return func(*args, original_msg=msg, alias_used=command_name, quiet_action=quiet_action)


def dispatch_reply_command(msg, reply, full_cmd, comment=True):
def get_attribution_for_message(msg):
host_url = 'https://chat.{}/'.format(msg._client.host)
message_url = '{}transcript/message/{}'.format(host_url, msg.id)
user_url = '{}users/{}/{}'.format(host_url, msg.owner.id, msg.owner.name)
return ' – from a [chat message]({}) by [{}]({})'.format(message_url, msg.owner.name, user_url)


def dispatch_reply_command(message_replied_to, reply, full_cmd, comment=True):
command_parts = full_cmd.split(" ", 1)

if len(command_parts) == 2:
Expand All @@ -664,16 +671,16 @@ def dispatch_reply_command(msg, reply, full_cmd, comment=True):
assert min_arity == 1

if max_arity == 1:
return func(msg, original_msg=reply, alias_used=cmd, quiet_action=quiet_action)
return func(message_replied_to, original_msg=reply, alias_used=cmd, quiet_action=quiet_action)
elif max_arity == 2:
return func(msg, args, original_msg=reply, alias_used=cmd, quiet_action=quiet_action)
return func(message_replied_to, args, original_msg=reply, alias_used=cmd, quiet_action=quiet_action)
else:
args = args.split()
args.extend([None] * (max_arity - len(args)))

return func(msg, *args, original_msg=reply, alias_used=cmd, quiet_action=quiet_action)
return func(message_replied_to, *args, original_msg=reply, alias_used=cmd, quiet_action=quiet_action)
elif comment and is_privileged(reply.owner, reply.room):
post_data = get_report_data(msg)
post_data = get_report_data(message_replied_to)

if post_data:
expected_domains = (r'\b(?:erwaysoftware\.com|stackexchange\.com|stackoverflow\.com|serverfault\.com'
Expand All @@ -687,7 +694,8 @@ def dispatch_reply_command(msg, reply, full_cmd, comment=True):
# and doesn't have much text other than the reply, and contains at lesat one MS and/or SE domain.
# So, we don't want to forward it as a comment to MS.
return
Tasks.do(metasmoke.Metasmoke.post_auto_comment, full_cmd, reply.owner, url=post_data[0])
Tasks.do(metasmoke.Metasmoke.post_auto_comment, full_cmd + get_attribution_for_message(reply),
reply.owner, url=post_data[0])


def dispatch_shorthand_command(msg):
Expand Down

0 comments on commit 28d6e8e

Please sign in to comment.