brainiac-discord 0.0.23 → 0.0.25

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b8cac77bcff754559623d7dc4b787a4fb405c8e34924b59fcd24a9d3db58d70
4
- data.tar.gz: 027f50b17e55e46aa58c7305e62834b953054515c77da6a803ece5f90b5c3d35
3
+ metadata.gz: b993813772110a77d5ac815a314c8eb7853083ac9cbd0c3322579e1f1b80ee40
4
+ data.tar.gz: 63d422ec1ffe6e8d3c12b267c5f14061d23651e863e69f891f6d558a7e553010
5
5
  SHA512:
6
- metadata.gz: 80215591d21d89f226ae08f7c1ef246a7730bb36b9e71592f3b5ad06fdeee750c3e68508b8fd25071fb450754401946b614e8b28b9665660b8bf16f1b6a4a5c5
7
- data.tar.gz: 543f0b0d398e220b8e9927b0638a2e67780f6bdf48375456d13a741faed14bc4bc2b51ac95a6fce3a2f2c85f846591b4c08381d0579d2b567a43a0860849d279
6
+ metadata.gz: 72e8c931e9fb970da65743314407deebb8096f6f6e53263432ccf34fa637eed3e72b814df9de299f55f4ef162bf7bd50192c2c9a96cc077bb96defca272e06da
7
+ data.tar.gz: 476d43b17b45b289e661da974062445f1ff1a660410ab5679fd3a41777fbfaecccc7abe010b1d272cc848dc3610108fd1561b9517c140576ff58d5cff3efa51a
@@ -44,7 +44,8 @@ module Brainiac
44
44
  return
45
45
  end
46
46
 
47
- token ||= prompt_for_token(display_name, entry["open_browser"])
47
+ existing_id = discord_config.dig("user_mappings", display_name)
48
+ token ||= prompt_for_token(display_name, entry["open_browser"], existing_id)
48
49
  return unless token
49
50
 
50
51
  me = request(:get, "/users/@me", token)
@@ -68,15 +69,24 @@ module Brainiac
68
69
 
69
70
  private
70
71
 
71
- def prompt_for_token(display_name, browser)
72
+ # With a user_mappings entry the app already exists (the token was lost
73
+ # or rotated), so send the user straight to its Bot tab instead of
74
+ # "New Application". A bot's user ID is its application ID.
75
+ def prompt_for_token(display_name, browser, existing_id = nil)
72
76
  return nil unless $stdin.tty?
73
77
 
78
+ url = existing_id ? "#{PORTAL_URL}/#{existing_id}/bot" : PORTAL_URL
74
79
  puts ""
75
- puts " [Discord] Opening the developer portal in your browser…" if browser && open_url(PORTAL_URL)
76
- puts " [Discord] Create a bot for #{display_name} (the only manual step):"
77
- puts " 1. #{PORTAL_URL} → New Application → name it \"#{display_name}\""
78
- puts " 2. Bot tab → Reset Token → copy it"
79
- puts " Name, avatar, description and Message Content intent are set automatically."
80
+ puts " [Discord] Opening the developer portal in your browser…" if browser && open_url(url)
81
+ if existing_id
82
+ puts " [Discord] #{display_name} already has a Discord app, but its bot token isn't saved."
83
+ puts " #{url} → Reset Token → copy it"
84
+ else
85
+ puts " [Discord] Create a bot for #{display_name} (the only manual step):"
86
+ puts " 1. #{PORTAL_URL} → New Application → name it \"#{display_name}\""
87
+ puts " 2. Bot tab → Reset Token → copy it"
88
+ puts " Name, avatar, description and Message Content intent are set automatically."
89
+ end
80
90
  print " Bot token (blank to skip): "
81
91
  token = read_secret
82
92
  puts ""
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Discord
6
- VERSION = "0.0.23"
6
+ VERSION = "0.0.25"
7
7
  end
8
8
  end
9
9
  end
@@ -65,6 +65,21 @@ module Brainiac
65
65
  end
66
66
  end
67
67
 
68
+ # `agent create` writes the agent before the Discord step saves its token,
69
+ # so the server can see the agent first and only get the token here.
70
+ Brainiac.on(:agent_updated) do |ctx|
71
+ agent_key = ctx[:agent_key]
72
+ token = ((ctx[:entry].is_a?(Hash) && ctx[:entry]["env"]) || {})["DISCORD_BOT_TOKEN"]
73
+ next if token == Gateway.bot_token(agent_key)
74
+
75
+ Config.reload! # pick up the user_mappings entry the setup step wrote
76
+ Gateway.stop_bot!(agent_key)
77
+ if token
78
+ Gateway.start_bot!(agent_key, token)
79
+ LOG.info "[Discord] Started bot for #{ctx[:display_name]} (token added/changed)" if defined?(LOG)
80
+ end
81
+ end
82
+
68
83
  Brainiac.on(:agent_removed) do |ctx|
69
84
  agent_key = ctx[:agent_key]
70
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainiac-discord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis