Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tgcf/plugin_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Caption(BaseModel):
header: str = ""
footer: str = ""

class Unique(BaseModel):
check: bool = False

class Sender(BaseModel):
check: bool = False
Expand All @@ -104,6 +106,7 @@ class PluginConfig(BaseModel):
ocr: OcrConfig = OcrConfig()
replace: Replace = Replace()
caption: Caption = Caption()
unique: Unique = Unique()
sender: Sender = Sender()
gsheet_logger: GsheetLogger = GsheetLogger()

Expand Down
29 changes: 29 additions & 0 deletions tgcf/plugins/unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logging

from pydantic import BaseModel # pylint: disable=no-name-in-module

from tgcf.plugins import TgcfMessage, TgcfPlugin


class TgcfUnique(TgcfPlugin):
id_ = "unique"

def __init__(self, data) -> None:
self.max = 5
self.messages = []

def modify(self, tm: TgcfMessage) -> TgcfMessage:
if self.text_unique(tm):
logging.info("Message passed unique filter")
self.include_message(tm)
return tm

def text_unique(self, tm: TgcfMessage) -> bool:
return tm.raw_text not in self.messages

def include_message(self, tm: TgcfMessage):
self.messages.insert(0, tm.raw_text)
if len(self.messages) > self.max:
self.messages.pop()
logging.info("Too many messages. Remove 1 oldest")

5 changes: 5 additions & 0 deletions tgcf/web_ui/pages/4_🔌_Plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
"You can have blank lines inside header and footer, to make space between the orignal message and captions."
)

with st.expander("Unique"):
pc.unique.check = st.checkbox(
"Check if message is unique", value=pc.unique.check, key=f"apply unique {i}"
)

with st.expander("Sender"):
st.write(
"Modify the sender of forwarded messages other than the current user/bot"
Expand Down