botemon 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWM2NTA2NzA1OWZiMzYwMzZlNDNhMjEwZmY5MjcwYjBkYmM2MjM4OQ==
4
+ ODk1NDM4YzcwYWRkZWVmNzFmNTg0MmRhNTc1MjZkNWE4Njc5YmM5ZA==
5
5
  data.tar.gz: !binary |-
6
- MDhkMmE0ZjVlY2RlNGZhZDRhMDU4MWU2MzcxOTM2M2FlODQ4NTViYg==
6
+ MTg4NDUxZmFjNzg2NGY4ZmViNWMyMjEyODYyY2Q1MDYzYWFjZWQ2ZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NmQyNzk0MjFiZDFjZTcwYWY3ZTY2MjhhZDU1NWYzNzMzZTNkOWU0ODQ2MDc5
10
- ZjdkMmI4ZDE1YTA3MzI4MmU3YTliMWYyNmU0ZmU1NTgyODJlNzVlMThhYjNk
11
- NzVmMGI0YjUwNTg0YzQ2YzgxNTJiNDY5MzRmMWZkMzlkZTM3NGI=
9
+ ZTZkYjkwOGRlYjZhNDM4MzU5MTQ1N2ExODk5MDQ0YTIyNGJkZWJlZjI2MzVi
10
+ OGUwNDc5MGExZDZmYTM1ZWIwMDYxNWFkYmJkZTNjYmQzOGIzYjJmOTM0M2Y3
11
+ ZjE3ZDAyYmVmMjkyNmFiNzNlMDBmNGYzYWE5NmQ5YmQ1MDkyODg=
12
12
  data.tar.gz: !binary |-
13
- ZWFjODljNTlhNDRkOWIyNWI0MzUxMTU1M2NhNDRiOGY0MWFlYWZiNmRjNjRl
14
- YTQ3OTdhNTJhYzZlODQ0ZGYzNDAwZmQ3MjUwMzQ4NDZjZDhlZTEyMmZiZjA3
15
- NTJmZjg4NTI0OGQyOTVjZWNmM2RkMGI4MTBhZjI1ODI5ZDM3NzI=
13
+ NjliN2Y0MjQyN2FlZWRkYjNmOTU0Mjc5ZTAyZmU0YzU4NTYyNjU2NjFiNjlm
14
+ ZDc3MzgxZjE0NDBhNDRjNzQ4YmEwMGQ1NzMwZTkwYzc0ODgwYjk3MzdiMDUy
15
+ NGVmZjE1MzFiMWYwYjAyYmQzZWEzYjI3MGYzNDhkYjQzMTdmNDU=
data/bin/botemon CHANGED
@@ -39,6 +39,7 @@ Cinch::Bot.new {
39
39
  @pokemon_trivia = nil
40
40
  @players = []
41
41
  @trivia_owner = ''
42
+ @trivia_wrong = 0
42
43
  end
43
44
 
44
45
  on :message, /^pkmn (.+)/ do |m, name|
@@ -74,26 +75,10 @@ Cinch::Bot.new {
74
75
  else
75
76
  @pokemon_trivia = Pokedex.get Pokedex.id2name(Random.new.rand(1..649)), @storage
76
77
  @trivia_owner = m.user.nick
78
+ @trivia_wrong = 0
77
79
 
78
80
  m.reply @pokemon_trivia.clues.split("\n").map { |l| Format(:red, l) }.join("\n")
79
- m.reply Format(:red, "You have 30 seconds. Try to say which Pokémon is this!")
80
-
81
- Timer(60) {
82
- if @pokemon_trivia != nil
83
- m.reply Format(:red, "Time expired. The secret Pokémon is #{@pokemon_trivia.name}!")
84
- @pokemon_trivia = nil
85
- end
86
- }
87
- end
88
- end
89
-
90
- on :message, /^pkstop$/ do |m|
91
- if @pokemon_trivia != nil && (m.user.nick == 'mirkosp' || m.user.nick == 'RoxasShadowRS' || m.user.nick == @trivia_owner)
92
- @pokemon_trivia = nil
93
- @trivia_owner = ''
94
- m.reply Format(:red, "Game aborted by #{m.user.nick}.")
95
- else
96
- m.reply Format(:red, "Only ops can stop the game. #{m.user.nick} GTFO.")
81
+ m.reply Format(:red, "You have 3 chances to try to say which Pokémon is this!")
97
82
  end
98
83
  end
99
84
 
@@ -103,8 +88,26 @@ Cinch::Bot.new {
103
88
  elsif pokemon.downcase == @pokemon_trivia.name.downcase
104
89
  m.reply Format(:red, "Right, #{m.user.nick} won!")
105
90
  @pokemon_trivia = nil
91
+ @trivia_wrong = 0
106
92
  else
107
93
  m.reply Format(:red, "Nope, #{m.user.nick} was wrong.")
94
+ @trivia_wrong += 1
95
+ if @trivia_wrong >= 3
96
+ m.reply Format(:red, "Time expired. The secret Pokémon is #{@pokemon_trivia.name}!")
97
+ @pokemon_trivia = nil
98
+ @trivia_wrong = 0
99
+ end
100
+ end
101
+ end
102
+
103
+ on :message, /^pkstop$/ do |m|
104
+ if @pokemon_trivia != nil && (m.user.nick == 'mirkosp' || m.user.nick == 'RoxasShadowRS' || m.user.nick == @trivia_owner)
105
+ @pokemon_trivia = nil
106
+ @trivia_owner = ''
107
+ @trivia_wrong = 0
108
+ m.reply Format(:red, "Game aborted by #{m.user.nick}.")
109
+ else
110
+ m.reply Format(:red, "Only ops and the game luncher can stop the game. #{m.user.nick} GTFO.")
108
111
  end
109
112
  end
110
113
 
@@ -22,15 +22,15 @@ class Storage
22
22
 
23
23
  def initialize(file)
24
24
  @file = file
25
- db = File.exists?(file) ? JSON.load(File.read(file)) : []
26
- @db = [].tap { |d|
27
- db.each { |p| d << Pokemon.to_pokemon(p) }
25
+ @db = [].tap { |db|
26
+ (File.exists?(file) ? JSON.load(File.read(file)) : []).each { |p| db << Pokemon.to_pokemon(p) }
28
27
  }
29
28
  end
30
29
 
31
30
  def is_cached?(name)
32
31
  return @db.select { |p| p._name == name.downcase }.any?
33
32
  end
33
+ alias :include? :is_cached?
34
34
 
35
35
  def get(name)
36
36
  return @db.select { |p| p._name == name.downcase }.first
@@ -42,17 +42,16 @@ class Storage
42
42
  alias :dump :get_all
43
43
 
44
44
  def add(pokemon)
45
- @db << pokemon
45
+ @db << pokemon unless is_cached?(pokemon.name)
46
46
  end
47
47
  alias :put :add
48
48
 
49
49
  def save
50
- db_ary = [].tap { |ary|
50
+ [].tap { |ary|
51
51
  @db.each { |p| ary << p.to_ary }
52
- }
53
-
54
- File.open(@file, 'wb') { |f|
55
- f.write JSON.dump(db_ary)
52
+ File.open(@file, 'wb') { |f|
53
+ f.write JSON.dump(ary)
54
+ }
56
55
  }
57
56
  end
58
57
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Botemon
22
22
  def self.version
23
- '0.2.3'
23
+ '0.2.4'
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano