2023-10-16 09:46:31 -04:00
from time import time_ns
2020-09-22 17:57:43 -04:00
from telethon import Button
2020-09-13 13:50:36 -04:00
from ubot import ldr
2023-10-16 09:46:31 -04:00
2021-03-23 20:01:27 -04:00
@ldr.add ( " del " , no_disable = True , help = " Deletes messages from this bot, it ' s a safety feature. " )
2020-05-01 10:27:07 -04:00
async def delete_message ( event ) :
message_to_delete = await event . get_reply_message ( )
2020-05-26 14:23:04 -04:00
2020-10-03 11:27:11 -04:00
if message_to_delete and message_to_delete . sender_id == ( await event . client . get_me ( ) ) . id :
2020-05-01 10:27:07 -04:00
await message_to_delete . delete ( )
2021-03-23 20:01:27 -04:00
@ldr.add ( " start " , no_disable = True , help = " A start command to start the bot so you know what this bot is capable of when you start it, dumbass. " )
2020-09-22 17:57:43 -04:00
async def start_cmd ( event ) :
await event . reply (
2021-03-23 20:01:27 -04:00
f " Hi I ' m { ldr . settings . get_config ( ' bot_name ' ) or ' μBot ' } , use /help to see what commands I have! " ,
2020-09-22 17:57:43 -04:00
buttons = [ Button . url ( " Creator " , " https://t.me/Nick80835 " ) , Button . url ( " Source " , " https://github.com/Nick80835/microbot/tree/bot " ) ] ,
link_preview = False
)
2021-03-23 20:01:27 -04:00
@ldr.add ( " help " , no_disable = True )
2020-05-06 11:10:00 -04:00
async def help_cmd ( event ) :
2020-07-21 09:44:28 -04:00
if event . args :
2020-09-15 20:02:44 -04:00
for command in ldr . command_handler . incoming_commands :
if not command . hide_help :
if event . args == command . pattern :
if command . help :
await event . reply ( f " Help for ** { command . pattern } **: __ { command . help } __ " )
2020-07-21 09:44:28 -04:00
return
2020-09-15 20:02:44 -04:00
await event . reply ( f " ** { command . pattern } ** doesn ' t have a help string. " )
2020-07-21 09:44:28 -04:00
return
2020-09-15 20:02:44 -04:00
help_dict = { }
2020-05-06 11:10:00 -04:00
2020-09-15 20:02:44 -04:00
for command in ldr . command_handler . incoming_commands :
if not command . hide_help :
if command . module in help_dict :
2021-03-23 20:13:20 -04:00
help_dict [ command . module ] . append ( command . pattern )
2020-09-15 20:02:44 -04:00
else :
2021-03-23 20:13:20 -04:00
help_dict [ command . module ] = [ command . pattern ]
2020-05-06 11:10:00 -04:00
2020-09-15 20:02:44 -04:00
help_string = " \n " . join ( [ f " ** { module } **: { ' , ' . join ( pattern_list ) } " for module , pattern_list in help_dict . items ( ) ] )
2021-03-24 16:16:13 -04:00
prefix_help = f " **Bot prefix:** { ldr . prefix ( ) } \n **Group prefix:** { event . chat_db . prefix } \n \n "
2021-03-23 20:13:20 -04:00
await event . reply ( f " { prefix_help } **Available commands:** \n \n { help_string } " )
2020-05-06 11:10:00 -04:00
2021-03-23 20:01:27 -04:00
@ldr.add ( " prefix " , admin = True , no_private = True )
async def set_group_prefix ( event ) :
if not event . args :
2021-03-24 16:24:46 -04:00
await event . reply ( f " With this command you can set a custom prefix to replace `/`, the current prefix for this group is ` { event . chat_db . prefix } ` and this bot will always respond to ` { ldr . prefix ( ) } ` " )
2021-03-23 20:01:27 -04:00
return
2021-03-24 10:34:55 -04:00
if len ( event . args ) > 3 :
await event . reply ( " Custom prefixes must be at most 3 characters long! " )
2021-03-23 20:01:27 -04:00
return
2021-03-24 16:16:13 -04:00
event . chat_db . prefix = event . args
2021-03-24 16:24:46 -04:00
await event . reply ( f " Successfully set this group ' s prefix to ` { event . args } `! " )
2021-03-23 20:01:27 -04:00
2020-06-17 19:20:19 -04:00
@ldr.add ( " sudohelp " , sudo = True )
async def sudohelp ( event ) :
2020-07-21 09:44:28 -04:00
if event . args :
2020-09-15 20:02:44 -04:00
for command in ldr . command_handler . incoming_commands :
if command . hide_help :
if event . args == command . pattern :
if command . help :
await event . reply ( f " Help for ** { command . pattern } **: __ { command . help } __ " )
2020-07-21 09:44:28 -04:00
return
2020-09-15 20:02:44 -04:00
await event . reply ( f " ** { command . pattern } ** doesn ' t have a help string. " )
2020-07-21 09:44:28 -04:00
return
2020-09-15 20:02:44 -04:00
help_dict = { }
for command in ldr . command_handler . incoming_commands :
if command . hide_help :
if command . module in help_dict :
2021-03-24 10:39:02 -04:00
help_dict [ command . module ] . append ( command . pattern )
2020-09-15 20:02:44 -04:00
else :
2021-03-24 10:39:02 -04:00
help_dict [ command . module ] = [ command . pattern ]
2020-06-17 19:20:19 -04:00
2020-09-15 20:02:44 -04:00
help_string = " \n " . join ( [ f " ** { module } **: { ' , ' . join ( pattern_list ) } " for module , pattern_list in help_dict . items ( ) ] )
2020-06-17 19:20:19 -04:00
2020-09-15 20:02:44 -04:00
await event . reply ( f " **Available hidden commands:** \n \n { help_string } " )
2020-06-17 19:20:19 -04:00
@ldr.add ( " ping " , hide_help = True )
2020-05-02 16:43:52 -04:00
async def ping ( event ) :
start = time_ns ( )
2020-06-06 11:04:14 -04:00
ping_msg = await event . reply ( " Ping… " )
2020-05-03 16:44:01 -04:00
time_taken_ms = int ( ( time_ns ( ) - start ) / 1000000 )
2020-06-06 11:04:14 -04:00
await ping_msg . edit ( f " Ping… Pong! -> ** { time_taken_ms } **ms " )
2020-05-02 16:43:52 -04:00
2020-05-02 17:04:27 -04:00
@ldr.add ( " repo " )
2023-10-16 09:46:31 -04:00
async def bot_repo ( event ) :
2020-09-21 19:20:32 -04:00
await event . reply ( " https://github.com/Nick80835/microbot/tree/bot " )
2020-06-09 21:05:53 -04:00
2020-08-24 12:07:23 -04:00
@ldr.add ( " disable " , admin = True , help = " Disables commands in the current chat, requires admin. " )
async def disable_command ( event ) :
if event . args :
2020-09-15 20:02:44 -04:00
for command in ldr . command_handler . incoming_commands :
if event . args == command . pattern :
if command . not_disableable :
await event . reply ( f " ** { command . pattern } ** cannot be disabled! " )
2020-08-24 12:07:23 -04:00
return
2020-09-15 20:02:44 -04:00
await event . reply ( f " Disabling ** { command . pattern } ** in chat ** { event . chat . id } **! " )
2021-03-23 20:55:54 -04:00
event . chat_db . disable_command ( command . pattern )
2020-09-15 20:02:44 -04:00
return
2020-08-24 12:07:23 -04:00
await event . reply ( f " ** { event . args } ** is not a command! " )
else :
2020-10-10 19:38:21 -04:00
await event . reply ( " Specify a command to disable! " )
2020-08-24 12:07:23 -04:00
@ldr.add ( " enable " , admin = True , help = " Enables commands in the current chat, requires admin. " )
async def enable_command ( event ) :
if event . args :
2020-09-15 20:02:44 -04:00
for command in ldr . command_handler . incoming_commands :
if event . args == command . pattern :
await event . reply ( f " Enabling ** { command . pattern } ** in chat ** { event . chat . id } **! " )
2021-03-23 20:55:54 -04:00
event . chat_db . enable_command ( command . pattern )
2020-09-15 20:02:44 -04:00
return
2020-08-24 12:07:23 -04:00
await event . reply ( f " ** { event . args } ** is not a command! " )
else :
2020-10-10 19:38:21 -04:00
await event . reply ( " Specify a command to enable! " )
2020-08-24 12:07:23 -04:00
@ldr.add ( " showdisabled " , admin = True , help = " Shows disabled commands in the current chat. " )
async def show_disabled ( event ) :
2021-03-23 20:55:54 -04:00
disabled_list = event . chat_db . disabled_commands ( )
2020-08-24 12:07:23 -04:00
if disabled_list :
2021-03-23 19:16:21 -04:00
disabled_commands = " \n " . join ( disabled_list )
2020-08-24 12:07:23 -04:00
await event . reply ( f " Disabled commands in ** { event . chat . id } **: \n \n { disabled_commands } " )
else :
await event . reply ( f " There are no disabled commands in ** { event . chat . id } **! " )
2020-07-21 09:44:28 -04:00
@ldr.add ( " nsfw " , admin = True , help = " Enables or disables NSFW commands for a chat, requires admin. " )
2020-06-09 21:05:53 -04:00
async def nsfw_toggle ( event ) :
2021-03-23 19:16:21 -04:00
if event . args . lower ( ) not in ( " on " , " off " ) :
2021-03-24 16:16:13 -04:00
if event . chat_db . nsfw_enabled :
2020-06-09 21:05:53 -04:00
current_config = ' On '
else :
current_config = ' Off '
2021-03-24 16:16:13 -04:00
await event . reply ( f " Syntax: { event . prefix } nsfw (on|off) \n Current config for this chat: { current_config } " )
2020-06-09 21:05:53 -04:00
return
if event . args == " on " :
2021-03-24 16:16:13 -04:00
event . chat_db . nsfw_enabled = True
2020-06-09 21:07:50 -04:00
await event . reply ( " NSFW commands enabled for this chat! " )
2020-06-09 21:05:53 -04:00
elif event . args == " off " :
2021-03-24 16:16:13 -04:00
event . chat_db . nsfw_enabled = False
2020-06-09 21:07:50 -04:00
await event . reply ( " NSFW commands disabled for this chat! " )
2020-08-04 07:06:11 -04:00
@ldr.add ( " fun " , admin = True , help = " Enables or disables fun commands for a chat, requires admin. " )
async def fun_toggle ( event ) :
2021-03-23 19:16:21 -04:00
if event . args . lower ( ) not in ( " on " , " off " ) :
2021-03-24 16:16:13 -04:00
if event . chat_db . fun_enabled :
2020-08-04 07:06:11 -04:00
current_config = ' On '
else :
current_config = ' Off '
2021-03-24 16:16:13 -04:00
await event . reply ( f " Syntax: { event . prefix } fun (on|off) \n Current config for this chat: { current_config } " )
2020-08-04 07:06:11 -04:00
return
2021-03-23 19:16:21 -04:00
if event . args . lower ( ) == " on " :
2021-03-24 16:16:13 -04:00
event . chat_db . fun_enabled = True
2020-08-04 07:06:11 -04:00
await event . reply ( " Fun commands enabled for this chat! " )
2021-03-23 19:16:21 -04:00
elif event . args . lower ( ) == " off " :
2021-03-24 16:16:13 -04:00
event . chat_db . fun_enabled = False
2020-08-04 07:06:11 -04:00
await event . reply ( " Fun commands disabled for this chat! " )