Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Update sql function into briefer one & temporarily suspend developmen…
Browse files Browse the repository at this point in the history
…t due to CEE

Integrate unnecessary modules into two: sql_select & sql_update.
Due to CCEE, development will be temporarily suspended until June.
Todo list:
* Complete migrate to sql_select&update
* Auto sm function
* Add dynamic input string to variety list.
* A more detailed administration panel
  • Loading branch information
sor committed Mar 12, 2018
1 parent 91ac19f commit 069d4ea
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 16 deletions.
20 changes: 17 additions & 3 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def repm(bot, update, user_data):
if confirmed(id):
send(bot, update, chat_id = update.message.chat_id, text = '已经知道主人的身份啦,不用重复验证喵')
return
captcha = select_captcha(id)
captcha = str(sql_select('captcha', 'user', 'id', id))
status = pm(uid, '验证码', captcha, 'yes')
if status == -1:
send(bot, update, chat_id = update.message.chat_id, text = "U2娘不理人家了QAQ\n请稍候使用 '/repm' 再试")
Expand All @@ -119,9 +119,9 @@ def confirm(bot, update, args, user_data):
if confirmed(id):
send(bot, update, chat_id = update.message.chat_id, text = '幼兔娘早就认识主人了w')
return
real = select_captcha(id)
real = str(sql_select('captcha', 'user', 'id', id))
if real == captcha:
update_confirmed(id)
sql_update('user', 'confirmed', 1, 'id', id)
send(bot, update, chat_id = update.message.chat_id, text = "身份验证成功,幼兔娘记住你啦\n主人自由了!快去愉快地玩耍吧w\n群聊里输入 '幼兔娘 新人礼包' 获取幼兔娘的福利一份~\n悄悄告诉你: 幼兔娘和U2娘的体位很相似的说~ 快去试试吧w")
bot.restrict_chat_member(chat_id = tgconf['group'], user_id = id, can_send_messages = True, can_send_media_messages = True, can_send_other_messages = True, can_add_web_page_previews = True)
send(bot, update, chat_id = tgconf['my'], text = '%s: %s' % (name, str(uid)))
Expand Down Expand Up @@ -271,10 +271,24 @@ def bot_chat(bot, update, text, id):
reply(bot, update, word)
return

def bot_sm(bot, update, id, text):
status = get_sm_status(id)
if status == 'init':
num = sm_init(uid)
update_sm_num(id, num)
send(bot, update, chat_id = update.message.chat_id, text = '--- %d 号规则 ---' % (num))
send(bot, update, chat_id = update.message.chat_id, text = "规则名称:")
return
elif status == 'name':
return

def private(bot, update, chat_data, user_data):
id = update.effective_user.id
text = update.effective_message.text
log(bot, 'private', id, text)
if (text == '幼兔娘 调教') or (select_sm_status(id) != 'init'):
bot_sm(bot, update, id, text)
return
if text == '# trick':
update_mod_status(id, 'trick')
return
Expand Down
62 changes: 49 additions & 13 deletions bot/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
sql_log = open('sql.log', 'a')

def execute(sql, *s):
db.commit()
if s == ():
slog = '(%s, sql) %s' % (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()), sql)
else:
Expand All @@ -43,23 +44,23 @@ def id2uid(id):
uid = cursor.fetchone()[0]
return uid

def sql_select(name, table, column, value):
sql = 'select %s from %s where %s = %s' % (name, table, column, value)
execute(sql)
return cursor.fetchone()[0]

def sql_update(table, column, value, ec, ev):
sql = 'update %s set %s = %s where %s = %s' % (table, column, '%s', ec, ev)
execute(sql, value)
db.commit()
return

def init(id, uid):
captcha = random.randint(1000, 9999)
sql = 'insert into user values (%s, %s, \'\', \'init\', 0, 1, %s) on duplicate key update uid = %s, confirmed = 0, captcha = %s'
execute(sql, id, uid, captcha, uid, captcha)
db.commit()
return captcha
def select_captcha(id):
sql = 'select captcha from user where id = %s'
execute(sql, id)
captcha = str(cursor.fetchone()[0])
return captcha

def update_confirmed(id):
sql = 'update user set confirmed = 1 where id = %s'
execute(sql, id)
db.commit()
return

def update_captcha(id):
captcha = random.randint(1000, 9999)
Expand Down Expand Up @@ -118,7 +119,42 @@ def mod_status(id):
return status

def update_mod_status(id, status):
sql = 'update `user` set mod_status = \'%s\' where id = %s'
sql = 'update `user` set mod_status = %s where id = %s'
execute(sql, status, id)
db.commit()
return

def select_sm_status(id):
sql = 'select sm_status from `user` where id = %s'
execute(sql, id)
status = cursor.fetchone()[0]
return status

def select_sm_num(id):
sql = 'select sm_num from `user` where id = %s'
execute(sql, id)
status = cursor.fetchone()[0]
return status

def update_sm_status(id, status):
sql = 'update `user` set sm_status = %s where id = %s'
execute(sql, status, id)
db.commit()
return
return

def update_sm_num(id, num):
sql = 'update `user` set sm_num = %s where id = %s'
execute(sql, status, num)
db.commit()
return

def sm_num():
sql = 'select * from sm order by id'
return execute(sql)

def sm_init(uid):
num = sm_num()
sql = 'insert into sm (id, creator, disabled) values (%s, %s, 1)'
execute(sql, num, uid)
db.commit()
return num

0 comments on commit 069d4ea

Please sign in to comment.