1
0
Fork 0
forked from vbatts/maubot

Add stuff

This commit is contained in:
Tulir Asokan 2018-12-13 01:28:23 +02:00
parent 4b3d47176d
commit 8e2f2908a6
16 changed files with 258 additions and 1 deletions

View file

@ -0,0 +1 @@
from . import upload, build, login, init

View file

@ -0,0 +1,31 @@
# maubot - A plugin-based Matrix bot system.
# Copyright (C) 2018 Tulir Asokan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import click
import os
from ..base import app
from ..util import type_path
@app.command(short_help="Build a maubot plugin",
help="Build a maubot plugin. First parameter is the path to root of the plugin "
"to build. You can also use --output to specify output file.")
@click.argument("path", default=".")
@click.option("-o", "--output", help="Path to output built plugin to", type=type_path)
@click.option("-u", "--upload", help="Upload plugin to main server after building", is_flag=True,
default=False)
def build(path: str, output: str, upload: bool) -> None:
pass

View file

@ -0,0 +1,34 @@
# maubot - A plugin-based Matrix bot system.
# Copyright (C) 2018 Tulir Asokan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import click
import os
from ..base import app
from ..util import type_path
@app.command(help="Initialize a new maubot plugin")
@click.option("-n", "--name", help="The name of the project", default=os.path.basename(os.getcwd()),
prompt=True, show_default="directory name")
@click.option("-i", "--id", help="The maubot plugin ID (Java package name format)", prompt=True)
@click.option("-v", "--version", help="Initial version for project", default="0.1.0",
show_default=True)
@click.option("-l", "--license", help="The SPDX license identifier of the license for the project",
prompt=True, default="AGPL-3.0-or-later")
@click.option("-c", "--config", help="Include a config in the plugin stub", is_flag=True,
default=False)
def init(name: str, id: str, version: str, license: str, config: bool) -> None:
pass

View file

@ -0,0 +1,48 @@
# maubot - A plugin-based Matrix bot system.
# Copyright (C) 2018 Tulir Asokan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from urllib.request import urlopen
from urllib.error import HTTPError
import click
import json
import os
from colorama import Fore, Style
from maubot.cli.base import app
from maubot.cli.config import save_config, config
@app.command(help="Log in to a Maubot instance")
@click.argument("server", required=True, default="http://localhost:29316")
@click.option("-u", "--username", help="The username of your account", prompt=True,
default=lambda: os.environ.get('USER', ''), show_default="current user")
@click.password_option("-p", "--password", help="The password to your account", required=True,
confirmation_prompt=False)
def login(server, username, password) -> None:
data = {
"username": username,
"password": password,
}
try:
with urlopen(f"{server}/_matrix/maubot/v1/auth/login",
data=json.dumps(data).encode("utf-8")) as resp_data:
resp = json.load(resp_data)
config["servers"][server] = resp["token"]
save_config()
print(Fore.GREEN, "Logged in successfully")
except HTTPError as e:
if e.code == 401:
print(Fore.RED + "Invalid username or password" + Style.RESET_ALL)

View file

@ -0,0 +1,25 @@
# maubot - A plugin-based Matrix bot system.
# Copyright (C) 2018 Tulir Asokan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import click
import os
from maubot.cli.base import app
@app.command(help="Upload a maubot plugin")
@click.option("-s", "--server", help="The maubot instance to upload the plugin to")
def upload(server: str) -> None:
pass