开源软件名称(OpenSource Name):ma1uta/mxtoot开源软件地址(OpenSource Url):https://github.com/ma1uta/mxtoot开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):MXToot - Matrix-Mastodon bot written on java.OverviewUsageRequirements:
Run application serviceCommand:
will check you configuration in the mxtoot.yaml file. Command:
will run the application service. An example mxtoot.service file is provided for systemd usage with Invite a botInvite a bot with unique mxid like '@mxtoot_clientapp:homeserver.url' where
It is important that the name of the bot be unique. You can do this by choose unique clientapp (for example, your mastodon's username). Application service will create the bot and join it to the invited room. Also user who sent invite will be a owner of the bot. Registration bot in the Mastodon.To start registration flow use command After this you can enable your home stream by command Also owner can rejoin bot to a new room by command To delete bot execute command RegistrationEach application service should me registered on the homeserver via registration file. There is an example how to register mxtoot: # unique identifier of the application service
id: "mxtoot"
# url of the application service
url: "https://app.me:8443"
# token AS will add to requests to HS
as_token: "EapiSh7h"
# token token HS will add to requests to AS
hs_token: "tah6Zoox"
# This is a field which denotes the user_id localpart when using the AS token
sender_localpart: "mxtoot"
namespaces:
users: # List of users we're interested in
- exclusive: true
regex: "@mxtoot_.*"
rooms: [] # List of aliases we're interested in
aliases: [] # List of room ids we're interested in CertificateApplication service can use certificates stored in pkcs12 file (at current moment) to work under secure connection (https). To convert pem-based certificates to pkcs12 you can use next command:
where privkey.pem and fullchain.pem are private key and certificate with public key and all parent certificates. You can use certificates from Lets Encrypt. ConfigurationThere is only an one configuration yaml-file which include all settings. homeserverUrlUrl of the matrix homeserver. For example "https://matrix.org:8448" displayNameInitial bot's displayName. If command is enabled it is possible to change this name. Can be invoked only by owner. For example, "mxtoot". prefixInitial command's prefix. If command is enabled it is possible to change prefix. Can be invoked only by owner. For example, "!". DO NOT USE "/". This character is internal used by Web Riot and all commands with "/" prefix will be invoked only by Riot not bot. Workaround ro execute commands: place one or more spaces before prefix. Also there is a special placeholder {{display_name}} which will be replaced by current bot's name. You can set prefix as "{{display_name}}:" and all commands should be execute by bot's mention. For example, "mxtoot: help". commandsThere is a list of all enabled commands described by command's class. See more. runStateThere are two run states: APPLICATION_SERVICE and STANDALONE. In STANDALONE mode each of the bots will run in separated thread and receive events from /sync request like a common client. In APPLICATION_SERVICE mode bots wont'be run in threads and will receive events only from application service via /transaction endpoint. This state is recommended because reduces load of the homeserver. strictModeMay be When Application service receive events via /transaction endpoint it will validate event. When strictMode is enabled if unknown field is found application service will throw exception and stop it process. When strictMode is disabled it will skip event's validations and all unknown fields will be ignored. postFormatreplyFormatboostFormatmentionFormatfavouriteFormatfollowFormatInitial template of the post, reply, boost, mention, favourite and follow messages which come from Mastodon. To create messages uses jmustache library, it is another java implementation of the logic-less templating engine mustache. For example, how you can define template:
When bot receive message from the Mastodon it fill all placeholders Available placeholders: Notification
Status
If fetch statuses is enabled then add next fields:
Account
Emoji
Attachment
Mention
Tag
Application
dateTimeFormatDefines how display date and time from all Mastodon's messages. See more on the https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html in the Section "Patterns for Formatting and Parsing". dateTimeLocaleDefines locale of the localized date terms in the dateTimeFormat template. For example, you can set fetchMissingStatusesMay be Also there are a lot of dropwizard's settings. You can check it in the corresponding page. Because synapse doesn't work with zipped requests it need to disable zipping. And increase timeouts to avoid a lot of timeout errors in the /sync request (in STANDALONE run mode).
CommandsThere are two command's categories: commands which can be invoked only by owner (who invited bot) and commands which can be invoked as access policy configured (everyone or only owner). Access policy is configured by command SetAccessPolicy
To use commands you should list all available commands (class names) in the io.github.ma1uta.matrix.bot.command.LeaveLeave current room. If bot isn't available in any rooms it will delete itself. io.github.ma1uta.matrix.bot.command.NewNameSet new name. io.github.ma1uta.matrix.bot.command.PongJust pong. io.github.ma1uta.matrix.bot.command.SetAccessPolicySet or show access policy. All commands are divided into two categories: commands which can be invoked only by owner (who invited bot) or category which is set by this command. Possible values: OWNER or ALL. io.github.ma1uta.matrix.bot.command.JoinRejoin to a new room. Bot will leave from old room. io.github.ma1uta.matrix.bot.command.PrefixSet or show command prefix, override the prefix setting. io.github.ma1uta.matrix.bot.command.DefaultCommandSet default command. If invoked unknown commands or entered some text it would invoke the default command. For example, if invoke io.github.ma1uta.matrix.bot.command.HelpShow all commands. io.github.ma1uta.mxtoot.matrix.command.RegisterMastodonClientStart registration flow. Syntax: io.github.ma1uta.mxtoot.matrix.command.AuthorizeMastodonClientValidate auth code. io.github.ma1uta.mxtoot.matrix.command.TimelineStart or stop timeline. Bot create connection to the streaming resource and will receive all new messages. Possible value: io.github.ma1uta.mxtoot.matrix.command.PublicPost a new public message to the Mastodon. io.github.ma1uta.mxtoot.matrix.command.PrivatePost a new private message to the Mastodon. io.github.ma1uta.mxtoot.matrix.command.UnlistedPost a new unlistedpublic message to the Mastodon. io.github.ma1uta.mxtoot.matrix.command.DirectPost a new direct message to the Mastodon. io.github.ma1uta.mxtoot.matrix.command.ReplyReply to the message from Mastodon. The reply has the same visibility (public, private, unlisted, direct) as the origin. io.github.ma1uta.mxtoot.matrix.command.FetchStatusesSome messages from Mastodon has only identifier of the statuses or accounts. If this parameter is io.github.ma1uta.mxtoot.matrix.command.FormatSet or show post, reply or boost message templates. io.github.ma1uta.mxtoot.matrix.command.BoostBoost(reblog) message. io.github.ma1uta.mxtoot.matrix.command.FollowFollow to somebody. io.github.ma1uta.mxtoot.matrix.command.UnfollowUnfollow. io.github.ma1uta.mxtoot.matrix.command.MuteMute somebody. io.github.ma1uta.mxtoot.matrix.command.UnmuteUnmute. io.github.ma1uta.mxtoot.matrix.command.BlockBlock somebody. io.github.ma1uta.mxtoot.matrix.command.UnblockUnblock. io.github.ma1uta.mxtoot.matrix.command.FollowersShow followers of the specified user id. io.github.ma1uta.mxtoot.matrix.command.FollowingShow followings of the specified user id. CompileTo build you need jdk 8 (oracle or openjdk) and apache maven 3.5.2 or higher.
Don't hesitate to contact me in the #mxtoot:matrix.org room. :-) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论