P
P
pivazik2020-06-01 14:45:51
Python
pivazik, 2020-06-01 14:45:51

Command to change nickname on module re, how to highlight spaces, symbols, etc.?

Hello, there was a problem when creating a team to change nickname. According to the idea, the command I made works, but when you put spaces, symbols, and T, D., the text after that is no longer highlighted and an unfinished phrase is obtained. How to fix?
Here's what I managed to do:

if msg[0:4] == "%ник":
    get_nick = re.search("\w{5,15}", msg)
    if get_nick == None:
      vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "⚠ | Никнейм слишком короткий", "random_id": 0})
    if get_nick != None:
      user_id = event.obj["from_id"]
      users_nick[user_id] = get_nick[0]
      vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "✔ | Теперь @id" + str(user_id) + "(ваш) никнейм: " + str(get_nick[0]) + ".", "random_id": 0})
    with open('users_nick.pickle', 'wb') as f:
      pickle.dump(users_nick, f)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-06-01
@pivazik

if msg.startswith('%ник'):
...     nick = msg.lstrip('%ник').strip()
...     if len(nick) < 5:
...             print('too short')
...     else:
...             # TODO: change nick
...             pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question