Skip to content

Commit fa9ddd4

Browse files
authored
Merge pull request #11 from v411e/develop
Fix: Use access token instead of deprecated email/password
2 parents 422caf8 + c931efe commit fa9ddd4

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Create a `config.yaml` and a `auth.yaml` file in `./config/`. Enter the credenti
3131
# Credentials for your bot account
3232
bot_account:
3333
server: "mastodon.example.com"
34-
email: "hypebot@example.com"
35-
password: "averylongandsecurepassword"
34+
access_token: "Create a new application in your bot account at Preferences -> Development"
3635
```
3736

3837
`config.yaml`
@@ -46,7 +45,7 @@ profile_prefix: "I am boosting trending posts from:"
4645
4746
# profile fields to fill in
4847
fields:
49-
code: https://github.com/tante/hype
48+
code: https://github.com/v411e/hype
5049
operator: "YOUR HANDLE HERE"
5150
5251
# Define subscribed instances and

config/auth.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Credentials for your bot account
22
bot_account:
33
server: ""
4-
email: ""
5-
password: ""
4+
access_token: ""

hype/config.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66

77
class BotAccount:
88
server: str
9-
email: str
10-
password: str
9+
access_token: str
1110

12-
def __init__(self, server: str, email: str, password: str) -> None:
11+
def __init__(self, server: str, access_token: str) -> None:
1312
self.server = server
14-
self.email = email
15-
self.password = password
13+
self.access_token = access_token
1614

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

2018

2119
class Instance:
@@ -53,13 +51,11 @@ def __init__(self):
5351
config
5452
and config.get("bot_account")
5553
and config["bot_account"].get("server")
56-
and config["bot_account"].get("email")
57-
and config["bot_account"].get("password")
54+
and config["bot_account"].get("access_token")
5855
):
5956
self.bot_account = BotAccount(
6057
server=config["bot_account"]["server"],
61-
email=config["bot_account"]["email"],
62-
password=config["bot_account"]["password"],
58+
access_token=config["bot_account"]["access_token"],
6359
)
6460
else:
6561
logging.getLogger("Config").error(config)

hype/hype.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ def __init__(self, config: Config) -> None:
2020
self.log.info("Config loaded")
2121

2222
def login(self):
23-
self.client = self.init_client(self.config.bot_account.server)
2423
self.log.info(f"Logging in to {self.config.bot_account.server}")
25-
self.client.log_in(
26-
self.config.bot_account.email,
27-
self.config.bot_account.password,
28-
to_file=f"secrets/{self.config.bot_account.server}_usercred.secret",
29-
)
24+
self.client = Mastodon(
25+
api_base_url=self.config.bot_account.server,
26+
access_token=self.config.bot_account.access_token
27+
)
3028

3129
def update_profile(self):
3230
self.log.info("Update bot profile")

0 commit comments

Comments
 (0)