56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
''' Basic functions mod '''
|
|
|
|
import asyncio
|
|
|
|
from telethon import events
|
|
from telethon.tl.types import PeerUser
|
|
|
|
import utils
|
|
|
|
_config = None
|
|
|
|
async def mod_init(config: dict) -> bool:
|
|
''' Initialize the mod '''
|
|
global _config
|
|
_config = config
|
|
print('[I] mod_basic is initialized')
|
|
|
|
async def mod_deinit() -> None:
|
|
''' Deinitialize the mod '''
|
|
print('[I] mod_basic is deinitialized')
|
|
|
|
def mod_get_mighty() -> bool:
|
|
''' Mod is called 'mighty' if it receives all messages '''
|
|
return False
|
|
|
|
def mod_get_tags() -> None:
|
|
''' Get tags used by the mod '''
|
|
return ['base']
|
|
|
|
async def mod_new_message(session, event) -> None:
|
|
''' Handle new message '''
|
|
try:
|
|
# get the message
|
|
msg = event.message
|
|
# not outgoing - do not process
|
|
if not msg.out:
|
|
return
|
|
# peer must be user
|
|
peer = msg.peer_id
|
|
if type(peer) is not PeerUser:
|
|
return
|
|
|
|
# get the text
|
|
text = msg.message
|
|
# get args
|
|
args = [i for i in text.split(' ') if i][1:]
|
|
# no args
|
|
if not args:
|
|
response_text = 'tg-utility available mods:'
|
|
mods = utils.get_all_mods()
|
|
for mod in mods:
|
|
response_text += '\n - %s' % mod
|
|
await event.reply(message=response_text)
|
|
except:
|
|
utils.pex()
|