forked from Waterboy1602/Addarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransmission.py
85 lines (71 loc) · 2.35 KB
/
transmission.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
import os
import yaml
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import ConversationHandler
from commons import authentication, checkAdmin, checkId
from config import config
from translations import i18n
config = config["transmission"]
TSL_LIMIT = 'limited'
TSL_NORMAL = 'normal'
def transmission(update, context):
if not config["enable"]:
context.bot.send_message(
chat_id=update.effective_message.chat_id,
text=i18n.t("addarr.Transmission.NotEnabled"),
)
return ConversationHandler.END
if not checkId(update):
context.bot.send_message(
chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize")
)
return TSL_NORMAL
if not checkAdmin(update):
context.bot.send_message(
chat_id=update.effective_message.chat_id,
text=i18n.t("addarr.NotAdmin"),
)
return TSL_NORMAL
keyboard = [[
InlineKeyboardButton(
'\U0001F40C '+i18n.t("addarr.Transmission.TSL"),
callback_data=TSL_LIMIT
),
InlineKeyboardButton(
'\U0001F406 '+i18n.t("addarr.Transmission.Normal"),
callback_data=TSL_NORMAL
),
]]
markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text(
i18n.t("addarr.Transmission.Speed"), reply_markup=markup
)
return TSL_NORMAL
def changeSpeedTransmission(update, context):
if not checkId(update):
if (
authentication(update, context) == "added"
): # To also stop the beginning command
return ConversationHandler.END
choice = update.callback_query.data
command = f"transmission-remote {config['host']}"
if config["authentication"]:
command += (
" --auth "
+ config["username"]
+ ":"
+ config["password"]
)
message = None
if choice == TSL_NORMAL:
command += ' --no-alt-speed'
message = i18n.t("addarr.Transmission.ChangedToNormal")
elif choice == TSL_LIMIT:
command += ' --alt-speed'
message=i18n.t("addarr.Transmission.ChangedToTSL"),
os.system(command)
context.bot.send_message(
chat_id=update.effective_message.chat_id,
text=message,
)
return ConversationHandler.END