From 94cbb72783f7c6585e3fadc846d368ea2b05f105 Mon Sep 17 00:00:00 2001
From: "Alexander \"Ace\" Olofsson" <ace@haxalot.com>
Date: Fri, 25 Aug 2023 09:02:10 +0200
Subject: [PATCH] Make example bot friendlier

---
 examples/bot_api.rb | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/examples/bot_api.rb b/examples/bot_api.rb
index 0d2d955..9fefa4a 100755
--- a/examples/bot_api.rb
+++ b/examples/bot_api.rb
@@ -3,7 +3,7 @@
 
 # An example of a lightweight bot using the bot DSL
 #
-# This bot will implement a subset of the maubot ping/echo module
+# This bot will implement an intersection of the maubot ping/echo module
 # It showcases required and optional parameters, as well as limitations on commands
 
 require 'matrix_sdk/bot'
@@ -13,17 +13,6 @@ module Utils; end
 
 set :bot_name, 'examplebot'
 
-command :spam, only: :dm, desc: 'Spams a bunch of nonsense' do |message_count = nil|
-  message_count ||= 5
-  message_count_i = message_count.to_i
-  raise ArgumentError, 'Message count must be an integer' if message_count_i.to_s != message_count.to_s
-
-  spam = message_count_i.times.map { rand(10..30).times.map { rand(65..91).chr }.join }
-  spam.each do |msg|
-    room.send_notice(msg)
-  end
-end
-
 command(:thumbsup, desc: 'Gives you a thumbs up', only: -> { room.user_can_send? client.mxid, 'm.reaction' }) do
   room.send_event 'm.reaction', {
     'm.relates_to': {
@@ -34,6 +23,16 @@ command(:thumbsup, desc: 'Gives you a thumbs up', only: -> { room.user_can_send?
   }
 end
 
+command :multiply, only: :dm, desc: 'Performs a multiplication of two numbers' do |num_a, num_b|
+  num_rex = /^-?\d+(\.\d+)?$/
+  raise ArgumentError, 'Both arguments must be numbers' unless num_rex.match?(num_a) && num_rex.match?(num_b)
+
+  num_a_f = num_a.to_f
+  num_b_f = num_b.to_f
+
+  room.send_notice("#{num_a} * #{num_b} = #{(num_a_f * num_b_f).round(2)}")
+end
+
 command :echo, desc: 'Echoes the given message back as an m.notice' do |message|
   break if message.nil? # Don't echo empty requests
 
-- 
GitLab