forked from rDrama/rDrama
add kicking
parent
e1a37706b6
commit
018cde58c1
|
@ -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)
|
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_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)
|
everyone_regex = re.compile('(^|\s|>)!(everyone)' + NOT_IN_CODE_OR_LINKS, flags=re.A)
|
||||||
|
|
||||||
|
|
|
@ -135,18 +135,26 @@ def speak(data, v):
|
||||||
g.db.add(chat_message)
|
g.db.add(chat_message)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
if v.id == chat.owner_id and chat_adding_regex.fullmatch(text):
|
if v.id == chat.owner_id:
|
||||||
user = get_user(text[2:], graceful=True, attributes=[User.id])
|
if chat_adding_regex.fullmatch(text):
|
||||||
if user and not user.has_muted(v) and not user.has_blocked(v):
|
user = get_user(text[2:], graceful=True, attributes=[User.id])
|
||||||
existing = g.db.query(ChatMembership.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
|
if user and not user.has_muted(v) and not user.has_blocked(v):
|
||||||
leave = g.db.query(ChatLeave.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
|
existing = g.db.query(ChatMembership.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
|
||||||
if not existing and not leave:
|
leave = g.db.query(ChatLeave.user_id).filter_by(user_id=user.id, chat_id=chat_id).one_or_none()
|
||||||
chat_membership = ChatMembership(
|
if not existing and not leave:
|
||||||
user_id=user.id,
|
chat_membership = ChatMembership(
|
||||||
chat_id=chat_id,
|
user_id=user.id,
|
||||||
)
|
chat_id=chat_id,
|
||||||
g.db.add(chat_membership)
|
)
|
||||||
g.db.flush()
|
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(
|
to_notify = [x[0] for x in g.db.query(ChatMembership.user_id).filter(
|
||||||
ChatMembership.chat_id == chat_id,
|
ChatMembership.chat_id == chat_id,
|
||||||
|
|
Loading…
Reference in New Issue