ignore groupchats
This commit is contained in:
parent
3faeabb788
commit
f9b45edd54
14
main.py
14
main.py
|
|
@ -1,3 +1,4 @@
|
||||||
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
@ -21,6 +22,14 @@ link_regex = re.compile(
|
||||||
'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)', re.DOTALL)
|
'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)', re.DOTALL)
|
||||||
|
|
||||||
|
|
||||||
|
def private_only(f):
|
||||||
|
@wraps(f)
|
||||||
|
def cb(update: Update, *args, **kwargs):
|
||||||
|
if update.effective_chat.type != 'private':
|
||||||
|
return
|
||||||
|
return f(update, *args, **kwargs)
|
||||||
|
return cb
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BotSettings:
|
class BotSettings:
|
||||||
token: str
|
token: str
|
||||||
|
|
@ -41,7 +50,7 @@ class Bot:
|
||||||
for f in dir(self):
|
for f in dir(self):
|
||||||
if f.startswith("cmd_"):
|
if f.startswith("cmd_"):
|
||||||
self.dispatcher.add_handler(
|
self.dispatcher.add_handler(
|
||||||
CommandHandler(f[4:], getattr(self, f)))
|
CommandHandler(f[4:], private_only(getattr(self, f))))
|
||||||
|
|
||||||
def _register_handlers(self):
|
def _register_handlers(self):
|
||||||
self.dispatcher.add_handler(MessageHandler(
|
self.dispatcher.add_handler(MessageHandler(
|
||||||
|
|
@ -90,7 +99,10 @@ class Bot:
|
||||||
return f"{n} {singular}"
|
return f"{n} {singular}"
|
||||||
return f"{n} {plural}"
|
return f"{n} {plural}"
|
||||||
|
|
||||||
|
@private_only
|
||||||
def message(self, update: Update, context: CallbackContext):
|
def message(self, update: Update, context: CallbackContext):
|
||||||
|
if update.effective_chat.type != 'private':
|
||||||
|
return
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
links = re.findall(link_regex, update.message.text)
|
links = re.findall(link_regex, update.message.text)
|
||||||
with self.db as db:
|
with self.db as db:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue