Class: MijDiscord::Cache::ChannelCache
- Inherits:
-
Object
- Object
- MijDiscord::Cache::ChannelCache
- Defined in:
- lib/mij-discord/cache.rb
Constant Summary collapse
- MAX_MESSAGES =
200
Instance Method Summary collapse
- #get_message(key, local: false) ⇒ Object
-
#initialize(channel, bot, max_messages: MAX_MESSAGES) ⇒ ChannelCache
constructor
A new instance of ChannelCache.
- #put_message(data, update: false) ⇒ Object
- #remove_message(key) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(channel, bot, max_messages: MAX_MESSAGES) ⇒ ChannelCache
Returns a new instance of ChannelCache.
253 254 255 256 257 258 |
# File 'lib/mij-discord/cache.rb', line 253 def initialize(channel, bot, max_messages: MAX_MESSAGES) @channel, @bot = channel, bot = reset end |
Instance Method Details
#get_message(key, local: false) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/mij-discord/cache.rb', line 264 def (key, local: false) id = key&.to_id return [id] if .has_key?(id) return nil if local begin response = MijDiscord::Core::API::Channel.(@bot.auth, @channel.id, key) rescue RestClient::ResourceNotFound return nil end = .store(id, MijDiscord::Data::Message.new(JSON.parse(response), @bot)) .shift while .length > end |
#put_message(data, update: false) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/mij-discord/cache.rb', line 281 def (data, update: false) id = data['id'].to_i if .has_key?(id) [id].update_data(data) if update return [id] end = .store(id, MijDiscord::Data::Message.new(data, @bot)) .shift while .length > end |
#remove_message(key) ⇒ Object
294 295 296 |
# File 'lib/mij-discord/cache.rb', line 294 def (key) .delete(key&.to_id) end |
#reset ⇒ Object
260 261 262 |
# File 'lib/mij-discord/cache.rb', line 260 def reset = {} end |