1+ import ts3lib , ts3defines
2+ from ts3plugin import ts3plugin , PluginHost
3+ from pytson import getCurrentApiVersion
4+ from bluscream import timestamp , getScriptPath , getChannelPassword
5+
6+ def loadCfg (path ):
7+ result = {}
8+ with open (path ) as fp :
9+ for line in fp :
10+ line = line .split ('=' , 1 )
11+ result [line [0 ].strip ()] = line [1 ].strip ()
12+ return result
13+
14+ def saveCfg (path , cfg :dict ):
15+ lines = []
16+ for k ,v in cfg .items ():
17+ lines .append ("%s=%s" % (k ,v ))
18+ if len (lines ) < 1 : return
19+ outF = open (path , "w" )
20+ outF .writelines (map (lambda s : s + '\n ' , lines ))
21+ outF .close ()
22+
23+ # noinspection PyArgumentList
24+ class shittyExploits (ts3plugin ):
25+ path = getScriptPath (__name__ )
26+ name = "Shitty Exploits"
27+ try : apiVersion = getCurrentApiVersion ()
28+ except : apiVersion = 21
29+ requestAutoload = True
30+ version = "1.0"
31+ author = "Bluscream"
32+ description = ""
33+ offersConfigure = False
34+ commandKeyword = ""
35+ infoTitle = "[b]Shitty Exploits[/b]:"
36+ hotkeys = []
37+ menuItems = [
38+ (ts3defines .PluginMenuType .PLUGIN_MENU_TYPE_CHANNEL , 0 , "Reconnect here" , "scripts/%s/refresh.svg" % __name__ ),
39+ (ts3defines .PluginMenuType .PLUGIN_MENU_TYPE_CHANNEL , 1 , "Reconnect with TP" , "scripts/%s/refresh.svg" % __name__ ),
40+ (ts3defines .PluginMenuType .PLUGIN_MENU_TYPE_CHANNEL , 2 , "Reconnect with Commander" , "scripts/%s/refresh.svg" % __name__ ),
41+ (ts3defines .PluginMenuType .PLUGIN_MENU_TYPE_CHANNEL , 3 , "Reconnect with Recording" , "scripts/%s/refresh.svg" % __name__ ),
42+ (ts3defines .PluginMenuType .PLUGIN_MENU_TYPE_CHANNEL , 4 , "Reconnect with All" , "scripts/%s/refresh.svg" % __name__ ),
43+ ]
44+ ini = ""
45+ cfg = {}
46+
47+ def __init__ (self ):
48+ self .ini = "%s/shittyExploits/config.ini" % ts3lib .getPluginPath ()
49+ self .cfg = loadCfg (self .ini )
50+ if PluginHost .cfg .getboolean ("general" , "verbose" ): ts3lib .printMessageToCurrentTab ("{0}[color=orange]{1}[/color] Plugin for pyTSon by [url=https://github.com/{2}]{2}[/url] loaded." .format (timestamp (), self .name , self .author ))
51+
52+ def onMenuItemEvent (self , schid , atype , mID , selectedItemID ):
53+ self .cfg ["client_is_talker" ] = 1 if mID in [1 ,4 ] else 0
54+ self .cfg ["client_is_channel_commander" ] = 1 if mID in [2 ,4 ] else 0
55+ self .cfg ["client_is_recording" ] = 1 if mID in [3 ,4 ] else 0
56+ saveCfg (self .ini , self .cfg )
57+ print (self .cfg )
58+ self .reconnect (schid , selectedItemID )
59+
60+ def infoData (self , schid , id , atype ):
61+ if atype != ts3defines .PluginItemType .PLUGIN_CHANNEL :
62+ return None
63+ with open (self .ini , encoding = "utf-8" ) as f :
64+ return [line .rstrip ('\n ' ) for line in f .readlines ()]
65+
66+ def reconnect (self , schid = 0 , cid = 0 ):
67+ if not schid : schid = ts3lib .getCurrentServerConnectionHandlerID ()
68+ err , host , port , pw = ts3lib .getServerConnectInfo (schid )
69+ address = host if not "." in host else "{}:{}" .format (host ,port )
70+ # ts3lib.stopConnection(schid, "")
71+ err , nickname = ts3lib .getClientSelfVariable (schid , ts3defines .ClientProperties .CLIENT_NICKNAME )
72+ err , nickname_phonetic = ts3lib .getClientSelfVariable (schid , ts3defines .ClientPropertiesRare .CLIENT_NICKNAME_PHONETIC )
73+ cpw = ""
74+ if not cid :
75+ err , cid = ts3lib .getClientSelfVariable (schid , ts3defines .ClientProperties .CLIENT_DEFAULT_CHANNEL )
76+ err , cpw = ts3lib .getClientSelfVariable (schid , ts3defines .ClientProperties .CLIENT_DEFAULT_CHANNEL_PASSWORD )
77+ else :
78+ (err , cid , cpw ) = ts3lib .getChannelConnectInfo (schid , cid )
79+ err , default_token = ts3lib .getClientSelfVariable (schid , ts3defines .ClientPropertiesRare .CLIENT_DEFAULT_TOKEN )
80+ args = [
81+ ts3defines .PluginConnectTab .PLUGIN_CONNECT_TAB_CURRENT , # connectTab: int,
82+ address , # serverLabel: Union[str, unicode],
83+ address , # serverAddress: Union[str, unicode],
84+ pw , # serverPassword: Union[str, unicode],
85+ nickname , # nickname: Union[str, unicode],
86+ cid , # channel: Union[str, unicode],
87+ cpw if cpw else "123" , # channelPassword: Union[str, unicode]
88+ "" , # captureProfile: Union[str, unicode],
89+ "" , # playbackProfile: Union[str, unicode]
90+ "" , # hotkeyProfile: Union[str, unicode],
91+ "" , # userIdentity: Union[str, unicode],
92+ default_token , # oneTimeKey: Union[str, unicode],
93+ nickname_phonetic , # phoneticName: Union[str, unicode]
94+ "" , # No idea
95+ ]
96+ print ("ts3lib.guiConnect({})" .format ("\" , \" " .join (str (x ) for x in args )))
97+ ts3lib .guiConnect (args [0 ],args [1 ],args [2 ],args [3 ],args [4 ],args [5 ],args [6 ],args [7 ],args [8 ],args [9 ],args [10 ],args [11 ],args [12 ], args [13 ])
0 commit comments