commands cosmetics part 2
This commit is contained in:
parent
dc2c195e95
commit
d84707900d
1 changed files with 23 additions and 21 deletions
|
@ -18,6 +18,7 @@ class Commander:
|
||||||
T_START_E = frozenset(['cmd_start_enabled'])
|
T_START_E = frozenset(['cmd_start_enabled'])
|
||||||
T_STOP = frozenset(['cmd_stop'])
|
T_STOP = frozenset(['cmd_stop'])
|
||||||
T_STOP_D = frozenset(['cmd_stop_disabled'])
|
T_STOP_D = frozenset(['cmd_stop_disabled'])
|
||||||
|
TOKEN_FAIL = "нет такой буквы в этом слове!"
|
||||||
NOPE = "а ты что ещё за хуй с горы?"
|
NOPE = "а ты что ещё за хуй с горы?"
|
||||||
YEP = "да, господин!"
|
YEP = "да, господин!"
|
||||||
DOC = """
|
DOC = """
|
||||||
|
@ -66,7 +67,7 @@ class Commander:
|
||||||
input_tokenset = frozenset(input_tokens.split(','))
|
input_tokenset = frozenset(input_tokens.split(','))
|
||||||
for token in input_tokenset:
|
for token in input_tokenset:
|
||||||
if token not in self.available_tokens:
|
if token not in self.available_tokens:
|
||||||
return "token not found!"
|
return self.TOKEN_FAIL
|
||||||
values = (','.join(sorted(input_tokenset)), phrase.strip())
|
values = (','.join(sorted(input_tokenset)), phrase.strip())
|
||||||
self.db_conn.update(DB_QUERY, values)
|
self.db_conn.update(DB_QUERY, values)
|
||||||
return self.YEP
|
return self.YEP
|
||||||
|
@ -76,12 +77,15 @@ class Commander:
|
||||||
def __add_user(self, caller: int, userspec: str) -> bool:
|
def __add_user(self, caller: int, userspec: str) -> bool:
|
||||||
if caller not in self.admins:
|
if caller not in self.admins:
|
||||||
return self.NOPE
|
return self.NOPE
|
||||||
user_id, names = userspec.strip().split(' ', 1)
|
DB_QUERY = 'INSERT INTO names (tg_id, name) values (%s,%s)'
|
||||||
for name in names.strip().split(','):
|
try:
|
||||||
query = 'INSERT INTO names (tg_id, name) values(%s,%s)'
|
user_id, names = userspec.strip().split(' ', 1)
|
||||||
values = (user_id, name)
|
for name in names.strip().split(','):
|
||||||
self.db_conn.update(query, values)
|
values = (user_id, name)
|
||||||
return self.YEP
|
self.db_conn.update(DB_QUERY, values)
|
||||||
|
return self.YEP
|
||||||
|
except Exception as e:
|
||||||
|
return str(e)
|
||||||
|
|
||||||
def __start_response(self) -> str:
|
def __start_response(self) -> str:
|
||||||
if self.responder.is_enabled():
|
if self.responder.is_enabled():
|
||||||
|
@ -107,20 +111,13 @@ class Commander:
|
||||||
|
|
||||||
async def action(self,
|
async def action(self,
|
||||||
event: telethon.events.common.EventBuilder) -> None:
|
event: telethon.events.common.EventBuilder) -> None:
|
||||||
chat_id = telethon.utils.get_peer_id(event.message.peer_id)
|
peer_id = event.message.peer_id
|
||||||
|
chat_id = telethon.utils.get_peer_id(peer_id)
|
||||||
if chat_id not in self.chats:
|
if chat_id not in self.chats:
|
||||||
return None
|
return None
|
||||||
command = event.message.text
|
command = event.message.text
|
||||||
sender = await event.get_sender()
|
sender = await event.get_sender()
|
||||||
match command:
|
match command:
|
||||||
case '.chat':
|
|
||||||
response = str(chat_id)
|
|
||||||
case '.list':
|
|
||||||
response = ', '.join(self.available_tokens)
|
|
||||||
case '.users':
|
|
||||||
users = await self.client.get_participants(
|
|
||||||
entity=event.message.peer_id)
|
|
||||||
response = self.__list_users(users)
|
|
||||||
case '.start':
|
case '.start':
|
||||||
response = self.__start_response()
|
response = self.__start_response()
|
||||||
self.responder.enable()
|
self.responder.enable()
|
||||||
|
@ -129,15 +126,20 @@ class Commander:
|
||||||
self.responder.disable()
|
self.responder.disable()
|
||||||
case '.help':
|
case '.help':
|
||||||
response = self.DOC
|
response = self.DOC
|
||||||
|
case '.chat':
|
||||||
|
#response = str(chat_id)
|
||||||
|
response = f'chat_id: {chat_id}\npeer_id: {peer_id}'
|
||||||
|
case '.users':
|
||||||
|
users = await self.client.get_participants(entity=peer_id)
|
||||||
|
response = self.__list_users(users)
|
||||||
|
case '.list':
|
||||||
|
response = ', '.join(self.available_tokens)
|
||||||
case command if command.startswith('.add '):
|
case command if command.startswith('.add '):
|
||||||
response = self.__add_response(sender.id, command[5:])
|
response = self.__add_response(sender.id, command[5:])
|
||||||
case command if command.startswith('.adduser '):
|
case command if command.startswith('.adduser '):
|
||||||
try:
|
response = self.__add_user(sender.id, command[9:])
|
||||||
response = self.__add_user(sender.id, command[9:])
|
|
||||||
except Exception as e:
|
|
||||||
response = str(e)
|
|
||||||
case command if command.startswith('.regex '):
|
case command if command.startswith('.regex '):
|
||||||
response = self.__list_regex(command[7:].strip())
|
response = self.__list_regex(command[7:].strip())
|
||||||
case _:
|
case _:
|
||||||
return None
|
return None
|
||||||
await self.client.send_message(event.message.peer_id, response)
|
await self.client.send_message(peer_id, response)
|
||||||
|
|
Loading…
Reference in a new issue