Compare commits
No commits in common. "main" and "regex-filter" have entirely different histories.
main
...
regex-filt
19
.github/workflows/cachix.yaml
vendored
19
.github/workflows/cachix.yaml
vendored
|
@ -1,19 +0,0 @@
|
||||||
name: "Cachix build"
|
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2.3.4
|
|
||||||
- uses: cachix/install-nix-action@v13
|
|
||||||
with:
|
|
||||||
install_url: https://nixos-nix-install-tests.cachix.org/serve/lb41az54kzk6j12p81br4bczary7m145/install
|
|
||||||
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve'
|
|
||||||
extra_nix_config: |
|
|
||||||
experimental-features = nix-command flakes
|
|
||||||
- uses: cachix/cachix-action@v8
|
|
||||||
with:
|
|
||||||
name: alarsyo
|
|
||||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
|
||||||
- run: |
|
|
||||||
nix build --verbose
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
/target
|
/target
|
||||||
/result
|
|
||||||
|
|
459
Cargo.lock
generated
459
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -23,4 +23,4 @@ void = "1"
|
||||||
|
|
||||||
[dependencies.matrix-sdk]
|
[dependencies.matrix-sdk]
|
||||||
git = "https://github.com/matrix-org/matrix-rust-sdk"
|
git = "https://github.com/matrix-org/matrix-rust-sdk"
|
||||||
rev = "b5de20349945afcde13a78f023b906f421bb9764"
|
rev = "b66c666997cbcf32071d24ffe2484a215de8d0e4"
|
||||||
|
|
60
flake.lock
60
flake.lock
|
@ -1,60 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"flake-compat": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1606424373,
|
|
||||||
"narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=",
|
|
||||||
"owner": "edolstra",
|
|
||||||
"repo": "flake-compat",
|
|
||||||
"rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "edolstra",
|
|
||||||
"repo": "flake-compat",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1617631617,
|
|
||||||
"narHash": "sha256-PARRCz55qN3gy07VJZIlFeOX420d0nGF0RzGI/9hVlw=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "b2c27d1a81b0dc266270fa8aeecebbd1807fc610",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1617929752,
|
|
||||||
"narHash": "sha256-ji0nqJUZp2bfHvO0sKxD24cW6Nk7LyjbPPMxjbJHji0=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "6fc2b7ecc2a167ce6a6902d5417daf1fa5cac777",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-compat": "flake-compat",
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
58
flake.nix
58
flake.nix
|
@ -1,58 +0,0 @@
|
||||||
{
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
|
||||||
flake-compat = {
|
|
||||||
url = "github:edolstra/flake-compat";
|
|
||||||
flake = false;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, ... }:
|
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs { inherit system; };
|
|
||||||
in
|
|
||||||
{
|
|
||||||
defaultPackage = pkgs.rustPlatform.buildRustPackage {
|
|
||||||
pname = "bad-news";
|
|
||||||
version = "0.1.0";
|
|
||||||
|
|
||||||
src = ./.;
|
|
||||||
|
|
||||||
cargoSha256 = "sha256-dNf/FYhNRu85Q4ZinvFGcJmMRayVdTJ9j28fu9BIinY=";
|
|
||||||
|
|
||||||
meta = with pkgs.lib; {
|
|
||||||
description = "A Matrix bot, bringer of bad news";
|
|
||||||
homepage = "https://github.com/alarsyo/bad-news";
|
|
||||||
license = with licenses; [ mit asl20 ];
|
|
||||||
platforms = platforms.unix;
|
|
||||||
};
|
|
||||||
|
|
||||||
nativeBuildInputs = with pkgs; [ pkg-config cmake ];
|
|
||||||
buildInputs = with pkgs; [ systemd openssl ];
|
|
||||||
};
|
|
||||||
|
|
||||||
defaultApp = flake-utils.lib.mkApp {
|
|
||||||
drv = self.defaultPackage."${system}";
|
|
||||||
};
|
|
||||||
|
|
||||||
devShell = pkgs.mkShell {
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
cargo
|
|
||||||
clippy
|
|
||||||
nixpkgs-fmt
|
|
||||||
rustPackages.clippy
|
|
||||||
rustc
|
|
||||||
rustfmt
|
|
||||||
|
|
||||||
pkg-config
|
|
||||||
cmake
|
|
||||||
systemd
|
|
||||||
openssl
|
|
||||||
];
|
|
||||||
|
|
||||||
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -4,8 +4,7 @@ use matrix_sdk::{
|
||||||
self, async_trait,
|
self, async_trait,
|
||||||
events::{room::member::MemberEventContent, StrippedStateEvent},
|
events::{room::member::MemberEventContent, StrippedStateEvent},
|
||||||
identifiers::RoomId,
|
identifiers::RoomId,
|
||||||
room::Room,
|
Client, EventEmitter, RoomState,
|
||||||
Client, EventHandler,
|
|
||||||
};
|
};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
@ -21,10 +20,10 @@ impl AutoJoinHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for AutoJoinHandler {
|
impl EventEmitter for AutoJoinHandler {
|
||||||
async fn on_stripped_state_member(
|
async fn on_stripped_state_member(
|
||||||
&self,
|
&self,
|
||||||
room: Room,
|
room: RoomState,
|
||||||
room_member: &StrippedStateEvent<MemberEventContent>,
|
room_member: &StrippedStateEvent<MemberEventContent>,
|
||||||
_: Option<MemberEventContent>,
|
_: Option<MemberEventContent>,
|
||||||
) {
|
) {
|
||||||
|
@ -32,12 +31,9 @@ impl EventHandler for AutoJoinHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Room::Invited(room) = room {
|
if let RoomState::Invited(room) = room {
|
||||||
let room_id = room.room_id();
|
let room_id = room.room_id();
|
||||||
let room_name = room
|
let room_name = room.display_name().await;
|
||||||
.display_name()
|
|
||||||
.await
|
|
||||||
.expect("couldn't get joined room name!");
|
|
||||||
println!(
|
println!(
|
||||||
"Received invitation for room `{}`: `{}`",
|
"Received invitation for room `{}`: `{}`",
|
||||||
room_id, room_name
|
room_id, room_name
|
||||||
|
@ -48,14 +44,16 @@ impl EventHandler for AutoJoinHandler {
|
||||||
"Bot isn't authorized to join room `{}`, declining invitation",
|
"Bot isn't authorized to join room `{}`, declining invitation",
|
||||||
room_id
|
room_id
|
||||||
);
|
);
|
||||||
room.reject_invitation().await.unwrap();
|
// leaving a room is equivalent to rejecting the invitation, as per
|
||||||
|
// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-leave
|
||||||
|
self.client.leave_room(room_id).await.unwrap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Autojoining room {}", room.room_id());
|
println!("Autojoining room {}", room.room_id());
|
||||||
let mut delay = 2;
|
let mut delay = 2;
|
||||||
|
|
||||||
while let Err(err) = room.accept_invitation().await {
|
while let Err(err) = self.client.join_room_by_id(room.room_id()).await {
|
||||||
// retry autojoin due to synapse sending invites, before the
|
// retry autojoin due to synapse sending invites, before the
|
||||||
// invited user can join for more information see
|
// invited user can join for more information see
|
||||||
// https://github.com/matrix-org/synapse/issues/4345
|
// https://github.com/matrix-org/synapse/issues/4345
|
||||||
|
|
12
src/bot.rs
12
src/bot.rs
|
@ -4,7 +4,10 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
events::{room::message::MessageEventContent, AnyMessageEventContent},
|
events::{
|
||||||
|
room::message::{MessageEventContent, TextMessageEventContent},
|
||||||
|
AnyMessageEventContent,
|
||||||
|
},
|
||||||
Client, ClientConfig, Session, SyncSettings,
|
Client, ClientConfig, Session, SyncSettings,
|
||||||
};
|
};
|
||||||
use systemd::{journal, JournalRecord};
|
use systemd::{journal, JournalRecord};
|
||||||
|
@ -37,7 +40,7 @@ impl BadNewsBot {
|
||||||
load_or_init_session(&self).await?;
|
load_or_init_session(&self).await?;
|
||||||
|
|
||||||
self.client
|
self.client
|
||||||
.set_event_handler(Box::new(AutoJoinHandler::new(
|
.add_event_emitter(Box::new(AutoJoinHandler::new(
|
||||||
self.client.clone(),
|
self.client.clone(),
|
||||||
self.config.room_id.clone(),
|
self.config.room_id.clone(),
|
||||||
)))
|
)))
|
||||||
|
@ -118,8 +121,9 @@ impl BadNewsBot {
|
||||||
unit.strip_suffix(".service").unwrap_or(unit),
|
unit.strip_suffix(".service").unwrap_or(unit),
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
let content =
|
let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text(
|
||||||
AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain(message));
|
TextMessageEventContent::plain(message),
|
||||||
|
));
|
||||||
let room_id = self.config.room_id.clone();
|
let room_id = self.config.room_id.clone();
|
||||||
let client_clone = self.client.clone();
|
let client_clone = self.client.clone();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue