Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new plugin unique, to check last messages #579

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions tgcf/plugin_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Caption(BaseModel):
header: str = ""
footer: str = ""

class Unique(BaseModel):
check: bool = False

class Sender(BaseModel):
check: bool = False
user_type: int = 0 # 0:bot, 1:user
Expand All @@ -94,6 +97,7 @@ class PluginConfig(BaseModel):
ocr: OcrConfig = OcrConfig()
replace: Replace = Replace()
caption: Caption = Caption()
unique: Unique = Unique()
sender: Sender = Sender()


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 @@ -163,6 +163,11 @@
"You can have blank lines inside header and footer, to make space between the orignal message and captions."
)

with st.expander("Unique"):
CONFIG.plugins.unique.check = st.checkbox(
"Use this plugin: unique", value=CONFIG.plugins.unique.check
)

with st.expander("Sender"):
st.write("Modify the sender of forwarded messages other than the current user/bot")
st.warning("Show 'Forwarded from' option must be disabled or else messages will not be sent",icon="⚠️")
Expand Down