qwtf_discord_bot 5.4.6 → 5.4.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/README.md +3 -3
- data/VERSION +1 -1
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +80 -45
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 494909e7fd239e609f01dd75f848bbe8137fc0d867acb5787b0944302ec5afc7
|
4
|
+
data.tar.gz: 9fea99c070c99eb6044fbc75f812ab200553208c656a494a5dbd6d8468fc8913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0174509b7ef119457eba3d97367e3c53e176a6e8597888c235d74f030a28a8afcebbf63b7c416c63b3f64183cf81e655b5d9eb7628c7df533514d609b575b9d
|
7
|
+
data.tar.gz: d8296d6419b4cb26ede8395a7552154e926be59cfac50cae5d7d8dd2aa291699c7f9cb3b6923330a7ff1641a58b85af60ad5e2d43b5c4d54f4820f35c786e8ed
|
data/README.md
CHANGED
@@ -90,14 +90,14 @@ This responds to discord messages:
|
|
90
90
|
- `!join`
|
91
91
|
- `!leave`
|
92
92
|
- `!teamsize <no_of_players>`
|
93
|
-
- `!kick <@player
|
93
|
+
- `!kick <@player> [@player2]`
|
94
94
|
- `!team <team_no>`
|
95
95
|
- `!unteam`
|
96
96
|
- `!addmap <map_name>`
|
97
97
|
- `!removemap <map_name>`
|
98
98
|
- `!maps`
|
99
|
-
- `!map
|
100
|
-
- `!choose`
|
99
|
+
- `!map [map_name]`
|
100
|
+
- `!choose [n]`
|
101
101
|
- `!win <team_no>`
|
102
102
|
- `!draw`
|
103
103
|
- `!notify <@role>`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.4.
|
1
|
+
5.4.7
|
@@ -26,7 +26,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
26
26
|
)
|
27
27
|
|
28
28
|
bot.command :help do |event, *args|
|
29
|
-
"Pug commands: `!status`, `!join`, `!team <team_no
|
29
|
+
"Pug commands: `!status`, `!join`, `!team <team_no> [@player1] [@player2]`, `!unteam`, `!leave`, `!kick <@player>`, `!win <team_no>`, `!draw`, `!end`, `!teamsize <no_of_players>`, `!addmap <map_name>`, `!removemap <map_name>`, `!maps`, `!map [map_name]`, `!choose [n]`, `!notify <@role>`"
|
30
30
|
end
|
31
31
|
|
32
32
|
bot.command :join do |event, *args|
|
@@ -45,18 +45,28 @@ class QwtfDiscordBotPug # :nodoc:
|
|
45
45
|
|
46
46
|
bot.command :choose do |event, *args|
|
47
47
|
setup_pug(event) do |e, pug|
|
48
|
-
if
|
48
|
+
if pug.joined_players.count.odd?
|
49
49
|
return send_embedded_message(
|
50
|
-
description: "Can't choose teams
|
51
|
-
channel:
|
50
|
+
description: "Can't choose teams with odd number of players",
|
51
|
+
channel: event.channel
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
if args.any? && args.first.to_i < 1
|
56
|
+
return send_embedded_message(
|
57
|
+
description: "Choose a number higher than 0; e.g. `!choose 2`",
|
58
|
+
channel: e.channel
|
59
|
+
)
|
57
60
|
end
|
58
61
|
|
59
|
-
|
62
|
+
iteration = if args.any?
|
63
|
+
args.first.to_i - 1
|
64
|
+
else
|
65
|
+
0
|
66
|
+
end
|
67
|
+
|
68
|
+
choose_fair_teams(pug: pug, event: e, iteration: iteration)
|
69
|
+
status(pug: pug, event: e)
|
60
70
|
end
|
61
71
|
end
|
62
72
|
|
@@ -69,35 +79,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
69
79
|
)
|
70
80
|
end
|
71
81
|
|
72
|
-
|
73
|
-
pug.game_map,
|
74
|
-
"#{pug.player_slots} joined",
|
75
|
-
].compact.join(MSG_SNIPPET_DELIMITER)
|
76
|
-
|
77
|
-
send_embedded_message(
|
78
|
-
description: nil,
|
79
|
-
channel: e.channel
|
80
|
-
) do |embed|
|
81
|
-
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
82
|
-
text: footer
|
83
|
-
)
|
84
|
-
|
85
|
-
pug.teams.each do |team_no, player_ids|
|
86
|
-
team_display_names = player_ids.map do |player_id|
|
87
|
-
e.display_name_for(player_id)
|
88
|
-
end
|
89
|
-
|
90
|
-
embed.add_field(
|
91
|
-
Discordrb::Webhooks::EmbedField.new(
|
92
|
-
{
|
93
|
-
inline: true,
|
94
|
-
name: team_name(team_no),
|
95
|
-
value: team_display_names.join("\n")
|
96
|
-
}
|
97
|
-
)
|
98
|
-
)
|
99
|
-
end
|
100
|
-
end
|
82
|
+
status(pug: pug, event: e)
|
101
83
|
end
|
102
84
|
end
|
103
85
|
|
@@ -619,20 +601,70 @@ class QwtfDiscordBotPug # :nodoc:
|
|
619
601
|
nil # stop discordrb printing return value
|
620
602
|
end
|
621
603
|
|
622
|
-
def
|
623
|
-
if !pug.
|
624
|
-
send_embedded_message(
|
625
|
-
description: "
|
604
|
+
def choose_fair_teams(pug:, event:, iteration: 0)
|
605
|
+
if !pug.full?
|
606
|
+
return send_embedded_message(
|
607
|
+
description: "Can't choose teams until PUG is full",
|
608
|
+
channel: e.channel
|
609
|
+
)
|
610
|
+
end
|
611
|
+
|
612
|
+
send_embedded_message(
|
613
|
+
description: "Choosing fair teams...",
|
614
|
+
channel: event.channel
|
615
|
+
)
|
616
|
+
|
617
|
+
combinations = get_fair_teams(pug.joined_players)
|
618
|
+
teams = combinations[iteration]
|
619
|
+
|
620
|
+
if !teams
|
621
|
+
return send_embedded_message(
|
622
|
+
description: "There are only #{combinations.count} possible combinations",
|
626
623
|
channel: event.channel
|
627
624
|
)
|
628
|
-
|
625
|
+
end
|
626
|
+
|
627
|
+
teams.each do |team_no, player_ids|
|
628
|
+
player_ids.each do |player_id|
|
629
|
+
pug.join_team(team_no: team_no, player_id: player_id)
|
630
|
+
end
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
def status(pug:, event:)
|
635
|
+
footer = [
|
636
|
+
pug.game_map,
|
637
|
+
"#{pug.player_slots} joined"
|
638
|
+
].compact.join(MSG_SNIPPET_DELIMITER)
|
639
|
+
|
640
|
+
send_embedded_message(
|
641
|
+
description: nil,
|
642
|
+
channel: event.channel
|
643
|
+
) do |embed|
|
644
|
+
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
645
|
+
text: footer
|
646
|
+
)
|
629
647
|
|
630
|
-
teams.each do |team_no, player_ids|
|
631
|
-
player_ids.
|
632
|
-
|
648
|
+
pug.teams.each do |team_no, player_ids|
|
649
|
+
team_display_names = player_ids.map do |player_id|
|
650
|
+
event.display_name_for(player_id)
|
633
651
|
end
|
652
|
+
|
653
|
+
embed.add_field(
|
654
|
+
Discordrb::Webhooks::EmbedField.new(
|
655
|
+
{
|
656
|
+
inline: true,
|
657
|
+
name: team_name(team_no),
|
658
|
+
value: team_display_names.join("\n")
|
659
|
+
}
|
660
|
+
)
|
661
|
+
)
|
634
662
|
end
|
635
663
|
end
|
664
|
+
end
|
665
|
+
|
666
|
+
def start_pug(pug, event)
|
667
|
+
choose_fair_teams(pug: pug, event: event) unless pug.actual_teams.any?
|
636
668
|
|
637
669
|
footer = [
|
638
670
|
pug.game_map,
|
@@ -695,6 +727,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
695
727
|
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
696
728
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
697
729
|
req.body = json
|
730
|
+
|
698
731
|
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
699
732
|
http.request(req)
|
700
733
|
end
|
@@ -705,9 +738,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
705
738
|
params = { 'players[]' => players }
|
706
739
|
uri.query = URI.encode_www_form(params)
|
707
740
|
req = Net::HTTP::Get.new(uri)
|
741
|
+
|
708
742
|
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
709
743
|
http.request(req)
|
710
744
|
end
|
711
|
-
|
745
|
+
|
746
|
+
JSON.parse(res.body).map(&:to_h)
|
712
747
|
end
|
713
748
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qwtf_discord_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.4.
|
4
|
+
version: 5.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|