async def harambe(self, message: discord.Message) -> None: """forever in our ~~memes~~ hearts""" if message.server is None: return server_id = message.server.id c.execute('select * from harambe where server=?', (server_id, )) result = c.fetchone() # result: [ server_id, last, number, chain, max ] if result is not None: # previous server # message.timestamp is a native datetime.datetime object # so in the database we are storing a datetime.datetime object # (=> str(datetime.datetime), it's a string-encoded ISO-based date) d_last = datetime.datetime.strptime(result[1], '%Y-%m-%d %H:%M:%S.%f') d_new = message.timestamp d_diff = d_new - d_last if d_diff.days >= 2: # update last in db c.execute( '''update harambe set last=?, number=number+1, chain=0 where server=?''', (str(d_new), server_id)) conn.commit() await self.bot.send_message( message.channel, 'days since harambe was last mentioned: ' '%s --> 0' % d_diff.days) elif d_diff.days == 1: if result[3] >= result[4]: c.execute('update harambe set max=?', (result[3] + 1, )) c.execute( '''update harambe set last=?, number=number+1, chain=chain+1 where server=?''', (str(d_new), server_id)) conn.commit() await self.bot.send_message( message.channel, 'daily harambe chain: %s' % str(result[3] + 1)) else: c.execute( '''update harambe set number=number+1 where server=?''', (server_id, )) conn.commit() else: d_new = message.timestamp c.execute( '''insert into harambe values (?, ?, 1, 0, 0)''', (server_id, str(d_new))) conn.commit()
def mailing(user, conn, c, user_from_db, vk_session): keyboard = vk_api.keyboard.VkKeyboard(inline=True) c.execute('''SELECT * FROM mailing WHERE id=:id''', {'id': user['id']}) user_mailing = c.fetchone() if user_mailing[1]: keyboard.add_button('first', vk_api.keyboard.VkKeyboardColor.POSITIVE) else: keyboard.add_button('first', vk_api.keyboard.VkKeyboardColor.NEGATIVE) if user_mailing[2]: keyboard.add_button('second', vk_api.keyboard.VkKeyboardColor.POSITIVE) else: keyboard.add_button('second', vk_api.keyboard.VkKeyboardColor.NEGATIVE) if user_mailing[3]: keyboard.add_button('third', vk_api.keyboard.VkKeyboardColor.POSITIVE) else: keyboard.add_button('third', vk_api.keyboard.VkKeyboardColor.NEGATIVE) message_id = vk_session.method( 'messages.send', { 'user_id': user['id'], 'random_id': random.getrandbits(64), 'message': 'Выберите на какую рассылку вы хотите подписаться.\n(Зелёный цвет означает что вы подписаны на эту рассылку)', 'keyboard': keyboard.get_keyboard() }) with conn: c.execute('''UPDATE people SET message_id=:message_id WHERE id=:id''', { 'id': user_from_db[0], 'message_id': message_id })
async def f(self, ctx: commands.Context) -> None: """pays respects""" u = (ctx.message.author.id, ) c.execute('select * from respect where user=?', u) u_ = c.fetchone() if u_ is not None: # user exists in db; increase respect c.execute('update respect set f=f+1 where user=?', u) conn.commit() else: # user does not exist in db c.execute('insert into respect values(?, 1)', u) conn.commit() await self.bot.say( '%s p-p-pays their respects... all that respect just for little me...' % ctx.message.author.mention)
async def respect(self, ctx: commands.Context) -> None: """find out how respectful you are""" real = ctx.message.content.lower() in ('actualrespect', 'realrespect') r = 0 if not real and ctx.message.author.id in fixed_respect: # we have the leet effect r = str(fixed_respect[ctx.message.author.id]) else: # db lookup u = (ctx.message.author.id, ) c.execute('select * from respect where user=?', u) result = c.fetchone() if result is not None: r = str(result[1]) await self.bot.say( '%s: %s respect... NOT LIKE I LIKE YOU OR ANYTHING BAKA' % (ctx.message.author.mention, r))
def parse_message(event, vk_session): user = vk_session.method('users.get', {'user_id': event.user_id})[0] print(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime()), "{0[first_name]} {0[last_name]}: {1.text}".format(user, event)) c.execute('SELECT * FROM people WHERE vk_id=:vk_id', {'vk_id': user['id']}) user_from_db = c.fetchall() if user_from_db != []: user_from_db = user_from_db[-1] if not user_from_db[10] is None: del_keyboard(user_from_db[10], vk_session=vk_session) with conn: c.execute( '''UPDATE people SET message_id=:message_id WHERE id=:id''', { 'id': user_from_db[0], 'message_id': None }) if user_from_db == []: create_new_people(conn, c, user) vk_session.method( 'messages.send', { 'user_id': user['id'], 'random_id': random.getrandbits(64), 'message': '''Ответьте на пару вопросов, чтобы оставить заявку и, вскоре после этого, мы свяжемся с Вами для уточнения деталей😊.''' }) ask_for_name(user, vk_session) elif event.text == 'Подать ещё одну заявку🆕': if not user_from_db[8] is None: create_new_people(conn, c, user) ask_for_name(user, vk_session) else: vk_session.method( 'messages.send', { 'user_id': user['id'], 'random_id': random.getrandbits(64), 'message': 'Вы не можете подать новую заявку пока не завершите заполнение этой😟.' }) elif event.text == 'Рассылка📫': mailing(user, conn, c, user_from_db, vk_session=vk_session) elif event.text == 'first': c.execute('''SELECT * FROM mailing WHERE id=:id''', {'id': user['id']}) user_mailing = c.fetchone() with conn: c.execute('''UPDATE mailing SET first=:first WHERE id=:id''', { 'id': user['id'], 'first': int(not bool(user_mailing[1])) }) done(user, vk_session=vk_session) elif event.text == 'second': c.execute('''SELECT * FROM mailing WHERE id=:id''', {'id': user['id']}) user_mailing = c.fetchone() with conn: c.execute('''UPDATE mailing SET second=:second WHERE id=:id''', { 'id': user['id'], 'second': int(not bool(user_mailing[2])) }) done(user, vk_session=vk_session) elif event.text == 'third': c.execute('''SELECT * FROM mailing WHERE id=:id''', {'id': user['id']}) user_mailing = c.fetchone() with conn: c.execute('''UPDATE mailing SET third=:third WHERE id=:id''', { 'id': user['id'], 'third': int(not bool(user_mailing[3])) }) done(user, vk_session=vk_session) elif user_from_db[4] is None: if event.text != "К предыдущему вопросу🔙": if event.text != 'Начать' and not check_for_dig(event.text): with conn: c.execute( '''UPDATE people SET nick_name=:nick_name WHERE id=:id''', { 'id': user_from_db[0], 'nick_name': event.text }) ask_for_class(user, vk_session) else: invalid_value(user, vk_session=vk_session) ask_for_name(user, vk_session) else: ask_for_name(user, vk_session) elif user_from_db[5] is None: if event.text != "К предыдущему вопросу🔙": try: if 1 <= int(event.text) <= 11: with conn: c.execute( '''UPDATE people SET class=:class WHERE id=:id''', { 'id': user_from_db[0], 'class': event.text }) ask_for_what(user, c=c, conn=conn, user_from_db=user_from_db, vk_session=vk_session) else: invalid_value(user, vk_session=vk_session) ask_for_class(user, vk_session) except: invalid_value(user, vk_session=vk_session) ask_for_class(user, vk_session) else: with conn: c.execute( '''UPDATE people SET nick_name=:nick_name WHERE id=:id''', { 'id': user_from_db[0], 'nick_name': None }) ask_for_name(user, vk_session) elif user_from_db[6] is None: if event.text != "К предыдущему вопросу🔙": if event.text == 'Повышение качества знаний📚' or event.text == 'Подготовка к экзамену💯': with conn: c.execute( '''UPDATE people SET for_what=:for_what WHERE id=:id''', { 'id': user_from_db[0], 'for_what': event.text }) if event.text == 'Повышение качества знаний📚': with conn: c.execute( '''UPDATE people SET exam=:exam WHERE id=:id''', { 'id': user_from_db[0], 'exam': '-' }) c.execute( '''UPDATE people SET kind=:kind WHERE id=:id''', { 'id': user_from_db[0], 'kind': '-' }) thanq(user, vk_session=vk_session) else: if int(user_from_db[5]) < 10: with conn: c.execute( '''UPDATE people SET exam=:exam WHERE id=:id''', { 'id': user_from_db[0], 'exam': 'ОГЭ' }) ask_for_kind(user, conn, c, user_from_db, vk_session=vk_session) else: ask_for_exam(user, conn, c, user_from_db, vk_session=vk_session) else: invalid_value(user, vk_session=vk_session) ask_for_what(user, conn, c, user_from_db, vk_session=vk_session) else: with conn: c.execute('''UPDATE people SET class=:class WHERE id=:id''', { 'id': user_from_db[0], 'class': None }) c.execute('''UPDATE people SET exam=:exam WHERE id=:id''', { 'id': user_from_db[0], 'exam': None }) c.execute('''UPDATE people SET kind=:kind WHERE id=:id''', { 'id': user_from_db[0], 'kind': None }) ask_for_class(user, vk_session) elif user_from_db[7] is None: if event.text != "К предыдущему вопросу🔙": if event.text == "Базу" or event.text == "Профиль": with conn: c.execute('''UPDATE people SET exam=:exam WHERE id=:id''', { 'id': user_from_db[0], 'exam': event.text }) ask_for_kind(user, conn, c, user_from_db, vk_session=vk_session) else: invalid_value(user, vk_session=vk_session) ask_for_exam(user, conn, c, user_from_db, vk_session=vk_session) else: with conn: c.execute( '''UPDATE people SET for_what=:for_what WHERE id=:id''', { 'id': user_from_db[0], 'for_what': None }) ask_for_exam(user, conn, c, user_from_db, vk_session=vk_session) elif user_from_db[8] is None: if event.text != "К предыдущему вопросу🔙": if event.text == 'Индивидуальные' or event.text == 'Групповые': with conn: c.execute('''UPDATE people SET kind=:kind WHERE id=:id''', { 'id': user_from_db[0], 'kind': event.text }) thanq(user, vk_session=vk_session) else: invalid_value(user, vk_session=vk_session) ask_for_kind(user, conn, c, user_from_db, vk_session=vk_session) else: if int(user_from_db[5]) < 10: with conn: c.execute( '''UPDATE people SET for_what=:for_what WHERE id=:id''', { 'id': user_from_db[0], 'for_what': None }) ask_for_what(user, conn, c, user_from_db, vk_session=vk_session) else: with conn: c.execute('''UPDATE people SET exam=:exam WHERE id=:id''', { 'id': user_from_db[0], 'exam': None }) c.execute( '''UPDATE people SET for_what=:for_what WHERE id=:id''', { 'id': user_from_db[0], 'for_what': None }) ask_for_exam(user, conn, c, user_from_db, vk_session=vk_session) elif event.text == 'К предыдущему вопросу🔙': if user_from_db[6] == 'Повышение качества знаний📚': with conn: c.execute( '''UPDATE people SET for_what=:for_what WHERE id=:id''', { 'id': user_from_db[0], 'for_what': None }) c.execute('''UPDATE people SET exam=:exam WHERE id=:id''', { 'id': user_from_db[0], 'exam': None }) c.execute('''UPDATE people SET kind=:kind WHERE id=:id''', { 'id': user_from_db[0], 'kind': None }) ask_for_what(user, conn, c, user_from_db, vk_session=vk_session) else: with conn: c.execute('''UPDATE people SET kind=:kind WHERE id=:id''', { 'id': user_from_db[0], 'kind': None }) ask_for_kind(user, conn, c, user_from_db, vk_session=vk_session) else: invalid_value(user, end=True, vk_session=vk_session)