def __init__(self): self.app = QApplication.instance() loadCfg(self.ini, self.cfg) 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))
def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID): if menuItemID != 0: return if atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL: if schid in self.targets: self.stop("", schid, self.targets[schid]) else: ts3lib.printMessageToCurrentTab( "{} {}: [color=red]Not following anyone on this tab.[/color]" .format(timestamp(), self.name)) uid = inputBox(self.name, "UID:", QApplication.clipboard().text()) parsed = parseClientURL(uid) if parsed: uid = parsed[1] elif atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CLIENT: (err, ownID) = ts3lib.getClientID(schid) if selectedItemID == ownID: return (err, uid) = ts3lib.getClientVariable( schid, selectedItemID, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) if not uid: ts3lib.printMessageToCurrentTab( "{} {}: [color=red]Cannot follow[/color] {}".format( timestamp(), self.name, selectedItemID)) return self.targets[schid] = uid ts3lib.printMessageToCurrentTab( "{} {}: [color=green]Now auto-following[/color] {}".format( timestamp(), self.name, clientURL(schid, selectedItemID))) if PluginHost.cfg.getboolean("general", "verbose"): print(self.name, "> self.targets[schid]", self.targets[schid], "selectedItemID", selectedItemID) self.joinTarget(schid)
def getText(self, multimsg=True, multiline=False, title="Enter text here", text="", max=1024): try: x = QDialog() x.setAttribute(Qt.WA_DeleteOnClose) if multiline: clipboard = QApplication.clipboard().text() _message = QInputDialog.getMultiLineText( x, title, text, clipboard) else: _message = QInputDialog.getText(x, title, text, QLineEdit.Normal, "", self.ok) if multimsg: return [ _message[i:i + max] for i in range(0, len(_message), max) ] else: return _message[:max] except: from traceback import format_exc ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def widgetbyobject(name): name = name.lower() instance = QApplication.instance() widgets = instance.topLevelWidgets() widgets = widgets + instance.allWidgets() for x in widgets: if str(x.objectName).lower() == name: return x
def grabWidget(objName, byClass=False): for widget in QApplication.instance().allWidgets(): try: if byClass and widget.className() == objName: return widget elif widget.objectName == objName: return widget except: ts3lib.logMessage(format_exc(), LogLevel.LogLevel_ERROR, "PyTSon", 0)
def widgets(name, app=None): if app is None: app = QApplication.instance() widgets = app.allWidgets() ret = [] for x in widgets: if str(x.objectName) == name: ret.append(x) return ret
def disconnect(self, schid=0, close_tab=False): if schid < 1: schid = ts3lib.getCurrentServerConnectionHandlerID() (err, status) = ts3lib.getConnectionStatus(schid) if status != ts3defines.ConnectStatus.STATUS_CONNECTION_ESTABLISHED: return clipboard = QApplication.clipboard().text() msg = inputBox("Disconnect", "Message", clipboard) if close_tab: self.schid = schid ts3lib.stopConnection(schid, msg if msg else "")
def widgetbyclass(name): ret = [] instance = QApplication.instance() widgets = instance.topLevelWidgets() widgets = widgets + instance.allWidgets() for x in widgets: if name in str(x.__class__).replace("<class '", "").replace("'>", ""): ret.extend(x) return ret
def onMenuItemEvent(self, schid, atype, menuItemID, channel): if menuItemID == 0: err, cids = ts3lib.getChannelList(schid) channels = dict() for cid in cids: (err, name) = ts3lib.getChannelVariable( schid, cid, ts3defines.ChannelProperties.CHANNEL_NAME) (err, order) = ts3lib.getChannelVariable( schid, cid, ts3defines.ChannelProperties.CHANNEL_ORDER) if err == ts3defines.ERROR_ok and name: channels[order] = name channels = OrderedDict(sorted(channels.items(), key=lambda t: t[0])) for name in channels.values(): ts3lib.printMessageToCurrentTab(name) elif menuItemID == 1: description = ts3lib.getChannelVariableAsString( schid, channel, ts3defines.ChannelProperties.CHANNEL_DESCRIPTION)[1] ts3lib.printMessageToCurrentTab(description) QApplication.clipboard().setText(description)
def sendMessage(self, schid, targetMode, toID): x = QWidget() clipboard = QApplication.clipboard().text(); _message = QInputDialog.getMultiLineText(x, "Enter long text here", "", clipboard) message = [_message[i:i + self.maxsize] for i in range(0, len(_message), self.maxsize)] if targetMode == ts3defines.TextMessageTargetMode.TextMessageTarget_CHANNEL: for msg in message: error = ts3lib.requestSendChannelTextMsg(schid, "\n"+msg, toID) if not error == ts3defines.ERROR_ok: _t = QMessageBox(QMessageBox.Critical, "Error #%s"%error,"Unable to send message to #%s!"%toID);_t.show();return elif targetMode == ts3defines.TextMessageTargetMode.TextMessageTarget_CLIENT: for msg in message: error = ts3lib.requestSendPrivateTextMsg(schid, "\n"+msg, toID) if not error == ts3defines.ERROR_ok: _t = QMessageBox(QMessageBox.Critical, "Error #%s"%error,"Unable to send message to #%s!"%toID);_t.show();return
def inputBox(title, text, default=""): """ :param default: :param title: :param text: :return: """ x = QWidget() x.setAttribute(Qt.WA_DeleteOnClose) ok = BoolResult() if not default: default = QApplication.clipboard().text() text = QInputDialog.getText(x, title, text, QLineEdit.Normal, default, ok) # QDir.Home.dirName() if ok: return text else: return False
def findWidget(name): try: name = name.lower() instance = QApplication.instance() widgets = instance.topLevelWidgets() widgets = widgets + instance.allWidgets() ret = dict() c = 0 for x in widgets: c += 1 if name in x.objectName.lower() or name in str( x.__class__).lower(): ret["class:" + str(x.__class__) + str(c)] = "obj:" + x.objectName continue if hasattr(x, "text"): if name in x.text.lower(): ret["class:" + str(x.__class__) + str(c)] = "obj:" + x.objectName return ret except: print("error")
def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID): try: url = "" if atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CLIENT: if menuItemID == 1: # Nickname (TSViewer) url = "http://www.tsviewer.com/index.php?page=search&action=ausgabe_user&nickname=%%CLIENT_NAME_PERCENT_ENCODED%%" elif menuItemID == 2: # Nickname (GameTracker) url = "http://www.gametracker.com/search/?search_by=online_offline_player&query=%%CLIENT_NAME_PERCENT_ENCODED%%" elif menuItemID == 3: # Nickname (TS3Index) url = "http://ts3index.com/?page=searchclient&nickname=%%CLIENT_NAME_PERCENT_ENCODED%%" elif menuItemID == 4: # Nickname (Google) url = "https://www.google.com/search?q=%%CLIENT_NAME_PERCENT_ENCODED%%" elif menuItemID == 5: # Profil (GameTracker) url = "http://www.gametracker.com/search/?search_by=profile_username&query=%%CLIENT_NAME_PERCENT_ENCODED%%" elif menuItemID == 6: # UID (TS3Index) url = "http://ts3index.com/?page=searchclient&uid=%%CLIENT_UNIQUE_ID%%" elif menuItemID == 7: # UID (Google) url = "https://www.google.com/search?q=%%CLIENT_UNIQUE_ID%%" elif menuItemID == 8: # Besitzer (TSViewer) url = "http://www.tsviewer.com/index.php?page=search&action=ausgabe&suchbereich=ansprechpartner&suchinhalt=%%CLIENT_NAME_PERCENT_ENCODED%%" elif menuItemID == 9: # Badges (TS3Index) url = "https://ts3index.com/?page=searchclient&badges=%%CLIENT_BADGES%%" else: return # payload = {'username':'******', 'password':'******'} # nickname_encoded = urlencode(nickname, quote_via=quote_plus) # nickname_encoded = nickname_encoded.replace("+", "%2B").replace("/", "%2F").replace("=", "%3D") if "%%CLIENT_NAME_PERCENT_ENCODED%%" in url: if selectedItemID: (err, nickname) = ts3lib.getClientVariable( schid, selectedItemID, ts3defines.ClientProperties.CLIENT_NICKNAME) else: nickname = inputBox(self.name, "Nickname:", QApplication.clipboard().text()) parsed = parseClientURL(nickname) if parsed: nickname = parsed[2] else: nickname = QUrl.toPercentEncoding(nickname) url = url.replace("%%CLIENT_NAME_PERCENT_ENCODED%%", "{}".format(nickname)) if "%%CLIENT_UNIQUE_ID%%" in url: if selectedItemID: (err, uid) = ts3lib.getClientVariable( schid, selectedItemID, ts3defines.ClientProperties. CLIENT_UNIQUE_IDENTIFIER) else: uid = inputBox(self.name, "UID:", QApplication.clipboard().text()) parsed = parseClientURL(uid) if parsed: uid = parsed[1] url = url.replace("%%CLIENT_UNIQUE_ID%%", "{}".format(QUrl.toPercentEncoding(uid))) if "%%CLIENT_BADGES%%" in url: if selectedItemID: (err, badges) = ts3lib.getClientVariable( schid, selectedItemID, ts3defines.ClientPropertiesRare.CLIENT_BADGES) else: badges = inputBox(self.name, "Badges:", QApplication.clipboard().text()) url = url.replace("%%CLIENT_BADGES%%", badges) else: return if PluginHost.cfg.getboolean("general", "verbose"): ts3lib.printMessageToCurrentTab( "Opening URL: \"{}\"".format(url)) QDesktopServices.openUrl(QUrl(url)) except: ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)