Add nostr login and periodic vote-beta announcements

This commit is contained in:
2026-09-04 11:56:39 -05:00
parent 5dde44e98e
commit ca44cf73df
14 changed files with 1775 additions and 108 deletions
+43
View File
@@ -43,6 +43,7 @@ class Config:
self.post_loop_interval = config.get("post_loop_interval", 1)
self.user_list_interval = config.get("user_list_interval", 300)
self.user_list_retry_interval = config.get("user_list_retry_interval", 60)
self.suggestion_announce_interval = config.get("suggestion_announce_interval", 0)
class Room:
def __init__(self, config_path="configs/config.yaml", search_terms=None, homeserver=None):
@@ -67,6 +68,7 @@ class Room:
self.banned_db_path = "banned_users.db"
self.init_db()
self.init_banned_db()
self.init_suggestion_counter_db()
def safe_db_name(self, room_id):
@@ -193,6 +195,47 @@ class Room:
dbutil.commit(conn)
conn.close()
def init_suggestion_counter_db(self):
"""Initialize the suggestion counter table for periodic announcements."""
conn = dbutil.connect(self.db_path)
c = conn.cursor()
_ = c.execute('''
CREATE TABLE IF NOT EXISTS suggestion_counter (
id INTEGER PRIMARY KEY CHECK (id = 1),
count INTEGER DEFAULT 0
)
''')
_ = c.execute('INSERT OR IGNORE INTO suggestion_counter (id, count) VALUES (1, 0)')
dbutil.commit(conn)
conn.close()
def get_suggestion_counter(self):
conn = dbutil.connect(self.db_path)
c = conn.cursor()
_ = c.execute('SELECT count FROM suggestion_counter WHERE id = 1')
row = c.fetchone()
conn.close()
return row[0] if row else 0
def increment_suggestion_counter(self, amount=1):
conn = dbutil.connect(self.db_path)
c = conn.cursor()
_ = c.execute('UPDATE suggestion_counter SET count = count + ? WHERE id = 1', (amount,))
dbutil.commit(conn)
conn.close()
return self.get_suggestion_counter()
async def check_and_announce_vote_beta(self, new_count):
"""Post a beta announcement if the suggestion count hits the configured interval."""
interval = self.config.suggestion_announce_interval
if interval <= 0:
return
if new_count > 0 and new_count % interval == 0:
url = self.vote_url()
await self.alert_post(
f"Psst! HTTP voting is now in beta! You can vote on titles at:\n{url}"
)
async def reject_banned_suggestion(self, post):
"""Reply to a banned user's suggestion and do not insert it."""
await self.alert_post(f"{post.display_name}: this user has been banned from submitting titles")