summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/rbot/plugins/figlet.rb33
-rw-r--r--data/rbot/plugins/roshambo.rb20
2 files changed, 39 insertions, 14 deletions
diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb
index 598adfaf..cf9ee8e8 100644
--- a/data/rbot/plugins/figlet.rb
+++ b/data/rbot/plugins/figlet.rb
@@ -1,8 +1,28 @@
-#DEFAULT_FONT="smslant"
-DEFAULT_FONT="rectangles"
+DEFAULT_FONTS = ['rectangles', 'smslant']
MAX_WIDTH=68
class FigletPlugin < Plugin
+ def initialize
+ super
+ @figlet_path = "/usr/bin/figlet"
+
+ # check that figlet actually has the font installed
+ for fontname in DEFAULT_FONTS
+ # check if figlet can render this font properly
+ if system("#{@figlet_path} -f #{fontname} test test test")
+ @figlet_font = fontname
+ break
+ end
+ end
+
+ # set the commandline params
+ @figlet_params = ['-k', '-w', MAX_WIDTH.to_s]
+
+ # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font)
+ @figlet_params += ['-f', @figlet_font] if @figlet_font
+
+ end
+
def help(plugin, topic="")
"figlet <message> => print using figlet"
end
@@ -13,9 +33,14 @@ class FigletPlugin < Plugin
m.reply "the message can't start with a - sign"
return
end
- m.reply Utils.safe_exec("/usr/bin/figlet", "-k", "-w", "#{MAX_WIDTH}", "-f", DEFAULT_FONT, message)
- return
+
+ # collect the parameters to pass to safe_exec
+ exec_params = [@figlet_path] + @figlet_params + [message]
+
+ # run figlet
+ m.reply Utils.safe_exec(*exec_params)
end
+
end
plugin = FigletPlugin.new
diff --git a/data/rbot/plugins/roshambo.rb b/data/rbot/plugins/roshambo.rb
index 7f776c39..74b94a4c 100644
--- a/data/rbot/plugins/roshambo.rb
+++ b/data/rbot/plugins/roshambo.rb
@@ -11,8 +11,8 @@ class RoshamboPlugin < Plugin
def initialize
super
@scoreboard = {}
- @plays = [:rock, :paper, :scissor]
@beats = { :rock => :scissors, :paper => :rock, :scissors => :paper}
+ @plays = @beats.keys
end
def help(plugin, topic="")
@@ -21,32 +21,32 @@ class RoshamboPlugin < Plugin
def rps(m, params)
# simultaneity
- choice = @plays.pick_one
+ bot_choice = @plays.pick_one
# init scoreboard
if not @scoreboard.has_key?(m.sourcenick) or (Time.now - @scoreboard[m.sourcenick]['timestamp']) > 3600
@scoreboard[m.sourcenick] = { 'me' => 0, 'you' => 0, 'timestamp' => Time.now }
end
- play = params[:play].to_sym
- s = score(choice, play)
+ human_choice = params[:play].to_sym
+ s = score(bot_choice, human_choice)
@scoreboard[m.sourcenick]['timestamp'] = Time.now
myscore=@scoreboard[m.sourcenick]['me']
yourscore=@scoreboard[m.sourcenick]['you']
case s
when 1
yourscore = @scoreboard[m.sourcenick]['you'] += 1
- m.reply "#{choice}. You win. Score: me #{myscore} you #{yourscore}"
+ m.reply "#{bot_choice}. You win. Score: me #{myscore} you #{yourscore}"
when 0
- m.reply "#{choice}. We tie. Score: me #{myscore} you #{yourscore}"
+ m.reply "#{bot_choice}. We tie. Score: me #{myscore} you #{yourscore}"
when -1
myscore = @scoreboard[m.sourcenick]['me'] += 1
- m.reply "#{choice}! I win! Score: me #{myscore} you #{yourscore}"
+ m.reply "#{bot_choice}! I win! Score: me #{myscore} you #{yourscore}"
end
end
- def score(a, b)
- return -1 if @beats[a] == b
- return 1 if @beats[b] == a
+ def score(bot_choice, human_choice)
+ return -1 if @beats[bot_choice] == human_choice
+ return 1 if @beats[human_choice] == bot_choice
return 0
end
end