Class: Cinch::Plugins::Booru

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/booru.rb

Constant Summary collapse

@@selectors =
{
  dan: "http://danbooru.donmai.us/post?tags=%<tags>s",
  gel: "http://gelbooru.com/index.php?page=post&s=list&tags=%<tags>s",
  safe: "http://safebooru.com/index.php?page=post&s=list&tags=%<tags>s",
  kona: "http://konachan.com/post?tags=%<tags>s",
  oreno: "http://oreno.imouto.org/post?tags=%<tags>s&searchDefault=Search",
  :"4walled" => "http://4walled.org/search.php?tags=%<tags>s&board=&width_aspect=&searchstyle=larger&sfw=&search=search",
  :"3d" => "http://behoimi.org/post?tags=%<tags>s",
  e621: "http://e621.net/post?tags=%<tags>s",
  nano: "http://booru.nanochan.org/post/list/%<tags>s/1",
  rule34: "http://rule34.paheal.net/post/list/%<tags>s/1",
  katawa: "http://shimmie.katawa-shoujo.com/post/list/%<tags>s/1",
  monster: "http://monstergirlbooru.com/index.php?q=/post/list/%<tags>s/1",
  win: "http://winbooru.info/post/list/1/%<tags>s"
}

Instance Method Summary collapse

Instance Method Details

#execute_booru(m, selector = nil, tags = nil) ⇒ Object


51
52
53
54
55
56
57
58
# File 'lib/cinch/plugins/booru.rb', line 51

def execute_booru(m, selector = nil, tags = nil)
  url = generate_url(selector, tags)
  if url
    m.reply url, true
  else
    m.reply "You have used an invalid selector. Valid selectors: %<selectors>s." % {:selectors => generate_selector_list}, true
  end
end

#execute_boorulist(m) ⇒ Object


61
62
63
64
65
66
67
# File 'lib/cinch/plugins/booru.rb', line 61

def execute_boorulist(m)
  table_array = []
  @@selectors.each {|k,v|
    table_array << "#{k}\t#{get_base_url(v)}"
  }
  m.user.notice table_format(table_array, justify: [:right, :left], headers: ["selector","url"], gutter: 1)
end

#generate_selector_listObject


44
45
46
47
48
# File 'lib/cinch/plugins/booru.rb', line 44

def generate_selector_list
  selectors = [];
  @@selectors.each {|key, value| selectors << key.to_s; }
  selectors[0..-2].join(", ") + ", and " + selectors[-1]
end

#generate_url(selector, tags) ⇒ Object


38
39
40
41
42
# File 'lib/cinch/plugins/booru.rb', line 38

def generate_url(selector, tags)
  return if (selector.nil? || @@selectors[selector.to_sym].nil?);
  return get_base_url(@@selectors[selector.to_sym]) if (tags.nil? || tags.empty?);
  @@selectors[selector.to_sym] % {:tags => CGI::escape(tags)};
end

#get_base_url(src) ⇒ Object


30
31
32
# File 'lib/cinch/plugins/booru.rb', line 30

def get_base_url(src)
  src.match(%r{^(http://.+?/)})[0];
end

#list_to_tags(list) ⇒ Object


34
35
36
# File 'lib/cinch/plugins/booru.rb', line 34

def list_to_tags(list)
  list.split(", ").uniq.map {|e| e.gsub %r{\s}, "_"}.join(" ");
end