-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
55 lines (41 loc) · 1.68 KB
/
main.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
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler
import logging
import configparser
import subprocess
from pathlib import Path
config_file = Path("config.ini")
if config_file.is_file():
with config_file.open() as f:
config = configparser.ConfigParser()
config.read_file(f)
TOKEN = config.get('DEFAULT', 'Token')
USERID = config.get('DEFAULT', 'UserId')
else:
print("config.ini non trovato")
exit(1)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
all_commands = {}
task = lambda f: all_commands.setdefault(f.__name__, f)
@task
def send_public_ip(update, context):
if update.effective_chat.type == 'private':
if str(update.effective_user.id) == USERID:
try:
my_public_ip = subprocess.run(["dig", "+short", "myip.opendns.com", "@resolver1.opendns.com"], check=True,
capture_output=True, encoding='utf-8').stdout
update.message.reply_text("Il Tuo Ip : {}".format(str(my_public_ip)))
except :
update.message.reply_text("Something went wrong :)")
else:
update.message.reply_text("This bot is not for you ! :)")
else:
update.message.reply_text("I'm Sorry. This is Command is only for private chat :)")
def main():
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
send_public_ip_handler = CommandHandler('sendPublicIp', send_public_ip)
dispatcher.add_handler(send_public_ip_handler)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()