mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-08-17 18:38:11 +02:00
fix: use Mastodon character counter
This commit is contained in:
+1
-1
@@ -15,6 +15,7 @@ decorator==5.3.1
|
||||
demoji==2.0.0
|
||||
deepl==1.30.0
|
||||
future==1.0.0
|
||||
grapheme==0.6.0
|
||||
idna==3.18
|
||||
importlib-metadata==9.0.0
|
||||
iniconfig==2.3.0
|
||||
@@ -48,7 +49,6 @@ six==1.17.0
|
||||
sniffio==1.3.1
|
||||
sound_lib @ git+https://github.com/accessibleapps/sound_lib@a439f0943fb95ee7b6ba24f51a686f47c4ad66b2
|
||||
sqlitedict==2.1.0
|
||||
twitter-text-parser==3.0.0
|
||||
types-python-dateutil==2.9.0.20260807
|
||||
urllib3==2.7.0
|
||||
win-inet-pton==1.1.0
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
import wx
|
||||
import logging
|
||||
import widgetUtils
|
||||
import config
|
||||
import output
|
||||
import languageHandler
|
||||
from twitter_text import parse_tweet, config
|
||||
from mastodon import MastodonError
|
||||
from mastodon import Mastodon, MastodonError
|
||||
from controller import messages
|
||||
from sessions.mastodon import templates, utils
|
||||
from wxUI.dialogs.mastodon import postDialogs
|
||||
@@ -17,18 +15,9 @@ from . import userList
|
||||
|
||||
log = logging.getLogger("controller.mastodon.messages")
|
||||
|
||||
def character_count(post_text, post_cw, character_limit=500):
|
||||
# We will use text for counting character limit only.
|
||||
full_text = post_text+post_cw
|
||||
# find remote users as Mastodon doesn't count the domain in char limit.
|
||||
users = re.findall("@[\w\.-]+@[\w\.-]+", full_text)
|
||||
for user in users:
|
||||
domain = user.split("@")[-1]
|
||||
full_text = full_text.replace("@"+domain, "")
|
||||
options = config.config.get("defaults")
|
||||
options.update(max_weighted_tweet_length=character_limit, default_weight=100)
|
||||
parsed = parse_tweet(full_text, options=options)
|
||||
return parsed.weightedLength
|
||||
def character_count(post_text, post_cw):
|
||||
"""Return the Mastodon-compatible length of a status and its content warning."""
|
||||
return Mastodon.get_status_length(post_text, post_cw)
|
||||
|
||||
class post(messages.basicMessage):
|
||||
def __init__(self, session, title, caption, text="", *args, **kwargs):
|
||||
@@ -121,7 +110,7 @@ class post(messages.basicMessage):
|
||||
def text_processor(self, *args, **kwargs):
|
||||
text = self.message.text.GetValue()
|
||||
cw = self.message.spoiler.GetValue()
|
||||
results = character_count(text, cw, character_limit=self.max)
|
||||
results = character_count(text, cw)
|
||||
self.message.SetTitle(_("%s - %s of %d characters") % (self.title, results, self.max))
|
||||
if results > self.max:
|
||||
self.session.sound.play("max_length.ogg")
|
||||
|
||||
Reference in New Issue
Block a user