Module: Cinch::Helpers
Overview
The Helpers module contains a number of methods whose purpose is
to make writing plugins easier by hiding parts of the API. The
#Channel helper, for example, provides an easier way for turning
a String object into a Channel object than directly using
ChannelList: Compare Channel("#some_channel") with
bot.channel_list.find_ensured("#some_channel").
The Helpers module automatically gets included in all plugins.
Type casts (collapse)
-
- (Channel) Channel(channel)
Helper method for turning a String into a Channel object.
-
- (Target) Target(target)
Helper method for turning a String into a Target object.
-
- (Timer) Timer(interval, options = {}, &block)
-
- (User) User(user)
Helper method for turning a String into an User object.
Logging (collapse)
-
- debug(message)
Logs a debugging message.
-
- error(message)
Logs an error message.
-
- exception(e)
Logs an exception.
-
- fatal(message)
Logs a fatal message.
-
- incoming(message)
Logs an incoming IRC message.
-
- info(message)
Logs an info message.
-
- log(messages, event = :debug, level = event)
Logs a message.
-
- outgoing(message)
Logs an outgoing IRC message.
-
- rescue_exception
Use this method to automatically log exceptions to the loggers.
-
- warn(message)
Logs a warning message.
Formatting (collapse)
-
- (String) Format(*args)
(also: #Color)
Instance Method Details
- (Channel) Channel(channel)
Helper method for turning a String into a Channel object.
36 37 38 39 |
# File 'lib/cinch/helpers.rb', line 36 def Channel(channel) return channel if channel.is_a?(Channel) bot.channel_list.find_ensured(channel) end |
- debug(message)
Logs a debugging message.
139 140 141 |
# File 'lib/cinch/helpers.rb', line 139 def debug() log(, :debug) end |
- error(message)
Logs an error message.
144 145 146 |
# File 'lib/cinch/helpers.rb', line 144 def error() log(, :error) end |
- exception(e)
Logs an exception.
174 175 176 |
# File 'lib/cinch/helpers.rb', line 174 def exception(e) log(e., :exception, :error) end |
- fatal(message)
Logs a fatal message.
149 150 151 |
# File 'lib/cinch/helpers.rb', line 149 def fatal() log(, :fatal) end |
- (String) Format(*args) Also known as: Color
182 183 184 |
# File 'lib/cinch/helpers.rb', line 182 def Format(*args) Formatting.format(*args) end |
- incoming(message)
Logs an incoming IRC message.
164 165 166 |
# File 'lib/cinch/helpers.rb', line 164 def incoming() log(, :incoming, :log) end |
- info(message)
Logs an info message.
154 155 156 |
# File 'lib/cinch/helpers.rb', line 154 def info() log(, :info) end |
- log(messages, event = :debug, level = event)
Logs a message.
129 130 131 132 133 134 135 136 |
# File 'lib/cinch/helpers.rb', line 129 def log(, event = :debug, level = event) if self.is_a?(Cinch::Plugin) = Array().map {|m| "[#{self.class}] " + m } end @bot.loggers.log(, event, level) end |
- outgoing(message)
Logs an outgoing IRC message.
169 170 171 |
# File 'lib/cinch/helpers.rb', line 169 def outgoing() log(, :outgoing, :log) end |
- rescue_exception
This method returns an undefined value.
Use this method to automatically log exceptions to the loggers.
120 121 122 123 124 125 126 |
# File 'lib/cinch/helpers.rb', line 120 def rescue_exception begin yield rescue => e bot.loggers.exception(e) end end |
- (Target) Target(target)
Helper method for turning a String into a Target object.
22 23 24 25 |
# File 'lib/cinch/helpers.rb', line 22 def Target(target) return target if target.is_a?(Target) Target.new(target, bot) end |
- (Timer) Timer(interval, options = {}, &block)
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cinch/helpers.rb', line 92 def Timer(interval, = {}, &block) = {:method => :timer, :threaded => true, :interval => interval}.merge() block ||= self.method([:method]) timer = Cinch::Timer.new(bot, , &block) timer.start if self.respond_to?(:timers) timers << timer end timer end |
- (User) User(user)
Helper method for turning a String into an User object.
51 52 53 54 55 56 57 58 |
# File 'lib/cinch/helpers.rb', line 51 def User(user) return user if user.is_a?(User) if user == bot.nick bot else bot.user_list.find_ensured(user) end end |
- warn(message)
Logs a warning message.
159 160 161 |
# File 'lib/cinch/helpers.rb', line 159 def warn() log(, :warn) end |