-
Notifications
You must be signed in to change notification settings - Fork 84
/
plaintext.rb
68 lines (58 loc) · 1.96 KB
/
plaintext.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require_relative 'lib/daily_file_formatter'
class PlaintextFormatter < DailyFileFormatter
NAME = 'plaintext'
def format_message(dialog, message, output_stream)
date_str = Time.at(message['date']).strftime('[%s] ' % @options['date_format'])
from_name = get_full_name(message['from'])
line = case message['event'].downcase
when 'message'
fwd_from_name = get_full_name(message['fwd_from'])
if !fwd_from_name.empty?
from_name += ' (forwarded from %s)' % fwd_from_name
elsif message['reply_id']
from_name += ' (reply)'
# Possible impovement: find reply text
end
content = case
when message['text'].to_s != ''
message['text']
when message['media']
filename = message['media']['file']
media_ref = filename ? ': %s' % filename : ''
"#{message['media']['type']}#{media_ref}"
# Possible improvement: include more media-specific information
else nil
end
case
when content.nil?
nil
when dialog['type'] == 'channel'
content
when message['text'].to_s != ''
"#{from_name}: #{content}"
when message['media']
"#{from_name} sent #{content}"
else nil
end
when 'service'
user_name = get_full_name(message['action']['user'])
case message['action']['type'].downcase
when 'chat_add_user'
"#{from_name} added #{user_name}"
when 'chat_del_user'
"#{from_name} removed #{user_name}"
when 'chat_rename'
"#{from_name} changed group name to #{message['action']['title']}"
else nil
end
else nil
end
output_stream.puts(date_str + line + "\n") if line
end
def get_filename_for_date(dialog, date)
'%s_%s.log' % [
get_safe_name(dialog['print_name']),
date.strftime('%Y-%m-%d')
]
end
end