Skip to content
Snippets Groups Projects
Verified Commit 94cbb727 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Make example bot friendlier

parent 06a7a8cb
No related branches found
No related tags found
No related merge requests found
Pipeline #102683 failed
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# An example of a lightweight bot using the bot DSL # 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 # It showcases required and optional parameters, as well as limitations on commands
require 'matrix_sdk/bot' require 'matrix_sdk/bot'
...@@ -13,17 +13,6 @@ module Utils; end ...@@ -13,17 +13,6 @@ module Utils; end
set :bot_name, 'examplebot' 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 command(:thumbsup, desc: 'Gives you a thumbs up', only: -> { room.user_can_send? client.mxid, 'm.reaction' }) do
room.send_event 'm.reaction', { room.send_event 'm.reaction', {
'm.relates_to': { 'm.relates_to': {
...@@ -34,6 +23,16 @@ command(:thumbsup, desc: 'Gives you a thumbs up', only: -> { room.user_can_send? ...@@ -34,6 +23,16 @@ command(:thumbsup, desc: 'Gives you a thumbs up', only: -> { room.user_can_send?
} }
end 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| command :echo, desc: 'Echoes the given message back as an m.notice' do |message|
break if message.nil? # Don't echo empty requests break if message.nil? # Don't echo empty requests
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment