rename teams-bot to team-bot

This commit is contained in:
missytake 2024-02-03 17:21:58 +01:00
parent 15885c4dfc
commit 6f785969b3
13 changed files with 67 additions and 66 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ __pycache__/
/venv/ /venv/
bot.db/ bot.db/
teams_bot_data/ teams_bot_data/
team_bot_data/

View file

@ -1,4 +1,4 @@
# Teams Bot # Team Bot
This bot connects your team to the outside This bot connects your team to the outside
and makes it addressable. and makes it addressable.
@ -22,8 +22,8 @@ To install this bot,
run: run:
``` ```
git clone https://git.0x90.space/missytake/teams-bot git clone https://github.com/deltachat-bot/team-bot
cd teams-bot cd team-bot
pip install . pip install .
``` ```
@ -32,19 +32,19 @@ with an email address
you want to use as a team: you want to use as a team:
``` ```
teams-bot init --email helpdesk@example.org --password p455w0rD team-bot init --email helpdesk@example.org --password p455w0rD
``` ```
This command will show a QR code; This command will show a QR code;
scan it with Delta Chat scan it with Delta Chat
to become part of the "team", to become part of the "team",
the verified group which manages the Teams Bot. the verified group which manages the Team Bot.
Now to run it, Now to run it,
simply execute: simply execute:
``` ```
teams-bot run -v team-bot run -v
``` ```
The bot only works as long as this command is running. The bot only works as long as this command is running.
@ -59,9 +59,9 @@ you can deploy this bot with it.
Just import it into your [deploy.py file](https://docs.pyinfra.com/en/2.x/getting-started.html#create-a-deploy) like this: Just import it into your [deploy.py file](https://docs.pyinfra.com/en/2.x/getting-started.html#create-a-deploy) like this:
``` ```
from teams_bot.pyinfra import deploy_teams_bot from team_bot.pyinfra import deploy_team_bot
deploy_teams_bot( deploy_team_bot(
unix_user='root', # an existing UNIX user (doesn't need root or sudo privileges) unix_user='root', # an existing UNIX user (doesn't need root or sudo privileges)
bot_email='helpdesk@example.org', # the email address your team wants to use bot_email='helpdesk@example.org', # the email address your team wants to use
bot_passwd='p4ssw0rd', # the password to the email account bot_passwd='p4ssw0rd', # the password to the email account
@ -79,7 +79,7 @@ login to the user with ssh
and run: and run:
``` ```
export $(cat ~/.env | xargs) && ~/.local/lib/teams-bot.venv/bin/teams-bot init export $(cat ~/.env | xargs) && ~/.local/lib/team-bot.venv/bin/team-bot init
``` ```
Then, Then,
@ -88,11 +88,11 @@ and keep it running in the background,
run: run:
``` ```
systemctl --user enable --now teams-bot systemctl --user enable --now team-bot
``` ```
You can view the log output You can view the log output
with `journalctl --user -fu teams-bot` with `journalctl --user -fu team-bot`
to confirm that it works. to confirm that it works.
## Development Environment ## Development Environment

View file

@ -1,14 +1,14 @@
[metadata] [metadata]
name = teams-bot name = team-bot
version = 0.0.1 version = 0.0.1
author = missytake author = missytake
author_email = missytake@systemli.org author_email = missytake@systemli.org
description = This bot connects your team to the outside and makes it addressable. description = This bot connects your team to the outside and makes it addressable.
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown
url = https://git.0x90.space/missytake/teams-bot url = https://github.com/deltachat-bot/team-bot
project_urls = project_urls =
Bug Tracker = https://git.0x90.space/missytake/teams-bot/issues Bug Tracker = https://github.com/deltachat-bot/team-bot/issues
classifiers = classifiers =
Programming Language :: Python :: 3 Programming Language :: Python :: 3
License :: OSI Approved :: ISC License (ISCL) License :: OSI Approved :: ISC License (ISCL)
@ -31,7 +31,7 @@ where = src
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
teams-bot = teams_bot.cli:main team-bot = team_bot.cli:main
[tox:tox] [tox:tox]
envlist = lint, py310 envlist = lint, py310

View file

@ -239,12 +239,12 @@ class RelayPlugin:
if not chat.get_name().startswith( if not chat.get_name().startswith(
"[%s] " % (self.account.get_config("addr").split("@")[0],) "[%s] " % (self.account.get_config("addr").split("@")[0],)
): ):
return False # all relay groups' names begin with a [tag] with the localpart of the teamsbot's address return False # all relay groups' names begin with a [tag] with the localpart of the team-bot's address
if ( if (
chat.get_messages()[0].get_sender_contact() chat.get_messages()[0].get_sender_contact()
!= self.account.get_self_contact() != self.account.get_self_contact()
): ):
return False # all relay groups were started by the teamsbot return False # all relay groups were started by the team-bot
if chat.is_protected(): if chat.is_protected():
return False # relay groups don't need to be protected, so they are not return False # relay groups don't need to be protected, so they are not
for crew_member in self.crew.get_contacts(): for crew_member in self.crew.get_contacts():

View file

@ -29,11 +29,11 @@ def set_log_level(verbose: int, db: str):
cls=click.Group, context_settings={"help_option_names": ["-h", "--help"]} cls=click.Group, context_settings={"help_option_names": ["-h", "--help"]}
) )
@click.pass_context @click.pass_context
def teams_bot(ctx): def team_bot(ctx):
"""This bot connects your team to the outside and makes it addressable.""" """This bot connects your team to the outside and makes it addressable."""
@teams_bot.command() @team_bot.command()
@click.option("--email", type=str, default=None, help="the email account for the bot") @click.option("--email", type=str, default=None, help="the email account for the bot")
@click.option( @click.option(
"--password", type=str, default=None, help="the password of the email account" "--password", type=str, default=None, help="the password of the email account"
@ -41,7 +41,7 @@ def teams_bot(ctx):
@click.option( @click.option(
"--dbdir", "--dbdir",
type=str, type=str,
default="teams_bot_data", default="team_bot_data",
help="path to the bot's database", help="path to the bot's database",
envvar="TEAMS_DBDIR", envvar="TEAMS_DBDIR",
) )
@ -123,11 +123,11 @@ def init(ctx, email: str, password: str, dbdir: str, verbose: int):
logging.info("Successfully changed crew ID to the new group.") logging.info("Successfully changed crew ID to the new group.")
@teams_bot.command() @team_bot.command()
@click.option( @click.option(
"--dbdir", "--dbdir",
type=str, type=str,
default="teams_bot_data", default="team_bot_data",
help="path to the bot's database", help="path to the bot's database",
envvar="TEAMS_DBDIR", envvar="TEAMS_DBDIR",
) )
@ -157,11 +157,11 @@ def run(ctx, dbdir: str, verbose: int):
ac.wait_shutdown() ac.wait_shutdown()
@teams_bot.command() @team_bot.command()
@click.option( @click.option(
"--dbdir", "--dbdir",
type=str, type=str,
default="teams_bot_data", default="team_bot_data",
help="path to the bot's database", help="path to the bot's database",
envvar="TEAMS_DBDIR", envvar="TEAMS_DBDIR",
) )
@ -191,7 +191,7 @@ def verify_crypto(ctx, dbdir: str, verbose: int):
def main(): def main():
teams_bot(auto_envvar_prefix="TEAMS") team_bot(auto_envvar_prefix="TEAMS")
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -6,7 +6,7 @@ from pyinfra import host
from pyinfra.facts.systemd import SystemdStatus from pyinfra.facts.systemd import SystemdStatus
def deploy_teams_bot( def deploy_team_bot(
unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None
): ):
"""Deploy TeamsBot to a UNIX user, with specified credentials """Deploy TeamsBot to a UNIX user, with specified credentials
@ -14,13 +14,13 @@ def deploy_teams_bot(
:param unix_user: the existing UNIX user of the bot :param unix_user: the existing UNIX user of the bot
:param bot_email: the email address for the bot account :param bot_email: the email address for the bot account
:param bot_passwd: the password for the bot's email account :param bot_passwd: the password for the bot's email account
:param dbdir: the directory where the bot's data will be stored. default: ~/.config/teams-bot/email@example.org :param dbdir: the directory where the bot's data will be stored. default: ~/.config/team-bot/email@example.org
""" """
clone_repo = git.repo( clone_repo = git.repo(
name="Pull the teams-bot repository", name="Pull the team-bot repository",
src="https://git.0x90.space/missytake/teams-bot", src="https://github.com/deltachat-bot/team-bot",
dest=f"/home/{unix_user}/teams-bot", dest=f"/home/{unix_user}/team-bot",
rebase=True, rebase=True,
_su_user=unix_user, _su_user=unix_user,
_use_su_login=True, _use_su_login=True,
@ -28,7 +28,7 @@ def deploy_teams_bot(
if clone_repo.changed: if clone_repo.changed:
server.script( server.script(
name="Setup virtual environment for teams-bot", name="Setup virtual environment for team-bot",
src=importlib.resources.files(__package__) src=importlib.resources.files(__package__)
/ "pyinfra_assets" / "pyinfra_assets"
/ "setup-venv.sh", / "setup-venv.sh",
@ -37,16 +37,16 @@ def deploy_teams_bot(
) )
server.shell( server.shell(
name="Compile teams-bot", name="Compile team-bot",
commands=[ commands=[
f". .local/lib/teams-bot.venv/bin/activate && cd /home/{unix_user}/teams-bot && pip install ." f". .local/lib/team-bot.venv/bin/activate && cd /home/{unix_user}/team-bot && pip install ."
], ],
_su_user=unix_user, _su_user=unix_user,
_use_su_login=True, _use_su_login=True,
) )
if not dbdir: if not dbdir:
dbdir = f"/home/{unix_user}/.config/teams_bot/{bot_email}/" dbdir = f"/home/{unix_user}/.config/team_bot/{bot_email}/"
secrets = [ secrets = [
f"TEAMS_DBDIR={dbdir}", f"TEAMS_DBDIR={dbdir}",
f"TEAMS_INIT_EMAIL={bot_email}", f"TEAMS_INIT_EMAIL={bot_email}",
@ -70,18 +70,18 @@ def deploy_teams_bot(
) )
files.template( files.template(
name="upload teams-bot systemd unit", name="upload team-bot systemd unit",
src=importlib.resources.files(__package__) src=importlib.resources.files(__package__)
/ "pyinfra_assets" / "pyinfra_assets"
/ "teams-bot.service.j2", / "team-bot.service.j2",
dest=f"/home/{unix_user}/.config/systemd/user/teams-bot.service", dest=f"/home/{unix_user}/.config/systemd/user/team-bot.service",
user=unix_user, user=unix_user,
unix_user=unix_user, unix_user=unix_user,
bot_email=bot_email, bot_email=bot_email,
) )
systemd.daemon_reload( systemd.daemon_reload(
name=f"{unix_user}: load teams-bot systemd service", name=f"{unix_user}: load team-bot systemd service",
user_name=unix_user, user_name=unix_user,
user_mode=True, user_mode=True,
_su_user=unix_user, _su_user=unix_user,
@ -101,10 +101,10 @@ def deploy_teams_bot(
_use_su_login=True, _use_su_login=True,
) )
try: try:
if services["teams-bot.service"]: if services["team-bot.service"]:
systemd.service( systemd.service(
name=f"{unix_user}: restart teams-bot systemd service", name=f"{unix_user}: restart team-bot systemd service",
service="teams-bot.service", service="team-bot.service",
running=True, running=True,
restarted=True, restarted=True,
user_mode=True, user_mode=True,

View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
python3 -m venv ~/.local/lib/team-bot.venv
source ~/.local/lib/team-bot.venv/bin/activate
pip install -U pip wheel

View file

@ -1,8 +1,8 @@
[Unit] [Unit]
Description=run deltachat teams-bot: {{ bot_email }} Description=run deltachat team-bot: {{ bot_email }}
[Service] [Service]
ExecStart=/home/{{ unix_user }}/.local/lib/teams-bot.venv/bin/teams-bot run -v ExecStart=/home/{{ unix_user }}/.local/lib/team-bot.venv/bin/team-bot run -v
EnvironmentFile=/home/{{ unix_user }}/.env EnvironmentFile=/home/{{ unix_user }}/.env
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s

View file

@ -1,6 +0,0 @@
#!/usr/bin/env bash
python3 -m venv ~/.local/lib/teams-bot.venv
source ~/.local/lib/teams-bot.venv/bin/activate
pip install -U pip wheel

View file

@ -7,7 +7,7 @@ import deltachat
import pytest import pytest
from _pytest.pytester import LineMatcher from _pytest.pytester import LineMatcher
from teams_bot.bot import RelayPlugin from team_bot.bot import RelayPlugin
class ClickRunner: class ClickRunner:
@ -65,9 +65,9 @@ def _perform_match(output, fnl):
@pytest.fixture @pytest.fixture
def cmd(): def cmd():
"""invoke a command line subcommand.""" """invoke a command line subcommand."""
from teams_bot.cli import teams_bot from team_bot.cli import team_bot
return ClickRunner(teams_bot) return ClickRunner(team_bot)
@pytest.fixture @pytest.fixture
@ -88,28 +88,28 @@ def relaycrew(crew):
@pytest.fixture @pytest.fixture
def crew(teams_bot, teams_user, tmpdir): def crew(team_bot, team_user, tmpdir):
from teams_bot.bot import SetupPlugin from team_bot.bot import SetupPlugin
crew = teams_bot.create_group_chat( crew = team_bot.create_group_chat(
f"Team: {teams_bot.get_config('addr')}", verified=True f"Team: {team_bot.get_config('addr')}", verified=True
) )
setupplugin = SetupPlugin(crew.id) setupplugin = SetupPlugin(crew.id)
teams_bot.add_account_plugin(setupplugin) team_bot.add_account_plugin(setupplugin)
qr = crew.get_join_qr() qr = crew.get_join_qr()
teams_user.qr_join_chat(qr) team_user.qr_join_chat(qr)
setupplugin.member_added.wait(timeout=30) setupplugin.member_added.wait(timeout=30)
crew.user = teams_user crew.user = team_user
crew.bot = teams_bot crew.bot = team_bot
crew.bot.setupplugin = setupplugin crew.bot.setupplugin = setupplugin
# wait until old user is properly added to crew # wait until old user is properly added to crew
last_message = teams_user.wait_next_incoming_message().text last_message = team_user.wait_next_incoming_message().text
while ( while (
f"Member Me ({teams_user.get_config('addr')}) added by bot" not in last_message f"Member Me ({team_user.get_config('addr')}) added by bot" not in last_message
): ):
print("User received message:", last_message) print("User received message:", last_message)
last_message = teams_user.wait_next_incoming_message().text last_message = team_user.wait_next_incoming_message().text
crew.kvstore = pickledb.load(tmpdir + "pickle.db", True) crew.kvstore = pickledb.load(tmpdir + "pickle.db", True)
crew.kvstore.set("crew_id", crew.id) crew.kvstore.set("crew_id", crew.id)
@ -117,7 +117,7 @@ def crew(teams_bot, teams_user, tmpdir):
@pytest.fixture @pytest.fixture
def teams_bot(tmpdir): def team_bot(tmpdir):
ac = account(tmpdir + "/bot.sqlite", show_ffi=True) ac = account(tmpdir + "/bot.sqlite", show_ffi=True)
yield ac yield ac
ac.shutdown() ac.shutdown()
@ -125,7 +125,7 @@ def teams_bot(tmpdir):
@pytest.fixture @pytest.fixture
def teams_user(tmpdir): def team_user(tmpdir):
ac = account(tmpdir + "/user.sqlite") ac = account(tmpdir + "/user.sqlite")
yield ac yield ac
ac.shutdown() ac.shutdown()

View file

@ -2,7 +2,7 @@ def test_help(cmd):
cmd.run_ok( cmd.run_ok(
[], [],
""" """
Usage: teams-bot [OPTIONS] COMMAND [ARGS]... Usage: team-bot [OPTIONS] COMMAND [ARGS]...
* -h, --help Show this message and exit. * -h, --help Show this message and exit.
* init Scan a QR code to create a crew and join it * init Scan a QR code to create a crew and join it
* run Run the bot, so it relays messages from and to the outside * run Run the bot, so it relays messages from and to the outside