Class: Cinch::Plugins::Bgg
- Inherits:
-
Object
- Object
- Cinch::Plugins::Bgg
- Includes:
- Cinch::Plugin
- Defined in:
- lib/cinch/plugins/bgg.rb
Constant Summary collapse
- USERS_FILE =
"users_list"
- USERS_SUBDIR =
"users"
- GAMES_SUBDIR =
"games"
Instance Method Summary collapse
- #bgg(m, title) ⇒ Object
- #bggactualuser(m, nick) ⇒ Object
- #bggself(m) ⇒ Object
- #bgguser(m, nick) ⇒ Object
-
#initialize(*args) ⇒ Bgg
constructor
A new instance of Bgg.
- #link_to_bgg(m, username) ⇒ Object
- #show_user_details(m, user) ⇒ Object
- #who_has_game(m, title) ⇒ Object
- #who_is_trading_game(m, title) ⇒ Object
- #who_played_game(m, title) ⇒ Object
- #who_rated_game(m, title) ⇒ Object
- #who_wants_game(m, title) ⇒ Object
- #who_what_a_game(m, title, action, string, with_number_info = nil) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Bgg
Returns a new instance of Bgg.
28 29 30 31 32 33 |
# File 'lib/cinch/plugins/bgg.rb', line 28 def initialize(*args) super @data_dir = config[:data_dir] @community = load_community end |
Instance Method Details
#bgg(m, title) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/cinch/plugins/bgg.rb', line 35 def bgg(m, title) game = search_bgg(m, title) unless game.nil? m.reply "#{m.user.nick}: #{game.name} (#{game.year}) - #{game.} - Rank: #{game.game_rank} - Designer: #{game.designers.join(", ")} - Mechanics: #{game.mechanics.join(", ")} - " << "http://boardgamegeek.com/boardgame/#{game.id}" end end |
#bggactualuser(m, nick) ⇒ Object
59 60 61 62 |
# File 'lib/cinch/plugins/bgg.rb', line 59 def bggactualuser(m, nick) user = search_for_user(m, nick) self.show_user_details(m, user) end |
#bggself(m) ⇒ Object
55 56 57 |
# File 'lib/cinch/plugins/bgg.rb', line 55 def bggself(m) self.bgguser(m, m.user.nick) end |
#bgguser(m, nick) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cinch/plugins/bgg.rb', line 43 def bgguser(m, nick) unless nick.start_with?("-u ") if self.in_community?(nick) name = self.find_bgg_by_irc(nick) user = search_for_user(m, name) self.show_user_details(m, user) else m.reply "There's no \"#{nick}\" in the community. To link yourself and join the community, \"!link_bgg bgg_username\". To search by actual bgg username, \"!bgguser -u bgg_username\".", true end end end |
#link_to_bgg(m, username) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/cinch/plugins/bgg.rb', line 69 def link_to_bgg(m, username) @community[m.user.nick] = username File.open("#{@data_dir}#{USERS_FILE}", 'w') do |file| @community.each do |irc_nick, bgg_name| file.write("#{irc_nick},#{bgg_name}\n") end end m.reply "You are now added to the community!", true end |
#show_user_details(m, user) ⇒ Object
64 65 66 67 |
# File 'lib/cinch/plugins/bgg.rb', line 64 def show_user_details(m, user) top5 = (user.top_games.empty? ? "" : "- Top 5: #{user.top_games.first(5).join(", ")} ") m.reply "#{user.name} - Collection: #{user.owned.size} #{top5}- http://boardgamegeek.com/user/#{user.name}", true end |
#who_has_game(m, title) ⇒ Object
79 80 81 |
# File 'lib/cinch/plugins/bgg.rb', line 79 def who_has_game(m, title) self.who_what_a_game(m, title, :owned, "Owning") end |
#who_is_trading_game(m, title) ⇒ Object
83 84 85 |
# File 'lib/cinch/plugins/bgg.rb', line 83 def who_is_trading_game(m, title) self.who_what_a_game(m, title, :trading, "Trading") end |
#who_played_game(m, title) ⇒ Object
95 96 97 |
# File 'lib/cinch/plugins/bgg.rb', line 95 def who_played_game(m, title) self.who_what_a_game(m, title, :played, "Played", "plays") end |
#who_rated_game(m, title) ⇒ Object
91 92 93 |
# File 'lib/cinch/plugins/bgg.rb', line 91 def who_rated_game(m, title) self.who_what_a_game(m, title, :rated, "Rated", "rating") end |
#who_wants_game(m, title) ⇒ Object
87 88 89 |
# File 'lib/cinch/plugins/bgg.rb', line 87 def who_wants_game(m, title) self.who_what_a_game(m, title, :wanted, "Wants") end |
#who_what_a_game(m, title, action, string, with_number_info = nil) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cinch/plugins/bgg.rb', line 99 def who_what_a_game(m, title, action, string, with_number_info = nil) game = search_bgg(m, title) unless game.nil? community = @community.dup community.each{ |irc, bgg| community[irc] = search_for_user(m, bgg, { :id => game.id, :use_cache => true }) } community.keep_if{ |irc, user| user.send(action).include? game.id.to_s } user_info = [] community.each do |irc, user| number_info = with_number_info.nil? ? "" : " (#{user.send(action)[game.id.to_s][with_number_info].to_s})" user_info << "#{self.dehighlight_nick(irc)}#{number_info}" end m.reply "#{string} \"#{game.name}\": #{user_info.join(", ")}", true end end |