MCPcopy Create free account
hub / github.com/PastKing/tgbot-verify / create_user

Method create_user

database_mysql.py:145–187  ·  view source on GitHub ↗

创建新用户

(
        self, user_id: int, username: str, full_name: str, invited_by: Optional[int] = None
    )

Source from the content-addressed store, hash-verified

143 conn.close()
144
145 def create_user(
146 self, user_id: int, username: str, full_name: str, invited_by: Optional[int] = None
147 ) -> bool:
148 """创建新用户"""
149 conn = self.get_connection()
150 cursor = conn.cursor()
151
152 try:
153 cursor.execute(
154 """
155 INSERT INTO users (user_id, username, full_name, invited_by, created_at)
156 VALUES (%s, %s, %s, %s, NOW())
157 """,
158 (user_id, username, full_name, invited_by),
159 )
160
161 if invited_by:
162 cursor.execute(
163 "UPDATE users SET balance = balance + 2 WHERE user_id = %s",
164 (invited_by,),
165 )
166
167 cursor.execute(
168 """
169 INSERT INTO invitations (inviter_id, invitee_id, created_at)
170 VALUES (%s, %s, NOW())
171 """,
172 (invited_by, user_id),
173 )
174
175 conn.commit()
176 return True
177
178 except pymysql.err.IntegrityError:
179 conn.rollback()
180 return False
181 except Exception as e:
182 logger.error(f"创建用户失败: {e}")
183 conn.rollback()
184 return False
185 finally:
186 cursor.close()
187 conn.close()
188
189 def get_user(self, user_id: int) -> Optional[Dict]:
190 """获取用户信息"""

Callers 1

start_commandFunction · 0.80

Calls 1

get_connectionMethod · 0.95

Tested by

no test coverage detected