Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix Ruby SDK
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Olofsson
Matrix Ruby SDK
Commits
94cbb727
Verified
Commit
94cbb727
authored
1 year ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
Make example bot friendlier
parent
06a7a8cb
No related branches found
No related tags found
No related merge requests found
Pipeline
#102683
failed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bot_api.rb
+11
-12
11 additions, 12 deletions
examples/bot_api.rb
with
11 additions
and
12 deletions
examples/bot_api.rb
+
11
−
12
View file @
94cbb727
...
@@ -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 a
n 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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment