qwtf_discord_bot 5.4.6 → 5.4.11
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 +102 -62
- 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: b7785ca7ed0ab47cdae89946225b60fe94c4e5ef21e8df14a1855ed70c262f9e
|
4
|
+
data.tar.gz: fbc91574a3557232b40236f750e4c6ad2e7e130f15e3176030ec18cfd519c776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ba026861ed819cbf511bf92f15781d88558788e4617c0a9e8e6af939907d3d1cde267ff1ad3e61f0f660e9e1c50b7f1d90b03299583c6a14037a23d5617df0f
|
7
|
+
data.tar.gz: 710d552cea8daf99b052e842db5120a5e399667d3a7af4391441ea410029d90ab3a316a5d67af93a9f9ffec6195ad05f59b3eb35c07b9a7dfad34eb7a73dba9b
|
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.11
|
@@ -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,29 @@ 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
|
+
|
69
|
+
message_obj = choose_fair_teams(pug: pug, event: e, iteration: iteration)
|
70
|
+
status(pug: pug, event: e, message_obj: message_obj) if message_obj
|
60
71
|
end
|
61
72
|
end
|
62
73
|
|
@@ -69,35 +80,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
69
80
|
)
|
70
81
|
end
|
71
82
|
|
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
|
83
|
+
status(pug: pug, event: e)
|
101
84
|
end
|
102
85
|
end
|
103
86
|
|
@@ -278,15 +261,6 @@ class QwtfDiscordBotPug # :nodoc:
|
|
278
261
|
|
279
262
|
user_id = mention_to_user_id(mention)
|
280
263
|
display_name = e.display_name_for(user_id) || arg
|
281
|
-
|
282
|
-
unless pug.joined?(user_id)
|
283
|
-
send_embedded_message(
|
284
|
-
description: "#{display_name} isn't in the PUG",
|
285
|
-
channel: e.channel
|
286
|
-
)
|
287
|
-
next
|
288
|
-
end
|
289
|
-
|
290
264
|
pug.join_team(team_no: team_no, player_id: user_id)
|
291
265
|
|
292
266
|
send_embedded_message(
|
@@ -378,7 +352,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
378
352
|
teams.merge({ name => { players: players, result: result } })
|
379
353
|
end
|
380
354
|
|
381
|
-
post_results(
|
355
|
+
id = post_results(
|
382
356
|
{
|
383
357
|
match: {
|
384
358
|
map: pug.game_map,
|
@@ -389,10 +363,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
389
363
|
}
|
390
364
|
}
|
391
365
|
}.to_json
|
392
|
-
)
|
366
|
+
).body
|
393
367
|
|
394
368
|
send_embedded_message(
|
395
|
-
description: "#{TEAM_NAMES[winning_team_no]} wins. [Ratings](http://ratings.fortressone.org)",
|
369
|
+
description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. [Ratings](http://ratings.fortressone.org)",
|
396
370
|
channel: e.channel
|
397
371
|
)
|
398
372
|
end
|
@@ -422,7 +396,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
422
396
|
teams.merge({ name => { players: players, result: 0 } })
|
423
397
|
end
|
424
398
|
|
425
|
-
post_results(
|
399
|
+
id = post_results(
|
426
400
|
{
|
427
401
|
match: {
|
428
402
|
map: pug.game_map,
|
@@ -433,10 +407,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
433
407
|
}
|
434
408
|
}
|
435
409
|
}.to_json
|
436
|
-
)
|
410
|
+
).body
|
437
411
|
|
438
412
|
send_embedded_message(
|
439
|
-
description: "Match drawn. [Ratings](http://ratings.fortressone.org)",
|
413
|
+
description: "Match ##{id} drawn. [Ratings](http://ratings.fortressone.org)",
|
440
414
|
channel: e.channel
|
441
415
|
)
|
442
416
|
end
|
@@ -619,20 +593,74 @@ class QwtfDiscordBotPug # :nodoc:
|
|
619
593
|
nil # stop discordrb printing return value
|
620
594
|
end
|
621
595
|
|
622
|
-
def
|
623
|
-
if !pug.
|
624
|
-
send_embedded_message(
|
625
|
-
description: "
|
596
|
+
def choose_fair_teams(pug:, event:, iteration: 0)
|
597
|
+
if !pug.full?
|
598
|
+
return send_embedded_message(
|
599
|
+
description: "Can't choose teams until PUG is full",
|
626
600
|
channel: event.channel
|
601
|
+
) && nil
|
602
|
+
end
|
603
|
+
|
604
|
+
message_obj = send_embedded_message(
|
605
|
+
description: "Choosing fair teams...",
|
606
|
+
channel: event.channel
|
607
|
+
)
|
608
|
+
|
609
|
+
combinations = get_fair_teams(pug.joined_players)
|
610
|
+
teams = combinations[iteration]
|
611
|
+
|
612
|
+
if !teams
|
613
|
+
return send_embedded_message(
|
614
|
+
description: "There are only #{combinations.count} possible combinations",
|
615
|
+
channel: event.channel,
|
616
|
+
message_obj: message_obj
|
617
|
+
) && nil
|
618
|
+
end
|
619
|
+
|
620
|
+
teams.each do |team_no, player_ids|
|
621
|
+
player_ids.each do |player_id|
|
622
|
+
pug.join_team(team_no: team_no, player_id: player_id)
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
message_obj
|
627
|
+
end
|
628
|
+
|
629
|
+
def status(pug:, event:, message_obj: nil)
|
630
|
+
footer = [
|
631
|
+
pug.game_map || "No map selected",
|
632
|
+
"#{pug.player_slots} joined",
|
633
|
+
].compact.join(MSG_SNIPPET_DELIMITER)
|
634
|
+
|
635
|
+
send_embedded_message(
|
636
|
+
description: nil,
|
637
|
+
channel: event.channel,
|
638
|
+
message_obj: message_obj
|
639
|
+
) do |embed|
|
640
|
+
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
641
|
+
text: footer
|
627
642
|
)
|
628
|
-
teams = get_fair_teams(pug.joined_players)
|
629
643
|
|
630
|
-
teams.each do |team_no, player_ids|
|
631
|
-
player_ids.
|
632
|
-
|
644
|
+
pug.teams.each do |team_no, player_ids|
|
645
|
+
team_display_names = player_ids.map do |player_id|
|
646
|
+
event.display_name_for(player_id)
|
633
647
|
end
|
648
|
+
|
649
|
+
embed.add_field(
|
650
|
+
Discordrb::Webhooks::EmbedField.new(
|
651
|
+
{
|
652
|
+
inline: true,
|
653
|
+
name: team_name(team_no),
|
654
|
+
value: team_display_names.join("\n")
|
655
|
+
}
|
656
|
+
)
|
657
|
+
)
|
634
658
|
end
|
635
659
|
end
|
660
|
+
end
|
661
|
+
|
662
|
+
def start_pug(pug, event)
|
663
|
+
choose_fair_teams(pug: pug, event: event) unless pug.actual_teams.any?
|
636
664
|
|
637
665
|
footer = [
|
638
666
|
pug.game_map,
|
@@ -684,17 +712,27 @@ class QwtfDiscordBotPug # :nodoc:
|
|
684
712
|
"There's no active PUG"
|
685
713
|
end
|
686
714
|
|
687
|
-
def send_embedded_message(message: nil, description: nil, channel:)
|
715
|
+
def send_embedded_message(message: nil, description: nil, channel:, message_obj: nil)
|
688
716
|
embed = Discordrb::Webhooks::Embed.new
|
689
717
|
embed.description = description
|
690
718
|
yield(embed) if block_given?
|
691
|
-
|
719
|
+
|
720
|
+
if message_obj
|
721
|
+
message_obj.edit(message, embed).tap do
|
722
|
+
puts(message)
|
723
|
+
end
|
724
|
+
else
|
725
|
+
channel.send_embed(message, embed).tap do
|
726
|
+
puts(message)
|
727
|
+
end
|
728
|
+
end
|
692
729
|
end
|
693
730
|
|
694
731
|
def post_results(json)
|
695
732
|
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
696
733
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
697
734
|
req.body = json
|
735
|
+
|
698
736
|
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
699
737
|
http.request(req)
|
700
738
|
end
|
@@ -705,9 +743,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
705
743
|
params = { 'players[]' => players }
|
706
744
|
uri.query = URI.encode_www_form(params)
|
707
745
|
req = Net::HTTP::Get.new(uri)
|
746
|
+
|
708
747
|
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
709
748
|
http.request(req)
|
710
749
|
end
|
711
|
-
|
750
|
+
|
751
|
+
JSON.parse(res.body).map(&:to_h)
|
712
752
|
end
|
713
753
|
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.11
|
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-
|
11
|
+
date: 2020-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|