diff options
author | clarkzjw <[email protected]> | 2023-02-22 23:51:49 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-23 12:07:32 -0800 |
commit | 736ba02520802499c9970afd9d1ee6a537fb2230 (patch) | |
tree | 4a26d357ef482e42f4fe2a77c0ad5418248bcdb1 | |
parent | b935ae39c533bfdee7d052acdf939b68833a882a (diff) | |
download | swarm2fediverse-736ba02520802499c9970afd9d1ee6a537fb2230.tar.gz |
bot: set default toot visibility to private
-rw-r--r-- | callback.py | 10 | ||||
-rw-r--r-- | command.py | 1 | ||||
-rw-r--r-- | config.py | 1 | ||||
-rw-r--r-- | dbstore/peewee_store.py | 6 | ||||
-rw-r--r-- | foursquare/poi.py | 1 |
5 files changed, 10 insertions, 9 deletions
diff --git a/callback.py b/callback.py index 4fe0540..aca8a90 100644 --- a/callback.py +++ b/callback.py | |||
@@ -3,7 +3,6 @@ from typing import cast, List | |||
3 | 3 | ||
4 | from telegram import ReplyKeyboardRemove | 4 | from telegram import ReplyKeyboardRemove |
5 | from telegram.constants import ChatAction | 5 | from telegram.constants import ChatAction |
6 | from telegram.error import BadRequest | ||
7 | from telegram.ext import CallbackContext | 6 | from telegram.ext import CallbackContext |
8 | 7 | ||
9 | from command import * | 8 | from command import * |
@@ -11,8 +10,9 @@ from dbstore.peewee_store import get_poi_by_fsq_id | |||
11 | from foursquare.poi import OSM_ENDPOINT | 10 | from foursquare.poi import OSM_ENDPOINT |
12 | from foursquare.poi import query_poi | 11 | from foursquare.poi import query_poi |
13 | from config import BOT_SCOPE | 12 | from config import BOT_SCOPE |
14 | from dbstore.peewee_store import User, db | 13 | from dbstore.peewee_store import User, db, TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_PUBLIC, TOOT_VISIBILITY_UNLISTED |
15 | import uuid | 14 | import uuid |
15 | from mastodon import Mastodon | ||
16 | 16 | ||
17 | 17 | ||
18 | def generate_uuid(): | 18 | def generate_uuid(): |
@@ -79,8 +79,6 @@ async def callback_generate_fedi_login_url(update: Update, context: ContextTypes | |||
79 | redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), | 79 | redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), |
80 | api_base_url=home_instance, | 80 | api_base_url=home_instance, |
81 | ) | 81 | ) |
82 | print("client_id: {}".format(client_id)) | ||
83 | print("client_secret: {}".format(client_secret)) | ||
84 | 82 | ||
85 | m = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) | 83 | m = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) |
86 | 84 | ||
@@ -115,7 +113,7 @@ async def callback_location_sharing(update: Update, context: ContextTypes.DEFAUL | |||
115 | 113 | ||
116 | poi = get_poi_by_fsq_id(context.user_data.get("fsq_id")) | 114 | poi = get_poi_by_fsq_id(context.user_data.get("fsq_id")) |
117 | content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) | 115 | content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) |
118 | status = get_mastodon_client(update.effective_user.id).status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) | 116 | status = get_mastodon_client(update.effective_user.id).status_post(content, visibility=TOOT_VISIBILITY_PRIVATE, media_ids=[]) |
119 | 117 | ||
120 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] | 118 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] |
121 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content | 119 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content |
@@ -190,7 +188,7 @@ async def _process_location_selection(context: ContextTypes.DEFAULT_TYPE) -> int | |||
190 | else: | 188 | else: |
191 | content = generate_toot_text(poi_name, "", "", context.user_data.get("latitude"), context.user_data.get("longitude")) | 189 | content = generate_toot_text(poi_name, "", "", context.user_data.get("latitude"), context.user_data.get("longitude")) |
192 | 190 | ||
193 | status = get_mastodon_client(context.user_data["user_id"]).status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) | 191 | status = get_mastodon_client(context.user_data["user_id"]).status_post(content, visibility=TOOT_VISIBILITY_PRIVATE, media_ids=[]) |
194 | 192 | ||
195 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] | 193 | context.user_data[KEY_TOOT_STATUS_ID] = status["id"] |
196 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content | 194 | context.user_data[KEY_TOOT_STATUS_CONTENT] = content |
@@ -4,7 +4,6 @@ from telegram.error import BadRequest | |||
4 | from telegram.ext import ContextTypes, ConversationHandler | 4 | from telegram.ext import ContextTypes, ConversationHandler |
5 | 5 | ||
6 | from config import * | 6 | from config import * |
7 | from mastodon import Mastodon | ||
8 | 7 | ||
9 | 8 | ||
10 | async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 9 | async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
@@ -16,7 +16,6 @@ TOOT_CLIENT_ID = config["TOOT"]["CLIENT_ID"] | |||
16 | TOOT_CLIENT_SECRET = config["TOOT"]["CLIENT_SECRET"] | 16 | TOOT_CLIENT_SECRET = config["TOOT"]["CLIENT_SECRET"] |
17 | TOOT_ACCESS_TOKEN = config["TOOT"]["ACCESS_TOKEN"] | 17 | TOOT_ACCESS_TOKEN = config["TOOT"]["ACCESS_TOKEN"] |
18 | 18 | ||
19 | DEFAULT_TOOT_VISIBILITY = "private" | ||
20 | 19 | ||
21 | MEDIA_GROUP_TIMEOUT = 3 | 20 | MEDIA_GROUP_TIMEOUT = 3 |
22 | 21 | ||
diff --git a/dbstore/peewee_store.py b/dbstore/peewee_store.py index 37b8c01..00897d7 100644 --- a/dbstore/peewee_store.py +++ b/dbstore/peewee_store.py | |||
@@ -1,5 +1,10 @@ | |||
1 | from peewee import * | 1 | from peewee import * |
2 | 2 | ||
3 | TOOT_VISIBILITY_PUBLIC = "public" | ||
4 | TOOT_VISIBILITY_UNLISTED = "unlisted" | ||
5 | TOOT_VISIBILITY_PRIVATE = "private" | ||
6 | |||
7 | |||
3 | db = SqliteDatabase("checkinbot.db") | 8 | db = SqliteDatabase("checkinbot.db") |
4 | db.connect(reuse_if_open=True) | 9 | db.connect(reuse_if_open=True) |
5 | 10 | ||
@@ -16,6 +21,7 @@ class User(BaseModel): | |||
16 | state = CharField(max_length=128) | 21 | state = CharField(max_length=128) |
17 | client_id = CharField(max_length=128) | 22 | client_id = CharField(max_length=128) |
18 | client_secret = CharField(max_length=128) | 23 | client_secret = CharField(max_length=128) |
24 | toot_visibility = CharField(max_length=128, default=TOOT_VISIBILITY_PRIVATE) | ||
19 | 25 | ||
20 | 26 | ||
21 | class Location(BaseModel): | 27 | class Location(BaseModel): |
diff --git a/foursquare/poi.py b/foursquare/poi.py index 45b4fa9..4ff11fb 100644 --- a/foursquare/poi.py +++ b/foursquare/poi.py | |||
@@ -19,7 +19,6 @@ def query_poi(search, latitude, longitude): | |||
19 | locations = list() | 19 | locations = list() |
20 | 20 | ||
21 | url = POI_SEARCH_API_ENDPOINT.format(search, latitude, longitude) | 21 | url = POI_SEARCH_API_ENDPOINT.format(search, latitude, longitude) |
22 | print(url) | ||
23 | response = requests.get(url, headers=headers) | 22 | response = requests.get(url, headers=headers) |
24 | 23 | ||
25 | for poi in json.loads(response.text)["results"]: | 24 | for poi in json.loads(response.text)["results"]: |