Sha256: 1ba0f761334716ac5daee8fc071290c31eb3d6d4e9a082f95f68e608b0581a39

Contents?: true

Size: 1.61 KB

Versions: 17

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

# description: Connect to discord and start IRB.

require "io/console"
require "discorb"
require "optparse"

intents_value = Discorb::Intents.all.value
token_file = "token"

ARGV.delete_at 0

opt = OptionParser.new <<~BANNER
                         This command will start an interactive Ruby shell with connected client.

                         Usage: discorb irb [options]
                       BANNER
opt.on("-i", "--intents", "intents to use, default to all") { |v| intents_value = v }
opt.on("-t", "--token-file", "token file to load, default to \"token\"") { |v| token_file = v }
opt.parse!(ARGV)

client = Discorb::Client.new(intents: Discorb::Intents.from_value(intents_value))
$messages = []

client.on :ready do
  puts "\e[96mLogged in as #{client.user}\e[m"

  def message
    $messages.last
  end

  def dirb_help
    puts <<~EOS
           \e[96mDiscord-IRB\e[m
           This is a debug client for Discord.
           \e[90mmessage\e[m to get latest message.

           \e[36mhttps://discorb-lib.github.io/#{Discorb::VERSION}/file.irb.html\e[m for more information.
         EOS
  end

  puts <<~FIRST_MESSAGE
         Running on \e[31mRuby #{RUBY_VERSION}\e[m, disco\e[31mrb #{Discorb::VERSION}\e[m
         Type \e[90mdirb_help\e[m to help.
       FIRST_MESSAGE

  binding.irb

  client.close!
end

client.on :message do |message|
  $messages << message
end

token = ENV["DISCORD_BOT_TOKEN"] || ENV["DISCORD_TOKEN"]
if token.nil?
  if File.exists?(token_file)
    token = File.read(token_file)
  else
    print "\e[90mToken?\e[m : "
    token = $stdin.noecho(&:gets).chomp
    puts
  end
end

client.run token

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
discorb-0.7.6 lib/discorb/exe/irb.rb
discorb-0.7.3 lib/discorb/exe/irb.rb
discorb-0.7.2 lib/discorb/exe/irb.rb
discorb-0.7.1 lib/discorb/exe/irb.rb
discorb-0.7.0 lib/discorb/exe/irb.rb
discorb-0.6.1 lib/discorb/exe/irb.rb
discorb-0.6.0 lib/discorb/exe/irb.rb
discorb-0.5.6 lib/discorb/exe/irb.rb
discorb-0.5.5 lib/discorb/exe/irb.rb
discorb-0.5.4 lib/discorb/exe/irb.rb
discorb-0.5.3 lib/discorb/exe/irb.rb
discorb-0.5.2 lib/discorb/exe/irb.rb
discorb-0.5.1 lib/discorb/exe/irb.rb
discorb-0.5.0 lib/discorb/exe/irb.rb
discorb-0.4.2 lib/discorb/exe/irb.rb
discorb-0.4.1 lib/discorb/exe/irb.rb
discorb-0.4.0 lib/discorb/exe/irb.rb