forked from ja7ad/PyCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
executable file
·150 lines (125 loc) · 5.27 KB
/
Copy pathbot.py
File metadata and controls
executable file
·150 lines (125 loc) · 5.27 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- coding: utf-8 -*-
import json
import os
import telegram
from telegram.ext import CommandHandler
from telegram.ext import Filters
from telegram.ext import MessageHandler
from telegram.ext import Updater
from src.api import RextesterApi
from src.logger import Logger
rex = RextesterApi()
log = Logger()
def clang(bot, update):
msg = "اوکی, لطفا کدی که به زبان C هست را برایم بفرستید"
log.info("CLang Request.")
bot.message.reply_text(msg)
def cpplang(bot, update):
msg = "اوکی, لطفا کدی که به زبان ++C هست را برایم بفرستید"
log.info("C++ Request.")
bot.message.reply_text(msg)
def mysql(bot, update):
msg = "اوکی, لطفا کدی که به زبان MySQL هست را برایم بفرستید"
log.info("MySQL Request.")
bot.message.reply_text(msg)
def sql_server(bot, update):
msg = "اوکی, لطفا کدی که به زبان SQL Server هست را برایم بفرستید"
log.info("SQL Server Request.")
bot.message.reply_text(msg)
def psql(bot, update):
msg = "اوکی, لطفا کدی که به زبان PostgreSQL هست را برایم بفرستید"
log.info("PostgreSQL Request.")
bot.message.reply_text(msg)
def python3(bot, update):
msg = "اوکی, لطفا کدی که به زبان Python 3 هست را برایم بفرستید"
log.info("Python 3 Request.")
bot.message.reply_text(msg)
def get_code(bot, update):
msg = bot.message or bot.edited_message
code = msg.text
msg_reply = msg.reply_to_message.text
cid = msg.from_user.first_name
really_cid = msg.from_user.id
callback_result(msg, code, msg_reply, cid, really_cid)
def callback_result(message, code, msg_reply, cid, really_cid):
if ("import os" in code and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text("استفاده از کتابخانه os مجاز نیست.")
if msg_reply:
if ("C" in msg_reply and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text(
rex.rextester_api(6, code, cid, really_cid),
parse_mode=telegram.ParseMode.MARKDOWN,
)
elif ("C++" in msg_reply and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text(
rex.rextester_api(7, code, cid, really_cid),
parse_mode=telegram.ParseMode.MARKDOWN,
)
elif ("MySQL" in msg_reply
and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text(
rex.rextester_api(33, code, cid, really_cid),
parse_mode=telegram.ParseMode.MARKDOWN,
)
elif ("SQL Server" in msg_reply
and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text(
rex.rextester_api(16, code, cid, really_cid),
parse_mode=telegram.ParseMode.MARKDOWN,
)
elif ("PostgreSQL" in msg_reply
and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text(
rex.rextester_api(34, code, cid, really_cid),
parse_mode=telegram.ParseMode.MARKDOWN,
)
elif ("Python 3" in msg_reply
and ("اوکی, لطفا کدی که به زبان" in msg_reply)
and "." not in msg_reply):
message.reply_text(
rex.rextester_api(24, code, cid, really_cid),
parse_mode=telegram.ParseMode.MARKDOWN,
)
def get_settings():
if os.path.exists("./settings.json"):
with open("./settings.json") as setting_file:
setting = json.load(setting_file)
return {
"token": setting["token"],
"proxy": setting["proxy"],
"proxy_address": setting["proxy_address"],
}
raise Exception("setting.json not found.")
if __name__ == "__main__":
settings = get_settings()
if settings["proxy"]:
updater = Updater(
settings["token"],
use_context=True,
request_kwargs={
"proxy_url": f"socks5h://{settings['proxy_address']}"
},
)
else:
updater = Updater(settings["token"], use_context=True)
dp = updater.dispatcher
dp.add_handler(
MessageHandler(
filters=(Filters.chat_type.groups & Filters.text & Filters.reply),
callback=get_code,
))
dp.add_handler(CommandHandler("py", python3, Filters.chat_type.groups))
dp.add_handler(CommandHandler("c", clang, Filters.chat_type.groups))
dp.add_handler(CommandHandler("cpp", cpplang, Filters.chat_type.groups))
dp.add_handler(CommandHandler("mysql", mysql, Filters.chat_type.groups))
dp.add_handler(
CommandHandler("sqlsv", sql_server, Filters.chat_type.groups))
dp.add_handler(CommandHandler("psql", psql, Filters.chat_type.groups))
updater.start_polling()
updater.idle()