IRB Discord fix and better error reporting

This commit is contained in:
Matthias Portzel 2024-03-24 00:49:25 -04:00
parent 58b6850c84
commit 3f03fc6ed0
1 changed files with 8 additions and 2 deletions

10
main.rb
View File

@ -58,7 +58,9 @@ def define_command text, options
begin
yield event
rescue => err
$study_channel.send "```rb\n#{PP.pp(err, "")}\n#{PP.pp(err.backtrace.join("\n"), "")}\n```"
# TODO: This is ugly
# Ideally we should also print to stderr and keep running
$study_channel.send "```rb\n#{PP.pp(err, "")}\n#{err.backtrace.join("\n")}\n```"
end
end
end
@ -254,6 +256,7 @@ define_command "Edit Puzzle", [
end
text = puzzle.text
# TODO: This errors for some reason and I don't know why
new_text = text.gsub(Regexp.compile(event.options["find_regex"]), new_text)
puzzle.text = new_text
puzzle.save
@ -297,7 +300,10 @@ end
define_command("IRB Discord", []) do |event|
if event.user == $me
return if $irb_sessions.filter { |s| s.user == event.user and s.channel == event.channel }.present?
if $irb_sessions.filter { |s| s.user == event.user and s.channel == event.channel }.present?
event.respond content: "You already had a live session, but it doesn't hurt to make sure."
next
end
event.respond content: "Started an IRB-Discord session. Use `exit` to exit."
session = DiscordIRBSession.new
session.user = event.user