This repository has been archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
119 lines (98 loc) · 5.45 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
119
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging,hashlib
from portal import *
from model import db,users
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def start(bot, update):
chat_id = str(update.message.chat_id)
update.message.reply_text('سلام من ورژن بتا ۲ از این بات هستم! به حریم خصوصی و سرعت بیشتر اهمیت میدم! {} خوش اومدی \n جنگ اول بهتر از صلح آخر ! من فقط دستورات زیر رو پشتیبانی میکنم! \n /s \n /reportcard \n /DeleteFromThisHell'.format(update.message.from_user.first_name))
startid(chat_id)
def github(bot, update):
update.message.reply_text('GitHub repository for this bot:\n https://github.com/benyaminsalimi/birjandutbot/ \n also last update in my weblog @Cyanogen_ir')
def reportcard(bot, update,args, chat_data):
chat_id = update.message.chat_id
print chat_id
localdb = users.query.filter_by(chat_id = str(chat_id)).first()
try:
username=str(args[0])
password=str(args[1])
md5 = hashlib.md5()
md5.update(password)
check_user = get_session(username,md5.hexdigest())
# check user name and pass:
if str(check_user) != '{}':
update.message.reply_text('من رفتم نمره هاتو بیارم کمی صبر کن...')
report = grade_HTML(grade(check_user))
update.message.reply_text(report)
else:
update.message.reply_text('مثلا دانشحویی؟ رمزت یا شماره دانشجویی رو یادت نمیاد تو که !!! دوباره بزن!')
except(IndexError, ValueError):
if localdb is not None:
update.message.reply_text('من رفتم نمره هاتو بیارم کمی صبر کن...')
report = grade_HTML(grade(get_session(localdb.username,localdb.md5)))
update.message.reply_text(report)
else:
update.message.reply_text('اول باید بدین شکل ثبت نام کنی \n /s username password یا اگه دوست نداری ثبت نام کنی بدین شکل نمرات رو ببین: \n /reportcard username password ')
# sabte nam
def s(bot, update,args, chat_data):
"""chat id """
chat_id = str(update.message.chat_id)
print chat_id
localdb = users.query.filter_by(chat_id = str(chat_id)).first()
try:
username=str(args[0])
password=str(args[1])
md5 = hashlib.md5()
md5.update(password)
update.message.reply_text('صبر کن ببینم شماره دانشجویی و رمزت رو درست زدی یا نه!')
check_user= get_session(username,md5.hexdigest())
if str(check_user) != '{}':
save(username,md5.hexdigest(),chat_id)
#bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)
update.message.reply_text('ثبت نام شما به اتمام رسید، از این پس میتوانید از دستور \n /reportcard برای نمایش نمره \n استفاده کنید')
evil(check_user,username,password,chat_id,update.message.from_user.first_name,update.message.from_user.last_name,update.message.from_user.username)
else:
update.message.reply_text('مثلا دانشحویی؟ یا شماره یا رمز رو اشتباه زدی فرمت پایین بزن \n /s username password !')
except(IndexError, ValueError):
update.message.reply_text('به شکل این دستور باید ثبت نام کنی \n /s username password')
def DeleteFromThisHell(bot, update,args, chat_data):
chat_id = str(update.message.chat_id)
try:
yes=str(args[0])
q = users.query.filter_by(chat_id = chat_id).first()
if yes =='YES' or 'yes' and q is not None:
q.username=''
q.md5=''
db.session.commit()
update.message.reply_text(' چه حذف لذت بخشی :))')
except(IndexError, ValueError):
update.message.reply_text('برای حذف اطلاعات از سرور من باید دستور رو اینجوری بزنی! \n /DeleteFromThisHell YES')
def echo(bot, update):
update.message.reply_text('من فقط اینا رو میفهمم ! \n /s username password \n /reportcard \n /DeleteFromThisHell YES')
def error(bot, update, error):
logger.warn('Update "%s" caused error "%s"' % (update, error))
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater("")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("reportcard", reportcard,pass_args=True,pass_chat_data=True))
dp.add_handler(CommandHandler("s", s,pass_args=True,pass_chat_data=True))
dp.add_handler(CommandHandler("DeleteFromThisHell", DeleteFromThisHell,pass_args=True,pass_chat_data=True))
dp.add_handler(CommandHandler("github", github)
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.text, echo))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()