Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ Create a `config.yaml` and a `auth.yaml` file in `./config/`. Enter the credenti
# Credentials for your bot account
bot_account:
server: "mastodon.example.com"
email: "hypebot@example.com"
password: "averylongandsecurepassword"
access_token: "Create a new application in your bot account at Preferences -> Development"
```

`config.yaml`
Expand All @@ -46,7 +45,7 @@ profile_prefix: "I am boosting trending posts from:"

# profile fields to fill in
fields:
code: https://github.com/tante/hype
code: https://github.com/v411e/hype
operator: "YOUR HANDLE HERE"

# Define subscribed instances and
Expand Down
3 changes: 1 addition & 2 deletions config/auth.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Credentials for your bot account
bot_account:
server: ""
email: ""
password: ""
access_token: ""
16 changes: 6 additions & 10 deletions hype/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

class BotAccount:
server: str
email: str
password: str
access_token: str

def __init__(self, server: str, email: str, password: str) -> None:
def __init__(self, server: str, access_token: str) -> None:
self.server = server
self.email = email
self.password = password
self.access_token = access_token

def __repr__(self) -> str:
return f"server: {self.server}, email: {self.email}, password: {self.password}"
return f"server: {self.server}, access_token: {self.access_token}"


class Instance:
Expand Down Expand Up @@ -53,13 +51,11 @@ def __init__(self):
config
and config.get("bot_account")
and config["bot_account"].get("server")
and config["bot_account"].get("email")
and config["bot_account"].get("password")
and config["bot_account"].get("access_token")
):
self.bot_account = BotAccount(
server=config["bot_account"]["server"],
email=config["bot_account"]["email"],
password=config["bot_account"]["password"],
access_token=config["bot_account"]["access_token"],
)
else:
logging.getLogger("Config").error(config)
Expand Down
10 changes: 4 additions & 6 deletions hype/hype.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ def __init__(self, config: Config) -> None:
self.log.info("Config loaded")

def login(self):
self.client = self.init_client(self.config.bot_account.server)
self.log.info(f"Logging in to {self.config.bot_account.server}")
self.client.log_in(
self.config.bot_account.email,
self.config.bot_account.password,
to_file=f"secrets/{self.config.bot_account.server}_usercred.secret",
)
self.client = Mastodon(
api_base_url=self.config.bot_account.server,
access_token=self.config.bot_account.access_token
)

def update_profile(self):
self.log.info("Update bot profile")
Expand Down