Module: LibDiscord::Formatter
- Defined in:
- lib/lib_discord/formatter.rb
Class Method Summary collapse
-
.channel(channel_id) ⇒ String
Format a channel ID for use in a message.
-
.guild_navigation(type) ⇒ String
Format a Guild navigation link for use in a message.
-
.role(role_id) ⇒ String
Format a role ID for use in a message.
-
.timestamp(unix_ts, style = nil) ⇒ String
Format a Unix timestamp for use in a message.
-
.user(user_id) ⇒ String
Format a user ID for use in a message.
Class Method Details
.channel(channel_id) ⇒ String
Format a channel ID for use in a message.
25 |
# File 'lib/lib_discord/formatter.rb', line 25 def self.channel(channel_id) = "<##{channel_id}>" |
.guild_navigation(type) ⇒ String
Format a Guild navigation link for use in a message.
86 87 88 89 90 91 92 93 |
# File 'lib/lib_discord/formatter.rb', line 86 def self.(type) accepted = MAPS.fetch(:GuildNavigationTypes).values unless accepted.include?(type) raise "Unknown guild navigation type: #{type}" end "<id:#{type}>" end |
.role(role_id) ⇒ String
Format a role ID for use in a message.
35 |
# File 'lib/lib_discord/formatter.rb', line 35 def self.role(role_id) = "<@&#{role_id}>" |
.timestamp(unix_ts, style = nil) ⇒ String
Format a Unix timestamp for use in a message.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lib_discord/formatter.rb', line 64 def self.(unix_ts, style = nil) ts = unix_ts.to_i return "<t:#{ts}>" unless style accepted = MAPS.fetch(:TimestampStyles).values unless accepted.include?(style) raise "Unknown timestamp style: #{style}" end "<t:#{ts}:#{style}>" end |
.user(user_id) ⇒ String
Format a user ID for use in a message.
15 |
# File 'lib/lib_discord/formatter.rb', line 15 def self.user(user_id) = "<@#{user_id}>" |