antonromashka

Сам код

Nov 5th, 2022 (edited)
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.33 KB | None | 0 0
  1. import telebot
  2. import datetime
  3. import time
  4.  
  5. ### HELP TEXT ------------------------------------------------------------------------|
  6. '''
  7. User Available Commands:
  8.    1. /poll
  9.    2. /stats
  10.    3. /start
  11.    4. /help
  12.    5. /groups
  13.  
  14. Developer Commands: #NOTE: ONLY @Parvat_R and @Rohithaditya are allowed for these comands:
  15.    1. /showIds
  16.    2. /botlogs
  17. '''
  18. ### MAIN VARS ------------------------------------------------------------------------|
  19. '''
  20. THESE ARE THE IMPORTANT VARS FOR POLL BOT
  21. '''
  22. BOT_TOKEN = '123' # YOUR BOT TOKEN HERE GET FROM @BotFather
  23. API_HASH = '123' # YOUR API HASH GET FROM my.telegram.org
  24. API_ID = '123' # YOUR API ID GET FROM my.telegram.org
  25. CHAT_ID = '123'# YOUR PRIVATE GROUP TO VIEW LOGS OR ERROR
  26. USERNAME = '123' # YOUR USERNAME THIS IS MANDTORY
  27.  
  28. ### ABOVE MAIN VARS -------------------------------------------------------------------|
  29. bot = telebot.TeleBot(token=BOT_TOKEN)
  30.  
  31. @bot.message_handler(commands=['showIds']
  32. def showIds(message):
  33.     try:
  34.         if message.from_user.username in ['Parvat_R', 'Rohithaditya', USERNAME]:
  35.             file = open('joined_groups.txt', 'r ')
  36.             bot.send_document(message.chat.id, file)
  37.             file.close()
  38.  
  39.     except Exception as error:
  40.         bot.send_message(CHAT_ID, str(error))
  41.  
  42. @bot.message_handler(commands=['stats', 'groups'])
  43. def stats(message):
  44.     try:
  45.         if message.from_user.username in['Parvat_R','Rohithaditya', USERNAME]:
  46.             print('Sending Stats To Owner')
  47.             with open('joined_groups.txt', 'r') as file:
  48.                 group_ids = []
  49.                 for line in file.readlines():
  50.                     for group_id in line.split(' '):
  51.                         group_ids.append(group_id)
  52.                         no_of_polls = len(group_ids)
  53.                         no_of_groups = len(list(set(group_ids)))
  54.                 group_ids.clear()
  55.                 bot.reply_to(message, f'Number of polls Maded: {no_of_polls}\nNo of groups bot has been added: {no_of_groups}')
  56.                 file.close()
  57.         else:
  58.                         bot.reply_to(message, f'Sorry {message.from_user.username}! You Are Not Allowed To Use This Command,')
  59.     except Exception as error:
  60.                             bot.send_message(CHAT_ID, f'Hi Devs!!\nHandle This Error plox\n{error}')
  61.                             try:
  62.                                 group_ids.clear()
  63.                             except:
  64.                                 pass
  65.                             bot.reply_to(message, f'An error occurred!\nError: {error}')
  66.                             bot.send_message(CHAT_ID, f'An error occurred!\nError: {error}')
  67.                             bot.send_document(CHAT_ID, '{message}')
  68.  
  69. @bot.message_handler(commands=['botlogs'])
  70. def ViewTheLogsFile(message):
  71.     try:
  72.         if message.from_user.username in ['Parvat_R', 'Rohithaditya', USERNAME]:
  73.             print('Owner Asked For The Logs!')
  74.             file = open('POLL_LOGS.txt', 'r')
  75.             bot.send_document(message.chat.id, file, timeout=60, disable_notification=True)
  76.             file.close()
  77.             print('Logs Sent To Owner')
  78.         else:
  79.             bot.reply_to(message, f'Sorry {message.from_user.username}! You Are Not Allowed For This Command,')
  80.     except Exception as error:
  81.         bot.reply_to(message, f'Error: {error}')
  82.  
  83. def poller(message):
  84.     MSG = message
  85.     try:
  86.         #### AN IMPORTANT PROCESS TO SAVE ALL THE USES IN THE POLL_LOGS.txt FILE
  87.         try:
  88.             file1 = open('joined_groups.txt', 'a')
  89.             file = open('POLL_LOGS.txt', 'a')
  90.         except FileNotFoundError as fnfe:
  91.             file = open('POLL_LOGS.txt', 'x')
  92.             file.close()
  93.             file = open('POLL_LOGS.txt', 'a')
  94.         text_to_add_in_log_file = f'''<pollbot command = log>
  95. Username: {message.from_user.username}
  96. User Id : {message.from_user.id}
  97. Command : {message.text}
  98. OWNER : {USERNAME}
  99. Chat Id : {message.chat.id}
  100. ChatType: {message.chat.type}
  101. GroupUserName: {message.chat.username}
  102. Date    : {datetime.datetime.now()}
  103.  
  104. <split info_end = True>Command Over</split>
  105.  
  106. '''
  107.         file1.write(f' {message.chat.id}')
  108.         file1.close()
  109.         file.write(text_to_add_in_log_file)
  110.         file.close()
  111.         ### PROCESS DONE!
  112.         #The complete command is cut on '|'
  113.         text_arr = message.text.split('|')
  114.  
  115.         #The splitted text are inserted in the commands list
  116.         #Always the first command or commands[0] will be '/poll
  117.         commands = []
  118.  
  119.         #Adding splitted text in commands:
  120.         for cmd in text_arr:
  121.             #ws_re_text = white space removed command text
  122.             ws_re_text = cmd.strip()
  123.             commands.append(ws_re_text)
  124.  
  125.         #Now the creations of commands for poll:
  126.         question     = commands[1]
  127.         options      = []
  128.         multi_answer = False
  129.         open_period  = None
  130.         explanation  = None
  131.         disable_noti = False
  132.         delete_msg   = False
  133.  
  134.         #Adding the options:
  135.         opt = commands[2].split(',')
  136.         for op in opt:
  137.             nop = op.replace('<.>', ',')
  138.             options.append(nop.strip())
  139.  
  140.         #Now checking the **kwargs in the command line
  141.         if len(commands) > 3:
  142.             for cmd in commands[3:]:
  143.                 main_cmd = cmd.strip().split('=')
  144.                
  145.                 if main_cmd[0].strip() in ['ma', 'multi_answer', 'm_a', 'mul_ans']:
  146.                     multi_answer = main_cmd[1].strip()
  147.                    
  148.                 if main_cmd[0].strip() in ['op', 'open_period', 'o_p', 'ope_per']:
  149.                     open_period = main_cmd[1].strip()
  150.  
  151.                 if main_cmd[0].strip() in ['ex', 'explanation', 'expl', 'e_x']:
  152.                     explanation = main_cmd[1].strip()
  153.  
  154.                 if main_cmd[0].strip() in ['dn', 'd_n', 'disable_notification', 'dis_not']:
  155.                     disable_noti = main_cmd[1].strip()
  156.                
  157.                 if main_cmd[0].strip() in ['dm', 'd_m', 'delete_message', 'del_msg']:
  158.                     delete_msg = True
  159.        
  160.         if delete_msg:
  161.             bot.delete_message(message.chat.id, message.id)
  162.         #The main function
  163.         return bot.send_poll(
  164.             message.chat.id,
  165.             question,
  166.             options,
  167.             allows_multiple_answers= multi_answer,
  168.             explanation            = explanation ,
  169.             open_period            = open_period ,
  170.             disable_notifications  = disable_noti)
  171.    
  172.     except IndexError:
  173.         return bot.reply_to(message, f'''Lol!!! You Have Entered Wrong Cmds
  174. The format of the command should be:
  175.  
  176. `/poll | your question | option1, option2, more options | **kwargs`
  177.  
  178. But What You Sent Me was🤣🤣😂😂😁
  179.  
  180. {message.text}
  181.  
  182. Which is invalid.
  183. For more help use: /help
  184. or contact us at: @venilabots1
  185. ''')
  186.     except Exception as error:
  187.         bot.send_message(CHAT_ID,f'''Error From Poll Bot!
  188.  
  189. Error  :: {error}
  190.  
  191. --------------------------------
  192.  
  193. Command:: {message.text}
  194.  
  195. --------------------------------
  196.  
  197. UserDetails: {message.from_user}
  198.  
  199. --------------------------------
  200.  
  201. Date   :: {message.date}
  202.  
  203. --------------------------------
  204.  
  205. The Complete Detail:
  206. {message}
  207.  
  208.  
  209. ''')
  210.        
  211.         return bot.reply_to(message, f'''An Unexpected Error Occured!
  212. Error::  {error}
  213. The error was informed to @venilabots''')
  214.        
  215.        
  216.  
  217. @bot.message_handler(commands=['poll'])
  218. def pollNow(message):
  219.     poller(message)
  220.  
  221. @bot.message_handler(commands=['help'])
  222. def helper(message):
  223.     return bot.reply_to(message, f'''My Name Defines Who Am I.
  224.    What Can I Do?
  225.    1. Create polls
  226.    2. Unlimited Polls
  227.    3. Vast options
  228.  
  229. Main Commands:
  230.    /help
  231.    /alive
  232.    /poll
  233.  
  234. Functions:
  235. /help:
  236.    See the Help Text
  237.  
  238. /alive:
  239.    Check if the bot is running or not
  240.  
  241. /poll:
  242.    Create polls.
  243.  
  244. How To Create Polls:
  245.  
  246. use:
  247. /poll | Your Question | Option1, Option2, Option3, more_option | **kwargs
  248. You can add As may options as you want. (minimum-1)
  249.  
  250. what is **kwargs?
  251. **kwargs are the optional commands, that you can pass when necessary!
  252. those are:
  253.    multi_answer = True/False
  254.        This enables or disables The multiple answer mode. By default It is False.
  255.        example:
  256.            /poll | This is my question | Ans1, Ans2 | multi_answer = True
  257.  
  258.    op = seconds
  259.        This tells how many seconds will the poll will last.
  260.        It might be 'op' or 'open_period'
  261.        example:
  262.            /poll | This is my question | Ans1, Ans2 | op = 60
  263.            Now the poll will last for 60 seconds.
  264.  
  265.    dn = True/False
  266.        This tells that the poll should be notified in the notifications of the
  267.        group members. By Default it is True. It might be 'dn' or 'disable_notification'.
  268.        example:
  269.            /poll | This is my question | Ans1, Ans2 | dn = False
  270.  
  271. Did you know, you can use multiple optional commands or dont use it:
  272. Example:
  273.    1.
  274.        /poll | Hi there | Hello, Good bye
  275.  
  276.    2.
  277.        /poll | This will close in 10s | Nice, Bad | op = 10
  278.        
  279.    3.
  280.        /poll | Hello | Hi, Bye, Hi dev, Bye human | ma = True | open_period = 50
  281.  
  282. Note:
  283.    -Use ',' to split the options.
  284.    -Every part is split by '|'.
  285.    -To use ',' in option use: '<.>'
  286.  
  287. For more informations visit:
  288. Official Site:
  289. https://sprin-g-reen.github.io/
  290. Telegram:
  291. @venilabots
  292. @venilabots1
  293.  
  294. Devs:
  295. @Parvat_R
  296. @Rohithaditya
  297.  
  298. Created with:
  299. python,
  300. pyTelegramBotAPI
  301. ''')
  302.  
  303.  
  304. @bot.message_handler(commands=['alive'])
  305. def alive(message):
  306.     bot.reply_to(message, f'Hey {message.from_user.username}, Ready To Serve You')
  307.  
  308. '''err_count = 0 #Check for errors
  309. while True:
  310.    try:
  311.        bot.polling()
  312.    except FileNotFoundError as e:
  313.        print(e)
  314.        err_count +=1
  315.        print(f'Error Number: {err_count}')
  316.        if err_count == 10:
  317.            break
  318. '''
  319. @bot.message_handler(commands=['start'])
  320. def alive(message):
  321.     bot.reply_to(message, f'Heya {message.from_user.username}, I am there to help you in polls. But this cmd is bit old try /help. SEE @VENILABOTS FOR MORE BOTS LIKE THIS')
  322.  
  323. err_count = 0 #Check for errors
  324. while True:
  325.     try:
  326.         bot.polling()
  327.     except FileNotFoundError as e:
  328.         print(e)
  329.         err_count +=1
  330.         print(f'Error Number: {err_count}')
  331.         if err_count == 10:
  332.             break
  333. """
  334. PLEASE KEEP CREDITS
  335. """
Advertisement
Add Comment
Please, Sign In to add comment