Skip to content

Commit

Permalink
Page and chat reporting from web.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnfaraday committed Jul 11, 2019
1 parent 0aa4ab0 commit 258994f
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 38 deletions.
4 changes: 4 additions & 0 deletions engine/styles/ares.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ CHAT SCREEN
word-wrap: break-word;
}

.chat-report {
max-height: 200px;
overflow-y: scroll;
}
.timestamp-tip {
color: $faded-text-color;
font-style: italic;
Expand Down
7 changes: 7 additions & 0 deletions install/migrations/0038_beta56_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def migrate
config['channels']['announce_channel'] = 'Game'
config = DatabaseMigrator.write_config_file("channels.yml", config)

Channel.all.each do |c|
messages = c.messages
messages.each do |m|
m['id'] = SecureRandom.uuid
end
c.update(messages: messages)
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions plugins/channels/channels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def self.get_web_request_handler(request)
return LeaveChannelRequestHandler
when "muteChannel"
return MuteChannelRequestHandler
when "reportChat"
return ReportChatRequestHandler
end
end

Expand Down
8 changes: 5 additions & 3 deletions plugins/channels/commands/channel_recall_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ChannelRecallCmd
def parse_args
args = cmd.parse_args(ArgParser.arg1_equals_optional_arg2)
self.name = args.arg1
self.num_messages = integer_arg(args.arg2) || 25
self.num_messages = integer_arg(args.arg2) || 50
end

def required_args
Expand All @@ -17,7 +17,7 @@ def required_args

def check_number
return t('channels.invalid_recall_limit') if self.num_messages < 1
return t('channels.invalid_recall_limit') if self.num_messages > 25
return t('channels.invalid_recall_limit') if self.num_messages > 50
return nil
end

Expand All @@ -27,7 +27,9 @@ def handle
start_message = [ (total_messages - self.num_messages), 0 ].max
messages = channel.messages[start_message, total_messages]
list = messages.map { |m| " [#{OOCTime.local_long_timestr(enactor, m['timestamp'])}] #{channel.display_name} #{m['message']}"}
template = BorderedListTemplate.new list, t('channels.recall_history', :name => channel.display_name(false))
template = BorderedListTemplate.new list,
t('channels.recall_history', :name => channel.display_name(false)),
"%R%ld%R#{t('channels.more_on_portal')}"
client.emit template.render
end
end
Expand Down
11 changes: 1 addition & 10 deletions plugins/channels/commands/channel_report_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ def required_args

def handle
Channels.with_an_enabled_channel(self.name, client, enactor) do |channel|
messages = channel.messages.map { |m| " [#{OOCTime.local_long_timestr(enactor, m['timestamp'])}] #{channel.display_name} #{m['message']}"}.join("%R")

body = t('channels.channel_reported_body', :name => channel.name, :reporter => enactor_name)
body << self.reason
body << "%R-------%R"
body << messages

Jobs.create_job(Jobs.trouble_category, t('channels.channel_reported_title'), body, Game.master.system_character)
Channels.report_channel_abuse(enactor, channel, channel.messages.last(50), self.reason)
client.emit_success t('channels.channel_reported')


end
end
end
Expand Down
11 changes: 11 additions & 0 deletions plugins/channels/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,16 @@ def self.join_channel(channel, char, chan_alias = nil)
def self.active_channels(char)
char.channels.select { |c| !Channels.is_muted?(char, c) }
end

def self.report_channel_abuse(enactor, channel, messages, reason)
messages = messages.map { |m| " [#{OOCTime.local_long_timestr(enactor, m['timestamp'])}] #{channel.display_name} #{m['message']}"}.join("%R")

body = t('channels.channel_reported_body', :name => channel.name, :reporter => enactor.name)
body << reason
body << "%R-------%R"
body << messages

Jobs.create_job(Jobs.trouble_category, t('channels.channel_reported_title'), body, Game.master.system_character)
end
end
end
4 changes: 3 additions & 1 deletion plugins/channels/locales/locale_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ en:
char_added_to_channel: "You add %{char} to channel %{channel}."
char_removed_from_channel: "You remove %{char} from channel %{channel}."
force_added: "You have been added to channel %{channel} by %{char}."
force_removed: "You have been removed from channel %{channel} by %{char}."
force_removed: "You have been removed from channel %{channel} by %{char}."

more_on_portal: "Full channel history is available on the web portal."
2 changes: 1 addition & 1 deletion plugins/channels/public/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def display_name(include_markers = true)

def add_to_history(msg)
return if !self.recall_enabled
new_messages = (self.messages << { message: msg, timestamp: DateTime.now })
new_messages = (self.messages << { message: msg, timestamp: DateTime.now, id: SecureRandom.uuid })
if (new_messages.count > Channels.recall_buffer_size)
new_messages.shift
end
Expand Down
2 changes: 2 additions & 0 deletions plugins/channels/web/chat_request_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def handle(request)
}},
messages: Channels.is_on_channel?(enactor, c) ? c.messages.map { |m| {
message: Website.format_markdown_for_html(m['message']),
id: m['id'],
timestamp: OOCTime.local_long_timestr(enactor, m['timestamp']) }} : nil,
}
end
Expand All @@ -51,6 +52,7 @@ def handle(request)
}},
messages: t.sorted_messages.map { |p| {
message: Website.format_markdown_for_html(p.message),
id: p.id,
timestamp: OOCTime.local_long_timestr(enactor, p.created_at)
}}
}
Expand Down
29 changes: 29 additions & 0 deletions plugins/channels/web/report_chat_request_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module AresMUSH
module Channels
class ReportChatRequestHandler
def handle(request)
enactor = request.enactor
key = request.args[:key]
message_ids = request.args[:messages] || []
reason = request.args[:reason]

