forked from Nikotecnology/ServerAccessLogging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
50 lines (39 loc) · 1.98 KB
/
Copy pathbot.py
File metadata and controls
50 lines (39 loc) · 1.98 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
import os
from importlib.machinery import SourceFileLoader
import telegram
from telegram.ext.callbackcontext import CallbackContext
from telegram.ext.commandhandler import CommandHandler
from telegram.ext.filters import Filters
from telegram.ext.messagehandler import MessageHandler
from telegram.ext.updater import Updater
from telegram.update import Update
# var = SourceFileLoader("var","/etc/profile.d/var.py").load_module()
TOKEN = os.environ.get('TOKEN')
USER_ID = os.environ.get('USER')
USERNAME = os.environ.get('USERNAME')
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
bot = telegram.Bot(token=TOKEN)
def closelast(update: Update, context: CallbackContext):
if (update.message.chat_id == USER_ID and update.message.chat.username == USERNAME) :
message = update.message.text
arguments = message.split(" ")
os.system("pkill -9 -t " + arguments[1])
else:
update.message.reply_text("L'id non corrisponde con quello fornito nel file .env")
chatidv = update.message.chat_id
usernamev = update.message.chat.username
namev = update.message.chat.full_name
bot.send_message(chat_id = USER_ID, text = namev + "(Username: @" + usernamev + ", ChatId = " + chatidv + ") tryed to kill the last ssh login")
def unknown(update: Update, context: CallbackContext):
update.message.reply_text(
"'%s' isn't a known command" % update.message.text)
def unknown_text(update: Update, context: CallbackContext):
update.message.reply_text("i can't understand '%s'" % update.message.text)
def start(update: Update, context: CallbackContext):
update.message.reply_text("Welcome user" % update.message.text)
updater.dispatcher.add_handler(CommandHandler('closelast', closelast))
updater.dispatcher.add_handler(MessageHandler(Filters.text, unknown))
updater.dispatcher.add_handler(MessageHandler(Filters.command, unknown))
updater.dispatcher.add_handler(MessageHandler(Filters.text, unknown_text))
updater.start_polling()