bobby-b 0.0.2 → 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 +35 -13
- data/lib/bobby-b/bobby.rb +57 -84
- metadata +5 -5
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
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'ostruct'
|
|
6
|
+
require 'bobby-b/bobby'
|
|
7
|
+
|
|
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
|
|
18
|
+
parser.banner = 'Usage: bobby-b [options]'
|
|
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
|
|
34
|
+
|
|
35
|
+
main
|
data/lib/bobby-b/bobby.rb
CHANGED
|
@@ -1,84 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"YOU HELPED ME WIN THE IRON THRONE, NOW HELP ME KEEP THE DAMN THING! WE WERE MEANT TO RULE TOGETHER!",
|
|
59
|
-
"I THOUGHT BEING KING MEANT I COULD DO WHATEVER I WANTED!",
|
|
60
|
-
"IT'S A GREAT CRIME TO LIE TO A KING!",
|
|
61
|
-
"THE GODS MOCK THE PRAYERS OF KINGS AND COWHERDS ALIKE!",
|
|
62
|
-
"BACKSTABBING DOESN'T PREPARE YOU FOR A FIGHT!",
|
|
63
|
-
"DRINK AND STAY QUIET, THE KING IS TALKING!",
|
|
64
|
-
"I WAS NEVER SO ALIVE AS WHEN I WAS WINNING THIS THRONE, OR SO DEAD AS NOW THAT I'VE WON IT!",
|
|
65
|
-
"GIVE ME SOMETHING FOR THE PAIN AND LET ME DIE!",
|
|
66
|
-
"I ASK YOU, NED, WHAT GOOD IS IT TO WEAR A CROWN?",
|
|
67
|
-
"THE GODS BE DAMNED! IT WAS A HOLLOW VICTORY THEY GAVE ME!",
|
|
68
|
-
"I SIT ON THE DAMN IRON SEAT WHEN I MUST. DOES THAT MEAN I DON'T HAVE THE SAME HUNGERS AS OTHER MEN?",
|
|
69
|
-
"A BIT OF WINE NOW AND AGAIN, A GIRL SQUEALING IN BED, THE FEEL OF A HORSE BETWEEN MY LEGS?",
|
|
70
|
-
"SEVEN HELLS, NED, I WANT TO HIT SOMEONE!",
|
|
71
|
-
"MORE THAN ONCE, I HAVE DREAMED OF GIVING UP THE CROWN!",
|
|
72
|
-
"TAKE SHIP FOR THE FREE CITIES WITH MY HORSE AND MY HAMMER, SPEND MY TIME WARRING AND WHORING, THAT’S WHAT I WAS MADE FOR!",
|
|
73
|
-
"THE SELLSWORD KING, HOW THE SINGERS WOULD LOVE ME!"
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
bot = Discordrb::Bot.new token: options.api_key
|
|
77
|
-
bot.message() do |event|
|
|
78
|
-
if "#{event.message}".include? "#{bot.bot_user.id}"
|
|
79
|
-
event.respond(responses.sample)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
bot.run
|
|
83
|
-
end
|
|
84
|
-
end
|
|
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,17 +1,17 @@
|
|
|
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
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: ''
|
|
14
|
-
email: kruhlmann
|
|
14
|
+
email: andreas@kruhlmann.dev
|
|
15
15
|
executables:
|
|
16
16
|
- bobby-b
|
|
17
17
|
extensions: []
|
|
@@ -29,9 +29,9 @@ 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
|
- - ">="
|