def plugin_prefs(parent, cmdr, is_beta): """ Return a TK Frame for adding to the EDMC settings dialog. """ if isinstance(appversion, str): core_version = semantic_version.Version(appversion) elif callable(appversion): core_version = appversion() logger.info(f'Core EDMC version: {core_version}') if core_version < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') this.disablePresence = tk.IntVar( value=config.getint("disable_presence")) else: logger.info('EDMC core version is at least 5.0.0-beta1') this.disablePresence = tk.IntVar( value=config.get_int("disable_presence")) frame = nb.Frame(parent) nb.Checkbutton(frame, text="Disable Presence", variable=this.disablePresence).grid() nb.Label(frame, text='Version %s' % VERSION).grid(padx=10, pady=10, sticky=tk.W) return frame
def plugin_start3(plugin_dir: str) -> str: """Start the telemetry plugin.""" if callable( appversion) and appversion() >= semantic_version.Version("5.0.0"): connect_telemetry() else: logger.fatal("EDMC-Telemetry requires EDMC 5.0.0 or newer.") status_message(message="ERROR: EDMC < 5.0.0", color="red", immediate=True) return "Telemetry"
def update_presence(): if isinstance(appversion, str): core_version = semantic_version.Version(appversion) elif callable(appversion): core_version = appversion() logger.info(f'Core EDMC version: {core_version}') if core_version < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') if config.getint("disable_presence") == 0: this.activity.state = this.presence_state this.activity.details = this.presence_details else: logger.info('EDMC core version is at least 5.0.0-beta1') if config.get_int("disable_presence") == 0: this.activity.state = this.presence_state this.activity.details = this.presence_details this.activity.timestamps.start = int(this.time_start) this.activity_manager.update_activity(this.activity, callback)
def journal_entry(cmdr, is_beta, system, station, entry, state): """ E:D client made a journal entry :param cmdr: The Cmdr name, or None if not yet known :param system: The current system, or None if not yet known :param station: The current station, or None if not docked or not yet known :param entry: The journal entry as a dictionary :param state: A dictionary containing info about the Cmdr, current ship and cargo :return: """ #we are going to send events to Canonn, The whitelist tells us which ones try: whiteList.journal_entry(cmdr, is_beta, system, station, entry, state, "Hutton-Helper-{}".format(HH_VERSION)) except: print("Canonn failed, but don't let that stop you") if is_beta: this.status['text'] = 'Disabled due to beta' return entry['commandername'] = cmdr news.commander = cmdr entry['hhstationname'] = station entry['hhsystemname'] = system entry['huttonappversion'] = HH_VERSION if isinstance(appversion, str): entry['edmcversion'] = appversion else: entry['edmcversion'] = str(appversion()) entry['uuid'] = UUID compress_json = json.dumps(entry) compress_json = compress_json.encode('utf-8') transmit_json = zlib.compress(compress_json) event = entry['event'] #sys.stderr.write('event: {}\r\n'.format(event)) #Very Chatty # Declare a function to make it easy to send the event to the server and get the response. # We've smuggled the transmit_json variable from journal_entry into xmit_event using a # keyword argument because Python 2.x doesn't have 'nonlocal'. Also, cmdr and system: def xmit_event(path, transmit_json=transmit_json, cmdr=cmdr, system=system): "Transmit the event to our server at ``path.format(cmdr=cmdr, system=system)``." path = path.format(cmdr=cmdr, system=system) return xmit.post(path, data=transmit_json, headers=xmit.COMPRESSED_OCTET_STREAM) # If we can find an entry in STATUS_FORMATS, fill in the string and display it to the user: status_format = EVENT_STATUS_FORMATS.get(event) if status_format: this.status['text'] = status_format.format(**entry) # Update the plugins for plugin in this.plugins: try: plugin.journal_entry(cmdr, is_beta, system, station, entry, state) except: PANIC("{}.journal_entry".format(plugin)) # Special event handling, which happens IN ADDITION TO the automatic transmission and # status message handling above: if event == 'MarketBuy': # For some events, we need our status to be based on translations of the event that # string.format can't do without a scary custom formatter: this.status['text'] = "{:,.0f} {} bought".format( float(entry['Count']), ITEM_LOOKUP.get(entry['Type'], entry['Type'])) elif event == 'MarketSell': this.status['text'] = "{:,.0f} {} sold".format( float(entry['Count']), ITEM_LOOKUP.get(entry['Type'], entry['Type'])) elif event == 'FactionKillBond': this.status['text'] = "Kill Bond Earned for {:,.0f} credits".format( float(entry['Reward'])) elif event == 'Bounty': this.status['text'] = "Bounty Earned for {:,.0f} credits".format( float(entry['TotalReward'])) elif event == 'RedeemVoucher': # For some events, we need to check another lookup table. There are ways to make the original lookup table # do this heavy lifting, too, but it'd make the code above more complicated than a trucker who'd only just # learned Python could be expected to maintain. redeem_status_format = REDEEM_TYPE_STATUS_FORMATS.get(entry['Type']) if redeem_status_format: this.status['text'] = redeem_status_format.format( float(entry['Amount'])) xmit_event('/redeemvoucher') elif event == 'SellExplorationData': baseval = entry['BaseValue'] bonusval = entry['Bonus'] totalvalue = entry['TotalEarnings'] this.status[ 'text'] = "Sold ExplorationData for {:,.0f} credits".format( float(totalvalue)) elif event == 'MultiSellExplorationData': baseval = entry['BaseValue'] bonusval = entry['Bonus'] totalvalue = entry['TotalEarnings'] this.status[ 'text'] = "Sold ExplorationData for {:,.0f} credits".format( float(totalvalue))