From 736ba02520802499c9970afd9d1ee6a537fb2230 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 22 Feb 2023 23:51:49 -0800 Subject: bot: set default toot visibility to private --- callback.py | 10 ++++------ command.py | 1 - config.py | 1 - dbstore/peewee_store.py | 6 ++++++ 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 from telegram import ReplyKeyboardRemove from telegram.constants import ChatAction -from telegram.error import BadRequest from telegram.ext import CallbackContext from command import * @@ -11,8 +10,9 @@ from dbstore.peewee_store import get_poi_by_fsq_id from foursquare.poi import OSM_ENDPOINT from foursquare.poi import query_poi from config import BOT_SCOPE -from dbstore.peewee_store import User, db +from dbstore.peewee_store import User, db, TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_PUBLIC, TOOT_VISIBILITY_UNLISTED import uuid +from mastodon import Mastodon def generate_uuid(): @@ -79,8 +79,6 @@ async def callback_generate_fedi_login_url(update: Update, context: ContextTypes redirect_uris="{}{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), api_base_url=home_instance, ) - print("client_id: {}".format(client_id)) - print("client_secret: {}".format(client_secret)) m = Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=home_instance) @@ -115,7 +113,7 @@ async def callback_location_sharing(update: Update, context: ContextTypes.DEFAUL poi = get_poi_by_fsq_id(context.user_data.get("fsq_id")) content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) - status = get_mastodon_client(update.effective_user.id).status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) + status = get_mastodon_client(update.effective_user.id).status_post(content, visibility=TOOT_VISIBILITY_PRIVATE, media_ids=[]) context.user_data[KEY_TOOT_STATUS_ID] = status["id"] context.user_data[KEY_TOOT_STATUS_CONTENT] = content @@ -190,7 +188,7 @@ async def _process_location_selection(context: ContextTypes.DEFAULT_TYPE) -> int else: content = generate_toot_text(poi_name, "", "", context.user_data.get("latitude"), context.user_data.get("longitude")) - status = get_mastodon_client(context.user_data["user_id"]).status_post(content, visibility=DEFAULT_TOOT_VISIBILITY, media_ids=[]) + status = get_mastodon_client(context.user_data["user_id"]).status_post(content, visibility=TOOT_VISIBILITY_PRIVATE, media_ids=[]) context.user_data[KEY_TOOT_STATUS_ID] = status["id"] context.user_data[KEY_TOOT_STATUS_CONTENT] = content diff --git a/command.py b/command.py index e45a2e2..901b792 100644 --- a/command.py +++ b/command.py @@ -4,7 +4,6 @@ from telegram.error import BadRequest from telegram.ext import ContextTypes, ConversationHandler from config import * -from mastodon import Mastodon async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: diff --git a/config.py b/config.py index 3b5767b..9e72598 100644 --- a/config.py +++ b/config.py @@ -16,7 +16,6 @@ TOOT_CLIENT_ID = config["TOOT"]["CLIENT_ID"] TOOT_CLIENT_SECRET = config["TOOT"]["CLIENT_SECRET"] TOOT_ACCESS_TOKEN = config["TOOT"]["ACCESS_TOKEN"] -DEFAULT_TOOT_VISIBILITY = "private" MEDIA_GROUP_TIMEOUT = 3 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 @@ from peewee import * +TOOT_VISIBILITY_PUBLIC = "public" +TOOT_VISIBILITY_UNLISTED = "unlisted" +TOOT_VISIBILITY_PRIVATE = "private" + + db = SqliteDatabase("checkinbot.db") db.connect(reuse_if_open=True) @@ -16,6 +21,7 @@ class User(BaseModel): state = CharField(max_length=128) client_id = CharField(max_length=128) client_secret = CharField(max_length=128) + toot_visibility = CharField(max_length=128, default=TOOT_VISIBILITY_PRIVATE) 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): locations = list() url = POI_SEARCH_API_ENDPOINT.format(search, latitude, longitude) - print(url) response = requests.get(url, headers=headers) for poi in json.loads(response.text)["results"]: -- cgit v1.2.3