Module: Termtter::Client
- Defined in:
- lib/plugins/db.rb,
lib/plugins/l2.rb,
lib/plugins/me.rb,
lib/plugins/sl.rb,
lib/plugins/log.rb,
lib/plugins/say.rb,
lib/plugins/bomb.rb,
lib/plugins/cool.rb,
lib/plugins/clear.rb,
lib/plugins/curry.rb,
lib/plugins/devel.rb,
lib/plugins/en2ja.rb,
lib/plugins/grass.rb,
lib/plugins/group.rb,
lib/plugins/shell.rb,
lib/plugins/timer.rb,
lib/plugins/wassr.rb,
lib/plugins/whois.rb,
lib/plugins/yhara.rb,
lib/plugins/yonda.rb,
lib/plugins/filter.rb,
lib/plugins/hatebu.rb,
lib/plugins/ignore.rb,
lib/plugins/otsune.rb,
lib/plugins/otsune.rb,
lib/plugins/primes.rb,
lib/plugins/random.rb,
lib/plugins/reblog.rb,
lib/plugins/scrape.rb,
lib/plugins/trends.rb,
lib/plugins/history.rb,
lib/plugins/outputz.rb,
lib/plugins/reverse.rb,
lib/plugins/storage.rb,
lib/plugins/twitpic.rb,
lib/termtter/client.rb,
lib/plugins/addspace.rb,
lib/plugins/countter.rb,
lib/plugins/defaults.rb,
lib/plugins/open_url.rb,
lib/plugins/saykanji.rb,
lib/plugins/uri-open.rb,
lib/plugins/quicklook.rb,
lib/plugins/fib_filter.rb,
lib/plugins/multi_post.rb,
lib/plugins/search_url.rb,
lib/plugins/typable_id.rb,
lib/plugins/http_server.rb,
lib/plugins/multi_reply.rb,
lib/plugins/switch_user.rb,
lib/plugins/command_plus.rb,
lib/plugins/command_plus.rb,
lib/plugins/defaults/fib.rb,
lib/plugins/defaults/exec.rb,
lib/plugins/github-issues.rb,
lib/plugins/screen-notify.rb,
lib/plugins/system_status.rb,
lib/plugins/update_editor.rb,
lib/plugins/list_with_opts.rb,
lib/plugins/defaults/stdout.rb,
lib/plugins/defaults/retweet.rb,
lib/plugins/hatebu_and_update.rb,
lib/plugins/defaults/auto_reload.rb,
lib/plugins/defaults/standard_commands.rb,
lib/plugins/defaults/standard_completion.rb
Constant Summary collapse
- SEARCH_URI =
'search.twitter.com'
Class Attribute Summary collapse
-
.commands ⇒ Object
readonly
Returns the value of attribute commands.
-
.hooks ⇒ Object
readonly
Returns the value of attribute hooks.
Class Method Summary collapse
- .add_alias(from, to, confirm = true) ⇒ Object
- .add_command(name) ⇒ Object
- .add_filter(&b) ⇒ Object
- .add_task(*arg, &block) ⇒ Object
- .alias(name, value) ⇒ Object
- .alias_command(arg) ⇒ Object
- .apply_filters_for_hook(hook_name, statuses, event) ⇒ Object
- .call_commands(text) ⇒ Object
-
.call_hooks(point, *args) ⇒ Object
return last hook return value.
- .clear_command ⇒ Object
- .clear_filter ⇒ Object
- .command_exists?(text) ⇒ Boolean
- .confirm(message, default_yes = true, &block) ⇒ Object
- .data_to_typable_id(data) ⇒ Object
- .default_logger ⇒ Object
- .delete_command(arg) ⇒ Object
- .english?(text) ⇒ Boolean
- .exit ⇒ Object
- .find_commands(text) ⇒ Object
- .find_filter_candidates(a, b, filters) ⇒ Object
- .find_group_candidates(a, b) ⇒ Object
- .find_status_ids(text) ⇒ Object
- .find_users(text) ⇒ Object
- .formatted_help(helps) ⇒ Object
- .get_command(name) ⇒ Object
- .get_group_of(screen_name) ⇒ Object
- .get_hook(name) ⇒ Object
- .get_hooks(point) ⇒ Object
- .handle_error(e) ⇒ Object
- .init(&block) ⇒ Object
- .input_editor ⇒ Object
- .is_member?(status, group = nil) ⇒ Boolean
- .legacy_config_support ⇒ Object
- .load_config ⇒ Object
- .load_history ⇒ Object
- .logger ⇒ Object
- .move_legacy_config_file ⇒ Object
- .normalize_as_user_name(text) ⇒ Object
- .open_uri(uri) ⇒ Object
-
.output(statuses, event) ⇒ Object
statuses => [status, status, …] status => { :id => status id, :created_at => created time, :user_id => user id, :name => user name, :screen_name => user screen_name, :source => source, :reply_to => reply_to status id, :text => status, :original_data => original data, }.
- .pause ⇒ Object
-
.plug(name, options = {}) ⇒ Object
- plug
-
Name -> (Hash) -> IO () where NAME = String | Symbol | [NAME].
- .plugin_list ⇒ Object
- .post_retweet(s, comment = nil) ⇒ Object
- .public_storage ⇒ Object
- .register_command(arg, opts = {}, &block) ⇒ Object
- .register_hook(arg, opts = {}, &block) ⇒ Object
- .register_macro(name, macro, options = {}) ⇒ Object
- .remove_alias(target) ⇒ Object
- .resume ⇒ Object
- .run ⇒ Object
- .save_history ⇒ Object
- .scrape_group(group) ⇒ Object
- .scrape_members(members) ⇒ Object
- .setup_logger ⇒ Object
- .show_settings(conf, level = 0) ⇒ Object
- .typable_id?(id) ⇒ Boolean
- .typable_id_convert(id) ⇒ Object
- .typable_id_status(id) ⇒ Object
- .typable_id_to_data(id) ⇒ Object
- .update_with_user_and_id(text, username, id) ⇒ Object
- .wassr_update(text) ⇒ Object
Class Attribute Details
.commands ⇒ Object (readonly)
Returns the value of attribute commands.
29 30 31 |
# File 'lib/termtter/client.rb', line 29 def commands @commands end |
.hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
29 30 31 |
# File 'lib/termtter/client.rb', line 29 def hooks @hooks end |
Class Method Details
.add_alias(from, to, confirm = true) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/termtter/client.rb', line 133 def add_alias(from, to, confirm = true) if confirm raise 'Already exist' if @aliases[from] end @aliases[from] = to end |
.add_command(name) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/termtter/client.rb', line 107 def add_command(name) if block_given? command = Command.new(:name => name) yield command @commands[command.name] = command else raise ArgumentError, 'must be given block to set parameters' end end |
.add_filter(&b) ⇒ Object
53 54 55 56 |
# File 'lib/termtter/client.rb', line 53 def add_filter(&b) warn "add_filter method will be removed. Use Termtter::Client.register_hook(:name => ..., :point => :filter_for_output, :exec => ... ) instead." @filters << b end |
.add_task(*arg, &block) ⇒ Object
242 243 244 |
# File 'lib/termtter/client.rb', line 242 def add_task(*arg, &block) @task_manager.add_task(*arg, &block) end |
.alias(name, value) ⇒ Object
45 46 47 |
# File 'lib/termtter/client.rb', line 45 def alias(name, value) @aliases[name] = value end |
.alias_command(arg) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/plugins/command_plus.rb', line 12 def alias_command(arg) original, new = arg.split(/\s+/) if @commands[original.to_sym] @commands[new.to_sym] = @commands[original.to_sym].clone @commands[new.to_sym].name = new.to_sym @commands[new.to_sym].aliases = [] @commands[new.to_sym].help = '' puts "alias '#{original}' to '#{new}'." else raise "#{original} command is not found." end end |
.apply_filters_for_hook(hook_name, statuses, event) ⇒ Object
177 178 179 180 181 |
# File 'lib/termtter/client.rb', line 177 def apply_filters_for_hook(hook_name, statuses, event) get_hooks(hook_name).inject(statuses) {|s, hook| hook.call(s, event) } end |
.call_commands(text) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/termtter/client.rb', line 193 def call_commands(text) @task_manager.invoke_and_wait do # FIXME: This block can become Maybe Monad get_hooks("pre_command").each {|hook| break if text == nil # interrupt if hook returns nil text = hook.call(text) } return if text.empty? commands = find_commands(text) raise CommandNotFound, text if commands.empty? commands.each do |command| command_str, command_arg = Command.split_command_line(text) modified_arg = command_arg # FIXME: This block can become Maybe Monad get_hooks("modify_arg_for_#{command.name.to_s}").each {|hook| break if modified_arg == false # interrupt if hook return false modified_arg = hook.call(command_str, modified_arg) } begin call_hooks("pre_exec_#{command.name.to_s}", command, modified_arg) result = command.call(command_str, modified_arg, text) # exec command call_hooks("post_exec_#{command.name.to_s}", command_str, modified_arg, result) rescue CommandCanceled end end call_hooks("post_command", text) end end |
.call_hooks(point, *args) ⇒ Object
return last hook return value
184 185 186 187 188 189 190 191 |
# File 'lib/termtter/client.rb', line 184 def call_hooks(point, *args) result = nil get_hooks(point).each {|hook| break if result == false # interrupt if hook return false result = hook.call(*args) } result end |
.clear_command ⇒ Object
117 118 119 |
# File 'lib/termtter/client.rb', line 117 def clear_command @commands.clear end |
.clear_filter ⇒ Object
58 59 60 |
# File 'lib/termtter/client.rb', line 58 def clear_filter @filters.clear end |
.command_exists?(text) ⇒ Boolean
226 227 228 |
# File 'lib/termtter/client.rb', line 226 def command_exists?(text) @commands.values.any? {|command| command.match?(text) } end |
.confirm(message, default_yes = true, &block) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/termtter/client.rb', line 356 def confirm(, default_yes = true, &block) pause # TODO: TaskManager から呼ばれるならこれいらないなぁ result = # Boolean in duck typing if default_yes prompt = "\"#{}".strip + "\" [Y/n] " /^y?$/i =~ Readline.readline(prompt, false) else prompt = "\"#{}".strip + "\" [N/y] " /^n?$/i =~ Readline.readline(prompt, false) end if result && block block.call end result ensure resume # TODO: TaskManager から呼ばれるならこれいらないなぁ end |
.data_to_typable_id(data) ⇒ Object
47 48 49 |
# File 'lib/plugins/defaults/stdout.rb', line 47 def self.data_to_typable_id(data) id = config.plugins.stdout.typable_id_prefix + @typable_id_generator.next(data) end |
.default_logger ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/termtter/client.rb', line 288 def default_logger logger = Logger.new(STDOUT) logger.formatter = lambda {|severity, time, progname, | color = case severity when /^DEBUG/ 'blue' when /^INFO/ 'cyan' when /^WARN/ 'magenta' when /^ERROR/ 'red' when /^FATAL/ 'on_red' else 'white' end TermColor.parse("<#{color}>" + TermColor.escape("[#{severity}] #{}\n") + "</#{color}>") } logger end |
.delete_command(arg) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/plugins/command_plus.rb', line 4 def delete_command(arg) if @commands.delete(arg.to_sym) puts "#{arg} command is deleted." else raise "#{arg} command is not found." end end |
.english?(text) ⇒ Boolean
14 15 16 |
# File 'lib/plugins/en2ja.rb', line 14 def self.english?(text) /[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ text end |
.exit ⇒ Object
246 247 248 249 250 |
# File 'lib/termtter/client.rb', line 246 def exit puts 'finalizing...' call_hooks(:exit) @task_manager.kill end |
.find_commands(text) ⇒ Object
230 231 232 |
# File 'lib/termtter/client.rb', line 230 def find_commands(text) @commands.values.select {|command| command.match?(text) } end |
.find_filter_candidates(a, b, filters) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/plugins/filter.rb', line 49 def self.find_filter_candidates(a, b, filters) if a.empty? filters.to_a else filters.grep(/^#{Regexp.quote a}/i) end. map {|u| b % u } end |
.find_group_candidates(a, b) ⇒ Object
21 22 23 24 25 |
# File 'lib/plugins/group.rb', line 21 def self.find_group_candidates(a, b) config.plugins.group.groups.keys.map {|k| k.to_s}. grep(/^#{Regexp.quote a}/). map {|u| b % u } end |
.find_status_ids(text) ⇒ Object
517 518 519 |
# File 'lib/plugins/defaults/standard_commands.rb', line 517 def self.find_status_ids(text) public_storage[:status_ids].select {|id| /#{Regexp.quote(text)}/ =~ id.to_s} end |
.find_users(text) ⇒ Object
521 522 523 |
# File 'lib/plugins/defaults/standard_commands.rb', line 521 def self.find_users(text) public_storage[:users].select {|user| /^#{Regexp.quote(text)}/ =~ user} end |
.formatted_help(helps) ⇒ Object
358 359 360 361 362 363 364 365 |
# File 'lib/plugins/defaults/standard_commands.rb', line 358 def self.formatted_help(helps) helps = helps.sort_by {|help| help[0] } width = helps.map {|n, _| n.size }.max space = 3 helps.map {|name, desc| name.to_s.ljust(width + space) + desc.to_s }.join("\n") end |
.get_command(name) ⇒ Object
121 122 123 |
# File 'lib/termtter/client.rb', line 121 def get_command(name) @commands[name] end |
.get_group_of(screen_name) ⇒ Object
27 28 29 |
# File 'lib/plugins/group.rb', line 27 def self.get_group_of(screen_name) config.plugins.group.groups.select{ |k, v| v.include? screen_name}.map{|a| a.first} end |
.get_hook(name) ⇒ Object
79 80 81 |
# File 'lib/termtter/client.rb', line 79 def get_hook(name) @hooks[name] end |
.get_hooks(point) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/termtter/client.rb', line 83 def get_hooks(point) # TODO: sort by alphabet @hooks.values.select do |hook| hook.match?(point) end end |
.handle_error(e) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/termtter/client.rb', line 343 def handle_error(e) if logger logger.error("#{e.class.to_s}: #{e.}") logger.error(e.backtrace.join("\n")) if config.devel else raise e end get_hooks(:on_error).each {|hook| hook.call(e) } rescue Exception => e puts "Error: #{e}" puts e.backtrace.join("\n") end |
.init(&block) ⇒ Object
311 312 313 |
# File 'lib/termtter/client.rb', line 311 def init(&block) @init_block = block end |
.input_editor ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/plugins/github-issues.rb', line 180 def self.input_editor(body = nil) file = Tempfile.new('termtter') editor = config.plugins.github_issues.editor file.write body if body file.close system("#{editor} #{file.path}") result = file.open.read file.flush file.close(false) result end |
.is_member?(status, group = nil) ⇒ Boolean
58 59 60 61 62 63 64 |
# File 'lib/plugins/group.rb', line 58 def self.is_member?(status, group = nil) if group config.plugins.group.groups[group].include? status.user.screen_name else config.plugins.group.groups.values.flatten.include? status.user.screen_name end end |
.legacy_config_support ⇒ Object
261 262 263 264 265 266 267 268 |
# File 'lib/termtter/client.rb', line 261 def legacy_config_support case File.ftype(File.('~/.termtter')) when 'directory' # nop when 'file' move_legacy_config_file end end |
.load_config ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/termtter/client.rb', line 252 def load_config legacy_config_support() if File.exist? Termtter::CONF_DIR unless File.exist?(Termtter::CONF_FILE) require 'termtter/config_setup' ConfigSetup.run end load Termtter::CONF_FILE end |
.load_history ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/plugins/history.rb', line 17 def self.load_history filename = File.(config.plugins.history.filename) keys = config.plugins.history.keys if File.exist?(filename) begin history = Marshal.load Zlib::Inflate.inflate(File.read(filename)) end if history keys.each do |key| public_storage[key] = history[key] if history[key] end Readline::HISTORY.push *history[:history] if history[:history] puts "history loaded(#{File.size(filename)/1000}kb)" end end end |
.logger ⇒ Object
280 281 282 |
# File 'lib/termtter/client.rb', line 280 def logger @logger end |
.move_legacy_config_file ⇒ Object
270 271 272 273 274 275 276 277 278 |
# File 'lib/termtter/client.rb', line 270 def move_legacy_config_file FileUtils.mv( Termtter::CONF_DIR, File.('~/.termtter___')) Dir.mkdir(Termtter::CONF_DIR) FileUtils.mv( File.('~/.termtter___'), Termtter::CONF_FILE) end |
.normalize_as_user_name(text) ⇒ Object
513 514 515 |
# File 'lib/plugins/defaults/standard_commands.rb', line 513 def self.normalize_as_user_name(text) text.strip.sub(/^@/, '') end |
.open_uri(uri) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/plugins/open_url.rb', line 6 def self.open_uri(uri) unless config.plugins.open_url.browser.empty? system config.plugins.open_url.browser, uri else case RUBY_PLATFORM when /linux/ system 'firefox', uri when /mswin(?!ce)|mingw|bccwin/ system 'explorer', uri else system 'open', uri end end end |
.output(statuses, event) ⇒ Object
statuses => [status, status, …] status => {
:id => status id,
:created_at => created time,
:user_id => user id,
:name => user name,
:screen_name => user screen_name,
:source => source,
:reply_to => reply_to status id,
:text => status,
:original_data => original data,
}
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/termtter/client.rb', line 156 def output(statuses, event) return if statuses.nil? || statuses.empty? statuses = statuses.sort_by(&:id) call_hooks(:pre_filter, statuses, event) filtered = apply_filters_for_hook(:filter_for_output, statuses.map(&:dup), event) @filters.each do |f| # TODO: code for compatibility. delete someday. filtered = f.call(filtered, event) end call_hooks(:post_filter, filtered, event) get_hooks(:output).each do |hook| hook.call( apply_filters_for_hook("filter_for_#{hook.name}", filtered, event), event ) end end |
.pause ⇒ Object
234 235 236 |
# File 'lib/termtter/client.rb', line 234 def pause @task_manager.pause end |
.plug(name, options = {}) ⇒ Object
- plug
-
Name -> (Hash) -> IO () where NAME = String | Symbol | [NAME]
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/termtter/client.rb', line 32 def plug(name, = {}) if Array === name # Obviously `name.respond_to?(:each)` is better, but for 1.8.6 compatibility we cannot. name.each {|i| plug(i, ) } return end .each do |key, value| config.plugins.__refer__(name.gsub(/-/, '_').to_sym).__assign__(key.to_sym, value) end load "plugins/#{name}.rb" rescue Exception => e Termtter::Client.handle_error(e) end |
.plugin_list ⇒ Object
388 389 390 391 392 |
# File 'lib/plugins/defaults/standard_commands.rb', line 388 def self.plugin_list (Dir["#{File.dirname(__FILE__)}/../*.rb"] + Dir["#{Termtter::CONF_DIR}/plugins/*.rb"]). map{|f| File.basename(f).sub(/\.rb$/, '')}. sort end |
.post_retweet(s, comment = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/plugins/defaults/retweet.rb', line 6 def self.post_retweet(s, comment = nil) if s.user.protected && !confirm("#{s.user.screen_name} is protected! Are you sure?", false) return end comment += ' ' unless comment.nil? text = ERB.new(config.plugins.retweet.format).result(binding) Termtter::API.twitter.update(text) puts "=> #{text}" end |
.public_storage ⇒ Object
49 50 51 |
# File 'lib/termtter/client.rb', line 49 def public_storage @public_storage ||= {} end |
.register_command(arg, opts = {}, &block) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/termtter/client.rb', line 90 def register_command(arg, opts = {}, &block) command = case arg when Command arg when Hash Command.new(arg) when String, Symbol = { :name => arg } .merge!(opts) [:exec_proc] = block Command.new() else raise ArgumentError, 'must be given Termtter::Command, Hash or String(Symbol) with block' end @commands[command.name] = command end |
.register_hook(arg, opts = {}, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/termtter/client.rb', line 62 def register_hook(arg, opts = {}, &block) hook = case arg when Hook arg when Hash Hook.new(arg) when String, Symbol = { :name => arg } .merge!(opts) [:exec_proc] = block Hook.new() else raise ArgumentError, 'must be given Termtter::Hook, Hash, String or Symbol' end @hooks[hook.name] = hook end |
.register_macro(name, macro, options = {}) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/termtter/client.rb', line 125 def register_macro(name, macro, = {}) command = { :name => name.to_sym, :exec_proc => lambda {|arg| call_commands(macro % arg)} }.merge() register_command(command) end |
.remove_alias(target) ⇒ Object
140 141 142 |
# File 'lib/termtter/client.rb', line 140 def remove_alias(target) @aliases.delete target end |
.resume ⇒ Object
238 239 240 |
# File 'lib/termtter/client.rb', line 238 def resume @task_manager.resume end |
.run ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/termtter/client.rb', line 315 def run load_config() Termtter::API.setup() setup_logger() @init_block.call(self) if @init_block plug 'defaults' plug 'devel' if config.devel plug config.system.load_plugins config.system.eval_scripts.each do |script| begin eval script rescue Exception => e handle_error(e) end end config.system.run_commands.each {|cmd| call_commands(cmd) } unless config.system.cmd_mode @task_manager.run() call_hooks(:initialize) call_hooks(:launched) end end |
.save_history ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/plugins/history.rb', line 35 def self.save_history filename = File.(config.plugins.history.filename) keys = config.plugins.history.keys history = { } keys.each do |key| history[key] = public_storage[key] end max_of_history = config.plugins.history.max_of_history history[:history] = Readline::HISTORY.to_a.reverse.uniq.reverse if history[:history].size > max_of_history history[:history] = history[:history][-max_of_history..-1] end File.open(filename, 'w') do |f| f.write Zlib::Deflate.deflate(Marshal.dump(history)) end puts "history saved(#{File.size(filename)/1000}kb)" end |
.scrape_group(group) ⇒ Object
14 15 16 17 |
# File 'lib/plugins/scrape.rb', line 14 def self.scrape_group(group) members = config.plugins.group.groups[group] || [] scrape_members(members) end |
.scrape_members(members) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/plugins/scrape.rb', line 5 def self.scrape_members(members) statuses = [] members.each_with_index do |member, index| puts "member #{index+1}/#{members.size} #{member}" statuses += Termtter::API.twitter.user_timeline(member) end statuses end |
.setup_logger ⇒ Object
284 285 286 |
# File 'lib/termtter/client.rb', line 284 def setup_logger @logger = config.logger || default_logger end |
.show_settings(conf, level = 0) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/plugins/defaults/standard_commands.rb', line 279 def self.show_settings(conf, level = 0) conf.__values__.each do |k, v| if v.instance_of? Termtter::Config puts "#{k}:" show_settings v, level + 1 else print ' ' * level puts "#{k} = #{v.nil? ? 'nil' : v.inspect}" end end end |
.typable_id?(id) ⇒ Boolean
58 59 60 61 62 63 64 |
# File 'lib/plugins/typable_id.rb', line 58 def self.typable_id?(id) if public_storage[:typable_id].assoc(id.to_s) return true else return false end end |
.typable_id_convert(id) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/plugins/typable_id.rb', line 39 def self.typable_id_convert(id) if current_id = public_storage[:typable_id].assoc(id.to_s) return current_id[1] elsif current_id = public_storage[:typable_id].rassoc(id.to_s) return current_id[0] else return nil end end |
.typable_id_status(id) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/plugins/typable_id.rb', line 49 def self.typable_id_status(id) if current_id = (public_storage[:typable_id].assoc(id.to_s)||\ public_storage[:typable_id].rassoc(id.to_s)) return current_id[2] else return nil end end |
.typable_id_to_data(id) ⇒ Object
51 52 53 |
# File 'lib/plugins/defaults/stdout.rb', line 51 def self.typable_id_to_data(id) @typable_id_generator.get(id) end |
.update_with_user_and_id(text, username, id) ⇒ Object
507 508 509 510 511 |
# File 'lib/plugins/defaults/standard_commands.rb', line 507 def self.update_with_user_and_id(text, username, id) text = "@#{username} #{text}" result = Termtter::API.twitter.update(text, {'in_reply_to_status_id' => id}) puts "replied => #{result.text}" end |
.wassr_update(text) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/plugins/multi_post.rb', line 5 def wassr_update(text) Net::HTTP.version_1_2 req = Net::HTTP::Post.new("/statuses/update.json?") req.basic_auth config.plugins.wassr.username, config.plugins.wassr.password Net::HTTP.start('api.wassr.jp', 80) do |http| res = http.request(req, "status=#{URI.escape(text)}&source=Termtter") end end |