error = Website.check_login(request)
return error if error

channel = Channel.find_one_by_name(key)
if (!channel)
return { error: t('webportal.not_found') }
end

messages = channel.messages.select { |m| message_ids.include?(m['id']) }
Channels.report_channel_abuse(enactor, channel, messages, reason)


{
}
end
end
end
end


14 changes: 5 additions & 9 deletions plugins/page/commands/page_report_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def required_args
end

def handle
thread = Page.thread_for_names(self.names.concat(enactor_name).uniq)
self.names << enactor_name
thread = Page.thread_for_names(self.names.uniq)
if (!thread)
client.emit_failure t('page.invalid_thread')
return
Expand All @@ -31,14 +32,9 @@ def handle
return
end

template = PageReviewTemplate.new(enactor, thread, thread.sorted_messages[from_page..to_page], chars)
log = template.render

body = t('page.page_reported_body', :name => chars.map { |c| c.name }.join, :reporter => enactor_name)
body << self.reason
body << "%R"
body << log
Jobs.create_job(Jobs.trouble_category, t('page.page_reported_title'), body, Game.master.system_character)
messages = thread.sorted_messages[from_page..to_page]
Page.report_page_abuse(enactor, thread, messages, self.reason)
client.emit_success t('page.pages_reported')

end
end
Expand Down
11 changes: 5 additions & 6 deletions plugins/page/commands/page_review_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ def handle

Page.mark_thread_read(thread, enactor)

paginator = Paginator.paginate(thread.sorted_messages.reverse, cmd.page, 25)
if (paginator.out_of_bounds?)
client.emit_failure paginator.out_of_bounds_msg
return
end
messages = thread.sorted_messages
total_messages = messages.count
start_message = [ (total_messages - 50), 0 ].max
list = messages[start_message, total_messages]

template = PageReviewTemplate.new(enactor, thread, paginator)
template = PageReviewTemplate.new(enactor, thread, list, start_message)
client.emit template.render
end
end
Expand Down
10 changes: 10 additions & 0 deletions plugins/page/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ def self.has_unread_page_threads?(char)
return false if !char
char.page_threads.any? { |t| Page.is_thread_unread?(t, char) }
end

def self.report_page_abuse(enactor, thread, messages, reason)
log = messages.map { |m| " [#{OOCTime.local_long_timestr(enactor, m.created_at)}] #{m.message}"}.join("%R")

body = t('page.page_reported_body', :name => thread.title_without_viewer(enactor), :reporter => enactor.name)
body << reason
body << "%R"
body << log
Jobs.create_job(Jobs.trouble_category, t('page.page_reported_title'), body, Game.master.system_character)
end
end

end
5 changes: 3 additions & 2 deletions plugins/page/locales/locale_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ en:
page_review_index_title: "PM Conversations"
invalid_thread: "No PM conversation with those characters was found."
invalid_report_range: "Invalid page range. Specify numbers from the page/log entries, like 2-10."
log_reported: "Thank you. A report has been created using your page log with %{name} as evidence. The page log has been reset and you can report this person again if needed."
pages_reported: "Thank you. The conversation has been reported to the admins."
page_reported_title: "Pages Reported"
page_reported_body: "%{reporter} has reported an issue with the following pages from a conversation with %{name}.%R%RReason:%R"

Expand All @@ -40,4 +40,5 @@ en:
cant_page_just_yourself: "You can't page just yourself. Maybe try the 'echo' command instead."
cannot_continue_conversation: "You cannot continue this conversation because one of the characters no longer exists."

new_pm: "%{name} sent you a private message."
new_pm: "%{name} sent you a private message."
more_on_portal: "Full message history is available on the web portal."
2 changes: 2 additions & 0 deletions plugins/page/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def self.get_web_request_handler(request)
return SendPageRequestHandler
when "markPageThreadRead"
return MarkThreadReadRequestHandler
when "reportPage"
return ReportPageRequestHandler
end
end

Expand Down
8 changes: 5 additions & 3 deletions plugins/page/templates/page_review.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
%lh
%xh<%= t('page.page_review_title', :title => title) %>%xn

<% paginator.items.each_with_index do |p, i| %>
<%= left("#{paginator.starting_index + i + 1}. ", 4) %> [<%= time(p) %>] <%= p.message %>
<% messages.each_with_index do |p, i| %>
<%= left("#{starting_index + i + 1}. ", 4) %> [<%= time(p) %>] <%= p.message %>
<% end %>
<%= paginator.page_footer %>

%ld
<%= t('page.more_on_portal') %>
%lf
7 changes: 4 additions & 3 deletions plugins/page/templates/page_review_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ module AresMUSH
module Page
class PageReviewTemplate < ErbTemplateRenderer

attr_accessor :thread, :enactor, :paginator
attr_accessor :thread, :enactor, :messages, :starting_index

def initialize(enactor, thread, paginator)
def initialize(enactor, thread, messages, starting_index)
@enactor = enactor
@thread = thread
@paginator = paginator
@messages = messages
@starting_index = starting_index
super File.dirname(__FILE__) + "/page_review.erb"
end

Expand Down
28 changes: 28 additions & 0 deletions plugins/page/web/report_page_request_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module AresMUSH
module Page
class ReportPageRequestHandler
def handle(request)
enactor = request.enactor
key = request.args[:key]
message_ids = request.args[:messages] || []
reason = request.args[:reason]

error = Website.check_login(request)
return error if error

thread = PageThread[key]
if (!thread)
return { error: t('page.invalid_thread') }
end

messages = thread.page_messages.select { |m| message_ids.include?(m.id) }
Page.report_page_abuse(enactor, thread, messages, reason)

{
}
end
end
end
end


0 comments on commit 258994f

Please sign in to comment.