forked from rDrama/rDrama
1
0
Fork 0

add kicking

master
Aevann 2024-03-10 21:44:57 +02:00
parent e1a37706b6
commit 018cde58c1
2 changed files with 21 additions and 12 deletions

View File

@ -12,6 +12,7 @@ mention_regex = re.compile('(?<![:/\w])@([\w-]{1,30})' + NOT_IN_CODE_OR_LINKS, f
group_mention_regex = re.compile('(?<![:/\w])!([\w-]{3,25})' + NOT_IN_CODE_OR_LINKS, flags=re.A|re.I)
chat_adding_regex = re.compile('\+@[\w-]{1,30}' + NOT_IN_CODE_OR_LINKS, flags=re.A)
chat_kicking_regex = re.compile('\-@[\w-]{1,30}' + NOT_IN_CODE_OR_LINKS, flags=re.A)
everyone_regex = re.compile('(^|\s|>)!(everyone)' + NOT_IN_CODE_OR_LINKS, flags=re.A)

View File

@ -135,18 +135,26 @@ def speak(data, v):
g.db.add(chat_message)
g.db.flush()
if v.id == chat.owner_id and chat_adding_regex.fullmatch(text):
user = get_user(text[2:], graceful=True, attributes=[User.id])
if user and not user.has_muted(v) and not user.has_blocked(v):
existing = g.db.query(ChatMembership.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
leave = g.db.query(ChatLeave.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
if not existing and not leave:
chat_membership = ChatMembership(
user_id=user.id,
chat_id=chat_id,
)
g.db.add(chat_membership)
g.db.flush()
if v.id == chat.owner_id:
if chat_adding_regex.fullmatch(text):
user = get_user(text[2:], graceful=True, attributes=[User.id])
if user and not user.has_muted(v) and not user.has_blocked(v):
existing = g.db.query(ChatMembership.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
leave = g.db.query(ChatLeave.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
if not existing and not leave:
chat_membership = ChatMembership(
user_id=user.id,
chat_id=chat_id,
)
g.db.add(chat_membership)
g.db.flush()
elif chat_kicking_regex.fullmatch(text):
user = get_user(text[2:], graceful=True, attributes=[User.id])
if user:
existing = g.db.query(ChatMembership).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
if existing:
g.db.delete(existing)
g.db.flush()
to_notify = [x[0] for x in g.db.query(ChatMembership.user_id).filter(
ChatMembership.chat_id == chat_id,