-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.rb
43 lines (32 loc) · 801 Bytes
/
shell.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
require 'readline'
require './shell_commands'
class Shell
include Commands
def initialize bot, config
@bot = bot
@cfg = config
@read = Readline
@list = config["shell_commands"]
user = bot.profile.name
disc = bot.profile.discriminator
@prompt = "(#{user}##{disc}) >> "
@read.completion_append_character = " "
@read.completion_proc = proc { |s| @read::HISTORY.grep(/^\S/) }
end
def loop
while input = @read.readline(@prompt, true)
@hist = @read::HISTORY
@hist.pop and next if input == ""
@hist.pop and next if input.match('^\s+$')
begin
eval(input)
rescue Exception => e
puts e.backtrace.join ""
puts e.message
else
puts "Done."
end
end
end
end