├── README.md ├── bot.py ├── loggingids.json └── user.txt /README.md: -------------------------------------------------------------------------------- 1 | # TelegramLoggingBot 2 | This Bot is written in Python with the help from the pyTelegramBotAPI. 3 | 4 | Test it at our official Telegram Bot: 5 | [@IchLoggeBot](https://telegram.me/IchLoggeBot) 6 | 7 | 8 | Let's start by installing everything you need. 9 | 10 | # Installation 11 | 12 | First of all, you need to install Python2 & the Python package manager 13 | 14 | 15 | After that you need to install the pyTelegramBotAPI. 16 | 17 | ``` 18 | sudo pip install pyTelegramBotAPI 19 | ``` 20 | Finally clone the repo 21 | 22 | ``` 23 | git clone https://github.com/aRandomStranger/TelegramLoggingBot/ 24 | ``` 25 | 26 | # Getting started 27 | 28 | Create 2 new files named "loggingids.json" and "user.txt" 29 | Open the file "bot.py" and replace following IDs with your options: 30 | 31 | ``` 32 | API_TOKEN = 'YOUR TOKEN' 33 | ``` 34 | This should be your Token received from Botfather. 35 | 36 | Also don't forget to replace the Debug Group ID 37 | 38 | 39 | 40 | # Running the Bot 41 | 42 | You can one-time run the Bot with the command 43 | ``` 44 | python bot.py 45 | ``` 46 | 47 | This isn't recommend. 48 | Use something like screen to hold the Bot. 49 | ``` screen -S LoggingBot ``` 50 | Then just retype the command and you are finished! 51 | 52 | # Special thanks to 53 | [@Edurolp](https://telegram.me/edurolp) - For helping with Debugging 54 | 55 | [@Gunny14](https://telegram.me/gunny14) - For helping users & being staff 56 | 57 | [@Sanguchi](https://telegram.me/Sanguchi) - For helping with Debugging, being staff & helping users 58 | 59 | [@JackRendor](https://telegram.me/JackRendor) - For helping users & being staff 60 | 61 | [@eternnoir](https://github.com/eternnoir/pyTelegramBotAPI) - for creating this loveful API! 62 | 63 | 64 | # Updates 65 | 66 | Don't miss any Updates - Subscribe to our Channel! 67 | [@IchLoggeBotNews](https://telegram.me/IchLoggeBotNews) - Updates in English Language 68 | -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #-*- coding:utf-8 -*- 3 | import sys 4 | import time 5 | reload(sys) 6 | sys.setdefaultencoding("utf-8") 7 | 8 | print "[System] Bot has started." 9 | 10 | user = [line.rstrip('\n') for line in open('user.txt','rt')] 11 | 12 | 13 | import telebot 14 | import random 15 | import json 16 | import time 17 | from pprint import pprint 18 | 19 | API_TOKEN = 'YOUR TOKEN' 20 | 21 | bot = telebot.TeleBot(API_TOKEN) 22 | 23 | with open('loggingids.json') as f: 24 | loggingIDs = json.load(f) 25 | 26 | @bot.message_handler(func=lambda m: True, content_types=['new_chat_participant']) 27 | def on_user_joins(m): 28 | cid = m.chat.id 29 | inviter = m.from_user.first_name 30 | if m.content_type == 'new_chat_participant': 31 | if m.new_chat_participant.id == bot.get_me().id: 32 | chatid = m.chat.id 33 | if str(cid) not in user: 34 | user.append(str(cid)) 35 | with open('user.txt', 'a') as f: 36 | f.write(str(cid)+"\n") 37 | bot.send_message(cid, "WOAAH! That was a very fast transport! 😨\nHi! My Name is Logging Bot clone! \n" + str(inviter) + " has invited me into this group!\n\nIf you want to Setup me type /setup into the Chat.\nI will try to bridge all your messages to another group! 😉\nIf you want to see all the cute guys behind the Bot type /credits 😇") 38 | print "New group received." 39 | userwhogotadded = m.new_chat_participant.first_name 40 | username = m.new_chat_participant.username 41 | groupname = m.chat.title 42 | groupid = m.chat.id 43 | bot.send_message(YOUR DEBUG ID, "# DEBUG # " + "Bot got invited to the group " + str(groupname) + "(" + str(groupid) + ")", parse_mode="HTML") 44 | 45 | 46 | 47 | @bot.message_handler(commands=['yes']) 48 | def yes(m): 49 | cid = m.chat.id 50 | user = m.from_user.first_name 51 | bot.send_message(YOUR DEBUG ID, str(user) + " had Problems in setting up." , parse_mode="Markdown") 52 | bot.send_message(cid, "Thank you very much for making our Bot better!") 53 | 54 | @bot.message_handler(commands=['no']) 55 | def no(m): 56 | cid = m.chat.id 57 | user = m.from_user.first_name 58 | bot.send_message(YOUR DEBUG ID, str(user) + " had no Problems in setting the Bot up." , parse_mode="Markdown") 59 | bot.send_message(cid, "Thank you very much for making our Bot better!") 60 | 61 | @bot.message_handler(commands=['credits']) 62 | def credits(m): 63 | cid = m.chat.id 64 | bot.send_message(cid, "_Open-source Group Logging Bot_ https://github.com/aRandomStranger/TelegramLoggingBot/ \n*Thank you very much to all of these guys! \nI (@aRandomStranger) really love this projekt! <3* Thanks to:\nEdurolp for helping out with Debugging shit\nGunny, Jack and Edu for supporting users and answer to their questions\n \nAlso thanks to Frank Wang for the wonderfull API!", parse_mode="Markdown") 65 | 66 | @bot.message_handler(commands=['help']) 67 | def help(m): 68 | cid = m.chat.id 69 | bot.send_message(cid, "*Bot Help Page*\n\n/setup - Start setup the Bot in this group\n/setloggingid - Sets a group ID to log all messages and send it into the group\n/id - Gets the current group-id\n /nobroadcasts - Opts you from Broadcasts out.\nAlso if you like to support our work please rate the bot at https://telegram.me/storebot?start=IchLoggeBot", parse_mode="Markdown") 70 | 71 | @bot.message_handler(commands=['setloggingid']) 72 | def setloginggid(m): 73 | idA, cid = m.chat.id, m.chat.id 74 | if len(m.text.split()) != 2: 75 | bot.send_message(cid, "Usage: /setloggingid ") 76 | return 77 | try: 78 | idB = int(m.text.split()[1]) 79 | except: 80 | bot.send_message(cid, "Usage: /setloggingid ") 81 | return 82 | bot.send_message(cid, "Group {} messages will be sent to {}".format(idA,idB)) 83 | loggingIDs[str(idA)] = str(idB) 84 | with open('loggingids.json','w') as f: 85 | json.dump(loggingIDs, f) 86 | 87 | 88 | @bot.message_handler(commands=['setup']) 89 | def welcome(m): 90 | cid = m.chat.id 91 | bot.send_message(cid, "*Welcome to this group!*\n *1)* Create a *new* Group and add the Bot into the Group.\n *2)* Type /id and copy the group-ID.\n *3)* Finish the setup by type /setloggingid in the group where the messages shall get noticed. Make sure you set the id WITH the minus ( - ) sign.\n* 4)* You are *finished!* _The Bot will start collecting and sending messages into the Logging Group!_\n", parse_mode="Markdown") 92 | 93 | def handle_messages(messages): 94 | for m in messages: 95 | prcs_msg(m) 96 | 97 | def prcs_msg(m): 98 | cid = m.chat.id 99 | if str(cid) in loggingIDs: 100 | try: 101 | bot.forward_message(int(loggingIDs[str(cid)]), cid, m.message_id) 102 | except: 103 | pass 104 | 105 | @bot.message_handler(commands=['id']) 106 | def id(m): 107 | cid = m.chat.id 108 | uid = m.from_user.id 109 | if cid > 0: 110 | bot.send_message( cid, "This feature is only in group chats available!") 111 | else: 112 | bot.send_message( cid, "Hi %s , The group ID is %s.\nUse it to setup a logging group!" %(m.from_user.first_name, cid)) 113 | print "ID command received" 114 | 115 | 116 | bot.set_update_listener(handle_messages) 117 | 118 | bot.polling(none_stop=True, interval=0, timeout=3) 119 | 120 | -------------------------------------------------------------------------------- /loggingids.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /user.txt: -------------------------------------------------------------------------------- 1 | xx This is the User-ID File xx 2 | xx Every added ID will be saved here. xx 3 | --------------------------------------------------------------------------------