#mastodon #fediverse #bot #activity-pub #simple #server-api #message-sent

app pravda

A bot to connect to a fediverse instance using the mastodon API and host social games

4 releases

0.1.3 Oct 31, 2023
0.1.2 Oct 25, 2023
0.1.1 Oct 20, 2023
0.1.0 Oct 17, 2023

#48 in Games

GPL-3.0 license

37KB
669 lines

Pravda: social games for a social network.

This crate is a functional bot that you can use to connect to a mastodon server (or one providing a similar API) in order to run social games. For now it can be used to play Rock, Paper, Scissors, or roll dice. The code is written modularly so that it is relatively easy to add new games.

The Game trait defines the behaviour for a game, involving an associated method new for setup, and a method next which receives user toots and is responsible to advance the state of the game. Every game receives every message and must be able to discard anything that is irrelevant to it.

There are some constants to shut down the bot remotely with a toot. ADMIN contains the administrative account, QUIT contains the quit message which must be sent as a mention to the bot, and INSTANCE contains the URL of the instance to connect to. At the moment, it uses my own fedi account by default, and the message !QUIT! but you should customise this if you deploy. The default instance is botsin.space, an appropriate instance for bots, but you should change this if you want to run it somewhere else.

Bear in mind you must have a valid account on the instance before you attempt to authorise the bot.

First run.

Decide where you want to execute the game, and make sure you have write permissions. The game will connect to an instance and attempt to establish an OAuth flow, asking you to visit a link and authorise the application with your mastodon/fedi account.

Once this is done, the information is written into a toml file, which should remain private, as it contains a token that allows for almost full control of the account it's authorised under.

On subsequent runs, if this file is encountered, the information will be read from it and the connection will be realised without human intervention.

Limitations.

It is not possible to connect this client to GoTosocial for now. mastodon-async does not use the websocket endpoint to stream from the fedi, but the SSE endpoint instead. GoToSocial only implements the websocket endpoint for streaming operations.

Naturally, it supports both HTTP and HTTPS, through the use of rustls-tls by default. You can change to OpenSSL by modifying the features in Cargo.toml.

Future ambitions.

I'm interested in implementing any sort of social game, by which I understand games which involve social interaction, deception, prediction, or the like. In particular, I am interested in implementing the following games:

Some of these games need more interesting names.

It would be nice to run a nomic on the fedi, but that is a lot more than a bot can do by itself.

Bug reports, feature requests, code contributions and other feedback.

If you want to tell me something about the crate, the best ways are:

Change log.

  • V 0.1.3: dice can be rolled with the dice command, accepting an ndm optional parameter.
  • V 0.1.2: exponential backoff system for cases where the streaming API fails. Assorted typographical corrections.
  • V 0.1.1: set a loop around the toot streaming in case it errors out.
  • V 0.1.0: initial release.

Dependencies

~14–31MB
~515K SLoC