-
Notifications
You must be signed in to change notification settings - Fork 15
/
bot.py
119 lines (95 loc) · 4.69 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
#-*- coding:utf-8 -*-
import sys
import time
reload(sys)
sys.setdefaultencoding("utf-8")
print "[System] Bot has started."
user = [line.rstrip('\n') for line in open('user.txt','rt')]
import telebot
import random
import json
import time
from pprint import pprint
API_TOKEN = 'YOUR TOKEN'
bot = telebot.TeleBot(API_TOKEN)
with open('loggingids.json') as f:
loggingIDs = json.load(f)
@bot.message_handler(func=lambda m: True, content_types=['new_chat_participant'])
def on_user_joins(m):
cid = m.chat.id
inviter = m.from_user.first_name
if m.content_type == 'new_chat_participant':
if m.new_chat_participant.id == bot.get_me().id:
chatid = m.chat.id
if str(cid) not in user:
user.append(str(cid))
with open('user.txt', 'a') as f:
f.write(str(cid)+"\n")
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 😇")
print "New group received."
userwhogotadded = m.new_chat_participant.first_name
username = m.new_chat_participant.username
groupname = m.chat.title
groupid = m.chat.id
bot.send_message(YOUR DEBUG ID, "# DEBUG # " + "Bot got invited to the group " + str(groupname) + "(" + str(groupid) + ")", parse_mode="HTML")
@bot.message_handler(commands=['yes'])
def yes(m):
cid = m.chat.id
user = m.from_user.first_name
bot.send_message(YOUR DEBUG ID, str(user) + " had Problems in setting up." , parse_mode="Markdown")
bot.send_message(cid, "Thank you very much for making our Bot better!")
@bot.message_handler(commands=['no'])
def no(m):
cid = m.chat.id
user = m.from_user.first_name
bot.send_message(YOUR DEBUG ID, str(user) + " had no Problems in setting the Bot up." , parse_mode="Markdown")
bot.send_message(cid, "Thank you very much for making our Bot better!")
@bot.message_handler(commands=['credits'])
def credits(m):
cid = m.chat.id
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")
@bot.message_handler(commands=['help'])
def help(m):
cid = m.chat.id
bot.send_message(cid, "*Bot Help Page*\n\n/setup - Start setup the Bot in this group\n/setloggingid <Group-ID> - 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")
@bot.message_handler(commands=['setloggingid'])
def setloginggid(m):
idA, cid = m.chat.id, m.chat.id
if len(m.text.split()) != 2:
bot.send_message(cid, "Usage: /setloggingid <ID>")
return
try:
idB = int(m.text.split()[1])
except:
bot.send_message(cid, "Usage: /setloggingid <ID>")
return
bot.send_message(cid, "Group {} messages will be sent to {}".format(idA,idB))
loggingIDs[str(idA)] = str(idB)
with open('loggingids.json','w') as f:
json.dump(loggingIDs, f)
@bot.message_handler(commands=['setup'])
def welcome(m):
cid = m.chat.id
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 <ID of other Group> 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")
def handle_messages(messages):
for m in messages:
prcs_msg(m)
def prcs_msg(m):
cid = m.chat.id
if str(cid) in loggingIDs:
try:
bot.forward_message(int(loggingIDs[str(cid)]), cid, m.message_id)
except:
pass
@bot.message_handler(commands=['id'])
def id(m):
cid = m.chat.id
uid = m.from_user.id
if cid > 0:
bot.send_message( cid, "This feature is only in group chats available!")
else:
bot.send_message( cid, "Hi %s , The group ID is %s.\nUse it to setup a logging group!" %(m.from_user.first_name, cid))
print "ID command received"
bot.set_update_listener(handle_messages)
bot.polling(none_stop=True, interval=0, timeout=3)