Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbts/matrix_bash_bot
matrix.org Bash Bot
https://github.com/sbts/matrix_bash_bot
Last synced: 5 days ago
JSON representation
matrix.org Bash Bot
- Host: GitHub
- URL: https://github.com/sbts/matrix_bash_bot
- Owner: sbts
- License: gpl-3.0
- Created: 2016-02-29T07:15:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T08:47:12.000Z (7 months ago)
- Last Synced: 2024-08-02T12:50:39.686Z (3 months ago)
- Language: Shell
- Size: 43.9 KB
- Stars: 11
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: change-password.sh
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - sbts/matrix_bash_bot - matrix.org Bash Bot (others)
README
# matrix_bash_bot
matrix.org Bash BotA Semi-Stateless Matrix Bot written in Bash
It depends on bash, curl and jqIt is currently far from complete, but is usable to Login, Join a Room, and Send a message to that room
In theory, you can also register a new user, although this function is untestedReceiving messages is being worked on at the moment.
Other functions will be added when I need them or someone else contributes them.
Some state is stored in /tmp so that consecutive runs don't need to re-login and re-join rooms.
This allows sending of multiple messages with a simple SendMessage command.
There is an assumption made here, there will only be one Login Name and one ROOM in use by any System User.
This is due to the state file being stored in a directory named with the System User appended.Function List
----------------------------------------------------------------------------------------------------------
: ######################################################################################
: ######################################################################################
: USAGE: matrix-bashbot.sh Option|Command [ARG1 [ARG2]]
: Options
: -v --version : script Version
: -h --help : this help
: ######################################################################################
: ######################################################################################
: ######################################################################################
: ######################################################################################
: Configuration and Stored State are first obtained from the defaults in the script
: Then read from ~/.matrix-bash-bot.rc
: NOTE: the location of the rc file can be overridden by setting environment variable
: matrix_bash_bot_rc
: before running or sourcing matrix-bashbot.sh
: Then read from $StateFile
: Each source overrides the previous one.
: $StateFile is stored in /tmp and is normally deleted on reboot
: any state_ variables can be stored in ~/.matrix-bash-bot.rc to provide defaults after a reboot.
: but beware, if you do this with the TOKENS and later run the LOGIN function you will
: need to manually update them otherwise a subsequent reboot will end up using the wrong TOKENS
: A better way of handling this is to make sure you do a login after every reboot.
: Eventually we will test for an empty TOKEN every time the script is run, and do an auto login.
: ######################################################################################
: ######################################################################################DIE : $1 = short message $2 = detail
: print a loud error message and exitclear_State : clear all stored state
: if the state is stored in /tmp (the default) then it would normally be cleared on reboot as welldump_Functions : Dump a help style list of functions and Comments starting with ##
: to get a function name to be dumped you need to follow the form, foo() ## comment
: All lines that start with "[[:space:]]*## " will be included regardless of being inside a function or notHELP : This Help Message
: print help and current state
: Run this with -h --help or HELPWRITE_README : Update the README.md file
VERSION : Display the current version of this script
: Run this with -V --version or VERSIONtest_rawurlencode : test the rawurlencode() function, prints the result as well as putting it in $URLstring
: $1 is the String to EncodeRegister : Register a new username.
: Username is read from "$StateFile" [default: /tmp/matrixbashbot-$USER/state-vars ]
: Password is currently stored in this script,
: but will soon be read from stdin instead
: Should only be called once for a username.
: ######################################################
: WARNING fixme this function is untested use with caution
: ######################################################LogIn : Login to get an access token for your username
: the token can be reused essentially forever.
: Username is read from "$StateFile" [default: /tmp/matrixbashbot-$USER/state-vars ]
: Password is currently stored in this script,
: but will soon be read from stdin insteadJoinRoom : $1 is room name
: joins the given room, appends the home_server (likely :matrix.org) if none is provided
: in most cases the room will already be joined, in that case, this function
: primarily is used to change the roomID which is used for all other actionsSendMessage : $1 is message to send
: send a text string to the currently selected room
: a default test string with appended date will be used if no string supplied.mpddj : $@ command to send to mpddj
: NOTE: all mpddj* commands use a fixed room !mpd:half-shot.uk
: skip the currently playing song on http://half-shot.uk/stream via mpddj in room mpd:half-shot.uk
: ping Ping the server and get the delay.
: current Get the current song title.
: next Skip current song.
: help This help text.
: search Get the first youtube result by keywords.
: [url] Type a youtube/soundcloud/file url in to add to the playlist.
: stream Get the url of the stream.
: playlist Display the the shortened playlist.mpddj_QueueSong : $1 is message to send
: queue a song on http://half-shot.uk/stream via mpddj in room mpd:half-shot.uk
: a default song will be selected if you don't enter one
: if a url is supplied containing http: or https: then it will attempt to play that URL
: otherwise it will ask mpddj to search for the song.mpddj_next : no arguments
: skip the currently playing song on http://half-shot.uk/stream via mpddj in room mpd:half-shot.ukmpddj_skip : no arguments
: skip the currently playing song on http://half-shot.uk/stream via mpddj in room mpd:half-shot.ukSetIrcTopic : This is a crude hack that bypasses setting the matrix topic
: and directly tries setting the topic on the IRC side of the bridge.
: of course this will only work if your matrix (IRC side) user has OPs
: or the channel does not have +t set
: on bridged channels, you would normally not have ROOM power to let you change the topic
: $1 is new topicSetTopic : change the topic in the matrix room
: may aslo change the topic for bridged channels in both matrix and IRC but it is unlikely
: as you normally don't have power on the matrix side which will block both sides of the bridge from changing
: on bridged channels, you would normally not have ROOM power to let you change the topic
: $1 is new topicGetInitialSync : retrieves initialSync date with limit=1 and stores it in /tmp/matrixbashbot-$USER/state-initial-sync
: for now nothing else is done with the data, it is just stored in the fileGetRecentEvents : this is broken for now, should return the last X events in the current room
: ######################################################
: WARNING fixme this function is untested use with caution
: ######################################################DoSync : runs a sync from the last known event time
: ######################################################
: WARNING fixme this function is untested use with caution
: ######################################################GetPushRules : dump the current PushRules to stdout as formatted JSON
GetRoomState : dump the current Roomstate to stdout as formatted JSON
SampleGets : some sample gets that don't need authentication