2020-02-09 17:09:13 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Yuuki_Libs
|
|
|
|
(c) 2020 Star Inc.
|
|
|
|
This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
"""
|
|
|
|
|
2020-02-10 14:36:32 +08:00
|
|
|
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
|
|
|
|
|
|
|
|
|
2020-02-09 17:09:13 +08:00
|
|
|
class Yuuki_JoinGroup:
|
|
|
|
def __init__(self, Yuuki):
|
|
|
|
"""
|
|
|
|
Event Type:
|
|
|
|
NOTIFIED_INVITE_INTO_GROUP (13)
|
|
|
|
"""
|
|
|
|
self.Yuuki = Yuuki
|
|
|
|
|
2020-02-10 14:36:32 +08:00
|
|
|
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
|
|
|
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
|
|
|
|
|
2020-02-09 17:09:13 +08:00
|
|
|
def action(self, ncMessage):
|
|
|
|
GroupInvite = []
|
2020-02-12 15:34:29 +08:00
|
|
|
BlockedIgnore = ncMessage.param2 in self.Yuuki.data.getData(["BlackList"])
|
2020-02-10 14:36:32 +08:00
|
|
|
if self.Yuuki_DynamicTools.checkInInvitationList(ncMessage) and not BlockedIgnore:
|
2020-02-09 17:09:13 +08:00
|
|
|
GroupID = ncMessage.param1
|
|
|
|
Inviter = ncMessage.param2
|
2020-02-10 14:36:32 +08:00
|
|
|
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
|
|
|
self.Yuuki.MyMID).getGroup(GroupID)
|
2020-02-09 17:09:13 +08:00
|
|
|
if GroupInfo.members:
|
|
|
|
GroupMember = [Catched.mid for Catched in GroupInfo.members]
|
|
|
|
GroupInfo.invitee = []
|
|
|
|
if GroupInfo.invitee:
|
2020-02-10 14:36:32 +08:00
|
|
|
GroupInvite = [
|
|
|
|
Catched.mid for Catched in GroupInfo.invitee]
|
|
|
|
self.Yuuki_DynamicTools.getClient(
|
|
|
|
self.Yuuki.MyMID).acceptGroupInvitation(self.Yuuki.Seq, GroupID)
|
2020-02-09 17:09:13 +08:00
|
|
|
if len(GroupMember) >= self.Yuuki.YuukiConfigs["GroupMebers_Demand"]:
|
2020-02-10 14:36:32 +08:00
|
|
|
GroupList = self.Yuuki.data.getData(
|
|
|
|
["Global", "GroupJoined"])
|
2020-02-09 17:09:13 +08:00
|
|
|
NewGroupList = GroupList.copy()
|
|
|
|
NewGroupList.append(GroupID)
|
2020-02-10 14:36:32 +08:00
|
|
|
self.Yuuki.data.updateData(
|
|
|
|
["Global", "GroupJoined"], NewGroupList)
|
2020-02-12 15:34:29 +08:00
|
|
|
self.Yuuki_DynamicTools.sendText(
|
|
|
|
GroupID,
|
|
|
|
self.Yuuki.get_text("Helllo^^\nMy name is %s ><\nNice to meet you OwO") %
|
|
|
|
(self.Yuuki.YuukiConfigs["name"],)
|
|
|
|
)
|
|
|
|
self.Yuuki_DynamicTools.sendText(
|
|
|
|
GroupID,
|
|
|
|
self.Yuuki.get_text("Type:\n\t%s/Help\nto get more information\n\nMain Admin of the Group:\n%s") %
|
|
|
|
(
|
|
|
|
self.Yuuki.YuukiConfigs["name"],
|
|
|
|
self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).displayName,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.Yuuki_DynamicTools.getGroupTicket(GroupID, self.Yuuki.MyMID, True)
|
2020-02-09 17:09:13 +08:00
|
|
|
# Log
|
2020-02-10 14:36:32 +08:00
|
|
|
self.Yuuki.data.updateLog(
|
|
|
|
"JoinGroup", (self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Inviter))
|
2020-02-09 17:09:13 +08:00
|
|
|
else:
|
2020-02-12 15:34:29 +08:00
|
|
|
self.Yuuki_DynamicTools.sendText(
|
|
|
|
GroupID,
|
|
|
|
self.Yuuki.get_text("Sorry...\nThe number of members is not satisfied (%s needed)") %
|
|
|
|
(self.Yuuki.YuukiConfigs["GroupMebers_Demand"],)
|
|
|
|
)
|
|
|
|
self.Yuuki_DynamicTools.getClient(self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupID)
|
2020-02-09 17:09:13 +08:00
|
|
|
# Log
|
2020-02-10 14:36:32 +08:00
|
|
|
self.Yuuki.data.updateLog(
|
|
|
|
"JoinGroup", (self.Yuuki.data.getTime(), GroupID, "Not Join", Inviter))
|
2020-02-09 17:09:13 +08:00
|
|
|
if ncMessage.param1 in self.Yuuki.data.getData(["Global", "GroupJoined"]) and not BlockedIgnore:
|
|
|
|
for userId in self.Yuuki.Connect.helper_ids:
|
2020-02-10 14:36:32 +08:00
|
|
|
if self.Yuuki_DynamicTools.checkInInvitationList(ncMessage, userId) or userId in GroupInvite:
|
|
|
|
self.Yuuki_DynamicTools.getClient(userId).acceptGroupInvitation(
|
|
|
|
self.Yuuki.Seq, ncMessage.param1)
|
|
|
|
self.Yuuki_DynamicTools.getGroupTicket(
|
|
|
|
ncMessage.param1, userId, True)
|
2020-02-09 17:09:13 +08:00
|
|
|
# Log
|
2020-02-10 14:36:32 +08:00
|
|
|
self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(
|
|
|
|
), ncMessage.param1, userId, ncMessage.param2))
|
|
|
|
self.Yuuki.Security(ncMessage)
|