module YtReport
Constants
- IRC_CTRL
- IRC_RESET
- STYLE_BANNER
- STYLE_CHIP
- STYLE_MUTED
- STYLE_SEP
- STYLE_TITLE
Public Class Methods
Source
# File lib/yt_report.rb, line 13 def self.irc_color(fg, bg = nil) bg ? "#{IRC_CTRL}#{fg},#{bg}" : "#{IRC_CTRL}#{fg}" end
Public Instance Methods
Source
# File lib/yt_report.rb, line 25 def decorate(value, style: STYLE_CHIP) return nil if value.nil? || value.to_s.strip.empty? "#{style}#{value}#{IRC_RESET}" end
Source
# File lib/yt_report.rb, line 98 def format_auth_pending_reply IrcReply.card( tag: "YT", title: "auth pending", body_lines: ["Authorization not complete yet — finish in your browser, then !yt auth status."], footer_parts: ["youtube.com"] ) end
Source
# File lib/yt_report.rb, line 116 def format_auth_setup_reply IrcReply.card( tag: "YT", title: "setup", body_lines: YtConfig.signup_steps, footer_parts: ["manual Gmail signup", "youtube.com"] ) end
Source
# File lib/yt_report.rb, line 85 def format_auth_start_reply(device) IrcReply.card( tag: "YT", title: "link account", body_lines: [ "Visit #{device[:verification_url]} and enter code #{device[:user_code]}.", "Then PM !yt auth status to finish linking this bot persona.", "Gmail signup is manual — see !yt auth help for setup steps." ], footer_parts: ["device flow", "expires #{device[:expires_in]}s"] ) end
Source
# File lib/yt_report.rb, line 107 def format_auth_success_reply(account) IrcReply.card( tag: "YT", title: "linked", body_lines: ["YouTube channel #{account['channel_title']} linked to this bot persona."], footer_parts: [account["channel_id"], "youtube.com"] ) end
Source
# File lib/yt_report.rb, line 193 def format_error(message) IrcReply.error(tag: "YT", message: message) end
Source
# File lib/yt_report.rb, line 72 def format_help_reply IrcReply.card( tag: "YT", title: "commands", body_lines: [ "Passive: post a YouTube link for video info.", "PM: !yt auth | auth status | logout", "Channel: !yt whoami | playlist list | show | create | delete | add | rem" ], footer_parts: ["youtube.com"] ) end
Source
# File lib/yt_report.rb, line 143 def format_logout_reply IrcReply.card( tag: "YT", title: "logged out", body_lines: ["YouTube account unlinked from this bot persona."], footer_parts: ["youtube.com"] ) end
Source
# File lib/yt_report.rb, line 35 def format_message(info) description = info[:description].to_s parts = [] parts << decorate(info[:title], style: STYLE_TITLE) channel = info[:channel].to_s.strip parts << "#{STYLE_MUTED}by#{IRC_RESET} #{decorate(channel)}" unless channel.empty? duration = YtLookup.format_duration(info[:duration], info[:duration_text]) parts << decorate(duration) unless duration.empty? quality = info[:quality].to_s.strip parts << decorate(quality) unless quality.empty? published = YtLookup.format_published_date(info[:published]) parts << decorate(published) unless published.empty? views = YtLookup.format_views(info[:views]) parts << decorate(views) unless views == "0 views" likes = YtLookup.format_likes(info[:likes]) parts << decorate(likes) unless likes.empty? subscribers = YtLookup.format_subscribers(info[:subscribers]) parts << decorate(subscribers) unless subscribers.empty? time_ago = YtLookup.format_time_ago(info[:published]) parts << decorate(time_ago) unless time_ago.empty? message = parts.compact.join(" #{separator} ") unless description.empty? message = "#{message} #{STYLE_MUTED}—#{IRC_RESET} #{STYLE_MUTED}#{description}#{IRC_RESET}" end message end
Source
# File lib/yt_report.rb, line 184 def format_playlist_action_reply(action, detail) IrcReply.card( tag: "YT", title: action, body_lines: [detail], footer_parts: ["youtube.com"] ) end
Source
# File lib/yt_report.rb, line 152 def format_playlist_list_reply(playlists) lines = playlists.map do |playlist| privacy = playlist[:privacy].to_s label = privacy.empty? ? playlist[:title] : "#{playlist[:title]} (#{privacy})" "#{playlist[:id]} — #{label}" end lines = ["No playlists yet."] if lines.empty? IrcReply.card( tag: "YT", title: "playlists", body_lines: lines, footer_parts: ["#{playlists.size} total", "youtube.com"] ) end
Source
# File lib/yt_report.rb, line 168 def format_playlist_show_reply(playlist, items) title = playlist[:title].to_s lines = items.each_with_index.map do |item, index| pos = index + 1 "#{pos}. #{item[:title]} — #{item[:video_id]}" end lines = ["Playlist is empty."] if lines.empty? IrcReply.card( tag: "YT", title: title, body_lines: lines.first(6), footer_parts: [playlist[:id], "#{items.size} videos", "youtube.com"] ) end
Source
# File lib/yt_report.rb, line 197 def format_recent(channel_url:, body_line:) parts = [] url = channel_url.to_s.strip parts << decorate(url, style: STYLE_BANNER) unless url.empty? body = body_line.to_s parts << body unless body.empty? parts.join(" #{separator} ") end
Source
# File lib/yt_report.rb, line 125 def format_whoami_reply(account) unless account return IrcReply.card( tag: "YT", title: "not linked", body_lines: ["No YouTube account linked — PM !yt auth to start device flow."], footer_parts: ["youtube.com"] ) end IrcReply.card( tag: "YT", title: account["channel_title"].to_s, body_lines: ["YouTube channel linked to this bot persona."], footer_parts: [account["channel_id"], "youtube.com"] ) end