bobby-b 0.0.6 → 0.0.7
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 +4 -4
- data/bin/bobby-b +26 -6
- data/lib/bobby-b/bobby.rb +57 -53
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49d79d669ad319f68c66c67e0f25f996813f22fa7e30b1b3e5c55636b32dc1be
|
|
4
|
+
data.tar.gz: 877a6014b3b04f7a139bcf3f68fb33c46e4ccc90fecfb95d43c4ed8a359b2ebc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b073214711e018c5fa53f3552f7e15da1b7a74ece07002de1b74ffa5d99b990a1bb7ae43221a4a9070ba116e29602315acec2d6b720008bb1abc20459d5d712
|
|
7
|
+
data.tar.gz: '04385341ecbec08b6b20638c0229e85204d2ab41203749fe3f9603fc446bd5bd7c82f4597a1c3766a9bc39e6f0bb13ef69eabd542b036bebbf136e863c6cf0fd'
|
data/bin/bobby-b
CHANGED
|
@@ -5,11 +5,31 @@ require 'optparse'
|
|
|
5
5
|
require 'ostruct'
|
|
6
6
|
require 'bobby-b/bobby'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
def validate_command_line_arguments(arguments)
|
|
9
|
+
has_api_key = arguments.key? :key
|
|
10
|
+
has_responses_file = arguments.key? :responses
|
|
11
|
+
|
|
12
|
+
has_api_key && has_responses_file
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def extract_command_line_arguments
|
|
16
|
+
options = {}
|
|
17
|
+
parser = OptionParser.new
|
|
10
18
|
parser.banner = 'Usage: bobby-b [options]'
|
|
11
|
-
parser.on('-k', '--
|
|
12
|
-
parser.on('-f', '--responses
|
|
13
|
-
|
|
19
|
+
parser.on('-k KEY', '--key=KEY', 'Discord API key', String)
|
|
20
|
+
parser.on('-f FILE', '--responses=FILE', 'List of responses file', String)
|
|
21
|
+
parser.parse!(into: options)
|
|
22
|
+
options
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def main
|
|
26
|
+
arguments = extract_command_line_arguments
|
|
27
|
+
puts arguments
|
|
28
|
+
arguments_are_valid = validate_command_line_arguments(arguments)
|
|
29
|
+
|
|
30
|
+
raise 'Invalid arguments' unless arguments_are_valid
|
|
31
|
+
|
|
32
|
+
Bobby.new(arguments).start
|
|
33
|
+
end
|
|
14
34
|
|
|
15
|
-
|
|
35
|
+
main
|
data/lib/bobby-b/bobby.rb
CHANGED
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'discordrb'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
@
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
event.
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def
|
|
37
|
-
now = Time.now.to_f
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'discordrb'
|
|
4
|
+
|
|
5
|
+
# Bobby B discord bot instance.
|
|
6
|
+
class Bobby
|
|
7
|
+
def initialize(options)
|
|
8
|
+
@queue = []
|
|
9
|
+
@last_message_time = 0
|
|
10
|
+
@cooldown = 0.5
|
|
11
|
+
@discord_token = options[:key]
|
|
12
|
+
@responses = File.readlines(options[:responses])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def start
|
|
16
|
+
start_queue
|
|
17
|
+
start_bot
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def start_bot
|
|
21
|
+
bot = Discordrb::Bot.new token: @discord_token
|
|
22
|
+
|
|
23
|
+
bot.message do |event|
|
|
24
|
+
@queue.unshift(event) if event.message.to_s.include? bot.bot_user.id.to_s
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
bot.run
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def send_newest_message
|
|
31
|
+
response = @responses.sample
|
|
32
|
+
event = @queue.pop
|
|
33
|
+
event.respond(response)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def is_on_cooldown
|
|
37
|
+
now = Time.now.to_f
|
|
38
|
+
bot_is_on_cooldown = now - @last_message_time < @cooldown
|
|
39
|
+
return bot_is_on_cooldown
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def process_queue_item
|
|
43
|
+
return if @queue.empty? || is_on_cooldown
|
|
44
|
+
|
|
45
|
+
send_newest_message
|
|
46
|
+
@last_message_time = Time.now.to_f
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def start_queue
|
|
50
|
+
Thread.new do
|
|
51
|
+
loop do
|
|
52
|
+
sleep 0.1
|
|
53
|
+
process_queue_item
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bobby-b
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Kruhlmann
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2020-07-21 00:00:00.000000000 Z
|
|
@@ -23,23 +23,23 @@ homepage: https://github.com/Kruhlmann/bobby-b
|
|
|
23
23
|
licenses:
|
|
24
24
|
- GPL-3.0-or-later
|
|
25
25
|
metadata: {}
|
|
26
|
-
post_install_message:
|
|
26
|
+
post_install_message:
|
|
27
27
|
rdoc_options: []
|
|
28
28
|
require_paths:
|
|
29
29
|
- lib
|
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
|
-
- -
|
|
32
|
+
- - '='
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
34
|
+
version: '2.7'
|
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '0'
|
|
40
40
|
requirements: []
|
|
41
|
-
rubygems_version: 3.1.
|
|
42
|
-
signing_key:
|
|
41
|
+
rubygems_version: 3.1.2
|
|
42
|
+
signing_key:
|
|
43
43
|
specification_version: 4
|
|
44
44
|
summary: Bobby B bot replacement
|
|
45
45
|
test_files: []
|