From a81f00d868e1873b882180fbf7d89624a65cffa6 Mon Sep 17 00:00:00 2001 From: aussig Date: Sun, 28 Jan 2024 16:52:14 +0000 Subject: [PATCH 1/5] Update CHANGELOG. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22a7850..464f985 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v3.4.0-xx - xxxx-xx-xx + + + ## v3.4.0-a1 - 2024-01-28 ### New Features: From ce31bbe1d9fd679c45444f660ff40064b9dfca4f Mon Sep 17 00:00:00 2001 From: aussig Date: Sun, 28 Jan 2024 18:39:52 +0000 Subject: [PATCH 2/5] No longer fail on first invalid webhook URL --- CHANGELOG.md | 3 +++ bgstally/discord.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 464f985..48bd502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## v3.4.0-xx - xxxx-xx-xx +### Bug Fixes: + +* If one of the discord webhook URLs was invalid, was failing immediately and wasn't trying any additional webhooks. ## v3.4.0-a1 - 2024-01-28 diff --git a/bgstally/discord.py b/bgstally/discord.py index 93398d4..ba82907 100644 --- a/bgstally/discord.py +++ b/bgstally/discord.py @@ -29,7 +29,7 @@ def post_plaintext(self, discord_text:str, webhooks_data:dict|None, channel:Disc for webhook in webhooks.values(): webhook_url:str = webhook.get('url') - if not self._is_webhook_valid(webhook_url): return + if not self._is_webhook_valid(webhook_url): continue # Get the previous state for this webhook's uuid from the passed in data, if it exists. Default to the state from the webhook manager specific_webhook_data:dict = {} if webhooks_data is None else webhooks_data.get(webhook.get('uuid', ""), webhook) @@ -72,7 +72,7 @@ def post_embed(self, title:str, description:str, fields:list, webhooks_data:dict for webhook in webhooks.values(): webhook_url:str = webhook.get('url') - if not self._is_webhook_valid(webhook_url): return + if not self._is_webhook_valid(webhook_url): continue # Get the previous state for this webhook's uuid from the passed in data, if it exists. Default to the state from the webhook manager specific_webhook_data:dict = {} if webhooks_data is None else webhooks_data.get(webhook.get('uuid', ""), webhook) From 1933d287791c54cd2c63583c0c6d47ebb2df08e0 Mon Sep 17 00:00:00 2001 From: aussig Date: Sun, 28 Jan 2024 19:55:26 +0000 Subject: [PATCH 3/5] Fix problems with post to discord button availability / state for new multi-channel support. Now always show post to discord buttons on FC and CMDR windows. --- CHANGELOG.md | 5 +++++ bgstally/discord.py | 25 +++++++------------------ bgstally/windows/activity.py | 11 +++++------ bgstally/windows/cmdrs.py | 14 +++++--------- bgstally/windows/fleetcarrier.py | 4 +++- 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48bd502..4660cda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,14 @@ ## v3.4.0-xx - xxxx-xx-xx +### Changes: + +* 'Post to Discord' button always visible (but greyed out if not usable) on Fleet Carrier and CMDR Information windows. + ### Bug Fixes: * If one of the discord webhook URLs was invalid, was failing immediately and wasn't trying any additional webhooks. +* Discord button enabling / disabling wasn't working properly with the new multiple discord channel support. ## v3.4.0-a1 - 2024-01-28 diff --git a/bgstally/discord.py b/bgstally/discord.py index ba82907..8a318ba 100644 --- a/bgstally/discord.py +++ b/bgstally/discord.py @@ -152,28 +152,17 @@ def _get_embed(self, title:str, description:str, fields:list, update:bool) -> di return embed - def is_webhook_valid(self, channel:DiscordChannel): + def valid_webhook_available(self, channel:DiscordChannel): """ - Check a channel's webhook is valid + Check whether there is a valid webhook available for this channel """ - return self._is_webhook_valid(self._get_webhook(channel)) + webhooks:dict = self.bgstally.webhook_manager.get_webhooks_as_dict(channel) # No need to deepcopy as we're not altering the data + for webhook in webhooks.values(): + webhook_url:str = webhook.get('url') + if self._is_webhook_valid(webhook_url): return True - def _get_webhook(self, channel:DiscordChannel): - """ - Get the webhook url for the given channel - """ - match channel: - case DiscordChannel.BGS: - return self.bgstally.state.DiscordBGSWebhook.get().strip() - case DiscordChannel.CMDR_INFORMATION: - return self.bgstally.state.DiscordCMDRInformationWebhook.get().strip() - case DiscordChannel.FLEETCARRIER_MATERIALS: - return self.bgstally.state.DiscordFCMaterialsWebhook.get().strip() - case DiscordChannel.FLEETCARRIER_OPERATIONS: - return self.bgstally.state.DiscordFCOperationsWebhook.get().strip() - case DiscordChannel.THARGOIDWAR: - return self.bgstally.state.DiscordTWWebhook.get().strip() + return False def _is_webhook_valid(self, webhook:str): diff --git a/bgstally/windows/activity.py b/bgstally/windows/activity.py index d2dee7e..f18f7dd 100644 --- a/bgstally/windows/activity.py +++ b/bgstally/windows/activity.py @@ -263,12 +263,11 @@ def _discord_button_available(self) -> bool: """ match self.bgstally.state.DiscordActivity.get(): case DiscordActivity.BGS: - return self.bgstally.discord.is_webhook_valid(DiscordChannel.BGS) + return self.bgstally.discord.valid_webhook_available(DiscordChannel.BGS) case DiscordActivity.THARGOIDWAR: - return self.bgstally.discord.is_webhook_valid(DiscordChannel.THARGOIDWAR) + return self.bgstally.discord.valid_webhook_available(DiscordChannel.THARGOIDWAR) case DiscordActivity.BOTH: - return self.bgstally.discord.is_webhook_valid(DiscordChannel.BGS) or \ - self.bgstally.discord.is_webhook_valid(DiscordChannel.THARGOIDWAR) + return self.bgstally.discord.valid_webhook_available(DiscordChannel.BGS) case _: return False @@ -297,7 +296,7 @@ def _post_to_discord(self, activity: Activity): discord_text:str = activity.generate_text(DiscordActivity.THARGOIDWAR, True) self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.THARGOIDWAR, self.discord_post_complete) else: - # Both, post to both channels + # Both - post combined report to BGS channels discord_text:str = activity.generate_text(DiscordActivity.BOTH, True) self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) else: @@ -311,7 +310,7 @@ def _post_to_discord(self, activity: Activity): discord_fields:Dict = activity.generate_discord_embed_fields(DiscordActivity.THARGOIDWAR) self.bgstally.discord.post_embed(f"TW Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.THARGOIDWAR, self.discord_post_complete) else: - # Both, post to both channels + # Both - post combined report to BGS channels discord_fields:Dict = activity.generate_discord_embed_fields(DiscordActivity.BOTH) self.bgstally.discord.post_embed(f"Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) diff --git a/bgstally/windows/cmdrs.py b/bgstally/windows/cmdrs.py index 9c33680..ba24b9d 100644 --- a/bgstally/windows/cmdrs.py +++ b/bgstally/windows/cmdrs.py @@ -96,10 +96,9 @@ def show(self): target.get('Notes', "Scanned")] treeview.insert("", 'end', values=target_values, iid=target.get('index')) - if self.bgstally.discord.is_webhook_valid(DiscordChannel.CMDR_INFORMATION) or self.bgstally.discord.is_webhook_valid(DiscordChannel.BGS): - self.post_button = tk.Button(buttons_frame, text="Post to Discord", command=partial(self._post_to_discord)) - self.post_button.pack(side=tk.RIGHT, padx=5, pady=5) - self.post_button['state'] = tk.DISABLED + self.post_button = tk.Button(buttons_frame, text="Post to Discord", command=partial(self._post_to_discord)) + self.post_button.pack(side=tk.RIGHT, padx=5, pady=5) + self.post_button['state'] = tk.DISABLED self.delete_button = tk.Button(buttons_frame, text="Delete", bg="red", fg="white", command=partial(self._delete_selected, treeview)) self.delete_button.pack(side=tk.RIGHT, padx=5, pady=5) @@ -123,7 +122,7 @@ def _cmdr_selected(self, values, column, treeview:TreeviewPlus, iid:str): self.post_button['state'] = tk.DISABLED self.delete_button['state'] = tk.DISABLED return - else: + elif self.bgstally.discord.valid_webhook_available(DiscordChannel.CMDR_INFORMATION): self.post_button['state'] = tk.NORMAL self.delete_button['state'] = tk.NORMAL @@ -206,8 +205,6 @@ def _post_to_discord(self): "inline": True }) - discord_channel:DiscordChannel = DiscordChannel.BGS - description:str = "" match self.selected_cmdr.get('Reason'): @@ -226,5 +223,4 @@ def _post_to_discord(self): description = f"```ansi\n{description}\n```" - if self.bgstally.discord.is_webhook_valid(DiscordChannel.CMDR_INFORMATION): discord_channel = DiscordChannel.CMDR_INFORMATION - self.bgstally.discord.post_embed(f"CMDR {self.selected_cmdr.get('TargetName')}", description, embed_fields, None, discord_channel, None) + self.bgstally.discord.post_embed(f"CMDR {self.selected_cmdr.get('TargetName')}", description, embed_fields, None, DiscordChannel.CMDR_INFORMATION, None) diff --git a/bgstally/windows/fleetcarrier.py b/bgstally/windows/fleetcarrier.py index c2e79c1..16af2b0 100644 --- a/bgstally/windows/fleetcarrier.py +++ b/bgstally/windows/fleetcarrier.py @@ -69,7 +69,9 @@ def show(self): buying_text.insert(tk.INSERT, fc.get_materials_plaintext(MaterialsCategory.BUYING)) buying_text.configure(state='disabled') - if self.bgstally.discord.is_webhook_valid(DiscordChannel.FLEETCARRIER_MATERIALS): ttk.Button(buttons_frame, text="Post to Discord", command=partial(self._post_to_discord)).pack(side=tk.RIGHT, padx=5, pady=5) + post_button:ttk.Button = ttk.Button(buttons_frame, text="Post to Discord", command=partial(self._post_to_discord)) + post_button.pack(side=tk.RIGHT, padx=5, pady=5) + post_button['state'] = tk.NORMAL if self.bgstally.discord.valid_webhook_available(DiscordChannel.FLEETCARRIER_MATERIALS) else tk.DISABLED def _post_to_discord(self): From 9ff3c69e51d66463160b300b0501c8e9b188273f Mon Sep 17 00:00:00 2001 From: aussig Date: Tue, 30 Jan 2024 18:42:42 +0000 Subject: [PATCH 4/5] Remove settings for enabling Discord BGS / TW / Both - now handled by new Discord webhook matrix. Closes #104. --- bgstally/state.py | 7 ++--- bgstally/ui.py | 15 ++++------ bgstally/windows/activity.py | 55 +++++++++--------------------------- 3 files changed, 20 insertions(+), 57 deletions(-) diff --git a/bgstally/state.py b/bgstally/state.py index e95b02a..08c9803 100644 --- a/bgstally/state.py +++ b/bgstally/state.py @@ -1,6 +1,6 @@ import tkinter as tk -from bgstally.constants import CheckStates, DiscordActivity, DiscordPostStyle +from bgstally.constants import CheckStates, DiscordPostStyle from config import config @@ -25,7 +25,6 @@ def load(self): self.IncludeSecondaryInf:tk.StringVar = tk.StringVar(value=config.get_str('XSecondaryInf', default=CheckStates.STATE_ON)) self.DiscordUsername:tk.StringVar = tk.StringVar(value=config.get_str('XDiscordUsername', default="")) self.DiscordPostStyle:tk.StringVar = tk.StringVar(value=config.get_str('XDiscordPostStyle', default=DiscordPostStyle.EMBED)) - self.DiscordActivity:tk.StringVar = tk.StringVar(value=config.get_str('XDiscordActivity', default=DiscordActivity.BOTH)) self.EnableOverlay:tk.StringVar = tk.StringVar(value=config.get_str('XEnableOverlay', default=CheckStates.STATE_ON)) self.EnableOverlayCurrentTick:tk.StringVar = tk.StringVar(value=config.get_str('BGST_EnableOverlayCurrentTick', default=CheckStates.STATE_ON)) self.EnableOverlayActivity:tk.StringVar = tk.StringVar(value=config.get_str('BGST_EnableOverlayActivity', default=CheckStates.STATE_ON)) @@ -33,7 +32,7 @@ def load(self): self.EnableOverlaySystem:tk.StringVar = tk.StringVar(value=config.get_str('BGST_EnableOverlaySystem', default=CheckStates.STATE_ON)) self.EnableSystemActivityByDefault:tk.StringVar = tk.StringVar(value=config.get_str('BGST_EnableSystemActivityByDefault', default=CheckStates.STATE_ON)) - # TODO: Legacy values, remove in future version + # TODO: Legacy values, used to migrate initial state, remove in future version self.DiscordBGSWebhook:tk.StringVar = tk.StringVar(value=config.get_str('XDiscordWebhook', default="")) self.DiscordCMDRInformationWebhook:tk.StringVar = tk.StringVar(value=config.get_str("BGST_DiscordCMDRInformationWebhook", default="")) self.DiscordFCMaterialsWebhook:tk.StringVar = tk.StringVar(value=config.get_str("BGST_DiscordFCMaterialsWebhook", default="")) @@ -78,7 +77,6 @@ def save(self): config.set('XSecondaryInf', self.IncludeSecondaryInf.get()) config.set('XDiscordUsername', self.DiscordUsername.get()) config.set('XDiscordPostStyle', self.DiscordPostStyle.get()) - config.set('XDiscordActivity', self.DiscordActivity.get()) config.set('XEnableOverlay', self.EnableOverlay.get()) config.set('BGST_EnableOverlayCurrentTick', self.EnableOverlayCurrentTick.get()) config.set('BGST_EnableOverlayActivity', self.EnableOverlayActivity.get()) @@ -90,4 +88,3 @@ def save(self): config.set('XCurrentSystemID', self.current_system_id if self.current_system_id != None else "") config.set('XStationFaction', self.station_faction if self.station_faction != None else "") config.set('XStationType', self.station_type if self.station_type != None else "") - config.set('XStationType', self.station_type if self.station_type != None else "") diff --git a/bgstally/ui.py b/bgstally/ui.py index 4840ecb..66c0878 100644 --- a/bgstally/ui.py +++ b/bgstally/ui.py @@ -130,23 +130,18 @@ def get_prefs_frame(self, parent_frame: tk.Frame): HyperlinkLabel(frame, text="Instructions for Use", background=nb.Label().cget('background'), url=URL_WIKI, underline=True).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 ttk.Separator(frame, orient=tk.HORIZONTAL).grid(row=current_row, columnspan=2, padx=10, pady=1, sticky=tk.EW); current_row += 1 - nb.Label(frame, text="General", font=FONT_HEADING_2).grid(row=current_row, column=0, padx=10, sticky=tk.NW) + nb.Label(frame, text="General Options", font=FONT_HEADING_2).grid(row=current_row, column=0, padx=10, sticky=tk.NW) nb.Checkbutton(frame, text="BGS Tally Active", variable=self.bgstally.state.Status, onvalue="Active", offvalue="Paused").grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 nb.Checkbutton(frame, text="Show Systems with Zero Activity", variable=self.bgstally.state.ShowZeroActivitySystems, onvalue=CheckStates.STATE_ON, offvalue=CheckStates.STATE_OFF).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 ttk.Separator(frame, orient=tk.HORIZONTAL).grid(row=current_row, columnspan=2, padx=10, pady=1, sticky=tk.EW); current_row += 1 - nb.Label(frame, text="Discord", font=FONT_HEADING_2).grid(row=current_row, column=0, padx=10, sticky=tk.NW) # Don't increment row because we want the 1st radio option to be opposite title - nb.Label(frame, text="Activity to Include").grid(row=current_row + 1, column=0, padx=10, sticky=tk.W) - nb.Radiobutton(frame, text="BGS", variable=self.bgstally.state.DiscordActivity, value=DiscordActivity.BGS).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - nb.Radiobutton(frame, text="Thargoid War", variable=self.bgstally.state.DiscordActivity, value=DiscordActivity.THARGOIDWAR).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - nb.Radiobutton(frame, text="Both", variable=self.bgstally.state.DiscordActivity, value=DiscordActivity.BOTH).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - nb.Label(frame, text="Post Format").grid(row=current_row, column=0, padx=10, sticky=tk.W) - nb.Radiobutton(frame, text="Modern", variable=self.bgstally.state.DiscordPostStyle, value=DiscordPostStyle.EMBED).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - nb.Radiobutton(frame, text="Legacy", variable=self.bgstally.state.DiscordPostStyle, value=DiscordPostStyle.TEXT).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - nb.Label(frame, text="Other Options").grid(row=current_row, column=0, padx=10, sticky=tk.W) + nb.Label(frame, text="Discord Options", font=FONT_HEADING_2).grid(row=current_row, column=0, padx=10, sticky=tk.NW) # Don't increment row because we want the 1st radio option to be opposite title nb.Checkbutton(frame, text="Abbreviate Faction Names", variable=self.bgstally.state.AbbreviateFactionNames, onvalue=CheckStates.STATE_ON, offvalue=CheckStates.STATE_OFF).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 nb.Checkbutton(frame, text="Include Secondary INF", variable=self.bgstally.state.IncludeSecondaryInf, onvalue=CheckStates.STATE_ON, offvalue=CheckStates.STATE_OFF).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 nb.Checkbutton(frame, text="Report Newly Visited System Activity By Default", variable=self.bgstally.state.EnableSystemActivityByDefault, onvalue=CheckStates.STATE_ON, offvalue=CheckStates.STATE_OFF).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 + nb.Label(frame, text="Post Format").grid(row=current_row, column=0, padx=10, sticky=tk.W) + nb.Radiobutton(frame, text="Modern", variable=self.bgstally.state.DiscordPostStyle, value=DiscordPostStyle.EMBED).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 + nb.Radiobutton(frame, text="Legacy", variable=self.bgstally.state.DiscordPostStyle, value=DiscordPostStyle.TEXT).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 ttk.Separator(frame, orient=tk.HORIZONTAL).grid(row=current_row, columnspan=2, padx=10, pady=1, sticky=tk.EW); current_row += 1 nb.Label(frame, text="Discord Webhooks", font=FONT_HEADING_2).grid(row=current_row, column=0, padx=10, sticky=tk.NW); current_row += 1 diff --git a/bgstally/windows/activity.py b/bgstally/windows/activity.py index f18f7dd..53c1ded 100644 --- a/bgstally/windows/activity.py +++ b/bgstally/windows/activity.py @@ -2,7 +2,6 @@ from functools import partial from os import path from tkinter import PhotoImage, ttk -from typing import Dict from ttkHyperlinkLabel import HyperlinkLabel @@ -69,7 +68,7 @@ def _show(self, activity: Activity): DiscordTextFrame = ttk.Frame(DiscordFrame) DiscordTextFrame.grid(row=2, column=0, pady=5, sticky=tk.NSEW) - DiscordText = DiscordAnsiColorText(DiscordTextFrame, state='disabled', wrap=tk.WORD, bg="Gray13", height=1, font=FONT_TEXT) + DiscordText = DiscordAnsiColorText(DiscordTextFrame, state='disabled', wrap=tk.WORD, bg="Gray13", height=15, font=FONT_TEXT) DiscordScroll = tk.Scrollbar(DiscordTextFrame, orient=tk.VERTICAL, command=DiscordText.yview) DiscordText['yscrollcommand'] = DiscordScroll.set DiscordScroll.pack(fill=tk.Y, side=tk.RIGHT) @@ -91,10 +90,6 @@ def _show(self, activity: Activity): ttk.Label(DiscordOptionsFrame, text="Post Format").grid(row=current_row, column=0, padx=10, sticky=tk.W) ttk.Radiobutton(DiscordOptionsFrame, text="Modern", variable=self.bgstally.state.DiscordPostStyle, value=DiscordPostStyle.EMBED).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 ttk.Radiobutton(DiscordOptionsFrame, text="Legacy", variable=self.bgstally.state.DiscordPostStyle, value=DiscordPostStyle.TEXT).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - ttk.Label(DiscordOptionsFrame, text="Activity to Include").grid(row=current_row, column=0, padx=10, sticky=tk.W) - ttk.Radiobutton(DiscordOptionsFrame, text="BGS", variable=self.bgstally.state.DiscordActivity, value=DiscordActivity.BGS, command=partial(self._option_change, DiscordText, activity)).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - ttk.Radiobutton(DiscordOptionsFrame, text="Thargoid War", variable=self.bgstally.state.DiscordActivity, value=DiscordActivity.THARGOIDWAR, command=partial(self._option_change, DiscordText, activity)).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 - ttk.Radiobutton(DiscordOptionsFrame, text="Both", variable=self.bgstally.state.DiscordActivity, value=DiscordActivity.BOTH, command=partial(self._option_change, DiscordText, activity)).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 ttk.Label(DiscordOptionsFrame, text="Other Options").grid(row=current_row, column=0, padx=10, sticky=tk.W) ttk.Checkbutton(DiscordOptionsFrame, text="Abbreviate Faction Names", variable=self.bgstally.state.AbbreviateFactionNames, onvalue=CheckStates.STATE_ON, offvalue=CheckStates.STATE_OFF, command=partial(self._option_change, DiscordText, activity)).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 ttk.Checkbutton(DiscordOptionsFrame, text="Include Secondary INF", variable=self.bgstally.state.IncludeSecondaryInf, onvalue=CheckStates.STATE_ON, offvalue=CheckStates.STATE_OFF, command=partial(self._option_change, DiscordText, activity)).grid(row=current_row, column=1, padx=10, sticky=tk.W); current_row += 1 @@ -261,15 +256,7 @@ def _discord_button_available(self) -> bool: """ Return true if the 'Post to Discord' button should be available """ - match self.bgstally.state.DiscordActivity.get(): - case DiscordActivity.BGS: - return self.bgstally.discord.valid_webhook_available(DiscordChannel.BGS) - case DiscordActivity.THARGOIDWAR: - return self.bgstally.discord.valid_webhook_available(DiscordChannel.THARGOIDWAR) - case DiscordActivity.BOTH: - return self.bgstally.discord.valid_webhook_available(DiscordChannel.BGS) - case _: - return False + return self.bgstally.discord.valid_webhook_available(DiscordChannel.BGS) or self.bgstally.discord.valid_webhook_available(DiscordChannel.THARGOIDWAR) def _update_discord_field(self, DiscordText, activity: Activity): @@ -278,7 +265,7 @@ def _update_discord_field(self, DiscordText, activity: Activity): """ DiscordText.configure(state='normal') DiscordText.delete('1.0', 'end-1c') - DiscordText.write(activity.generate_text(self.bgstally.state.DiscordActivity.get(), True)) + DiscordText.write(activity.generate_text(DiscordActivity.BOTH, True)) DiscordText.configure(state='disabled') @@ -287,32 +274,16 @@ def _post_to_discord(self, activity: Activity): Callback to post to discord in the appropriate channel(s) """ if self.bgstally.state.DiscordPostStyle.get() == DiscordPostStyle.TEXT: - if self.bgstally.state.DiscordActivity.get() == DiscordActivity.BGS: - # BGS Only - post to BGS channels - discord_text:str = activity.generate_text(DiscordActivity.BGS, True) - self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) - elif self.bgstally.state.DiscordActivity.get() == DiscordActivity.THARGOIDWAR: - # TW Only - post to TW channels - discord_text:str = activity.generate_text(DiscordActivity.THARGOIDWAR, True) - self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.THARGOIDWAR, self.discord_post_complete) - else: - # Both - post combined report to BGS channels - discord_text:str = activity.generate_text(DiscordActivity.BOTH, True) - self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) + discord_text:str = activity.generate_text(DiscordActivity.BGS, True) + self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) + discord_text = activity.generate_text(DiscordActivity.THARGOIDWAR, True) + self.bgstally.discord.post_plaintext(discord_text, activity.discord_webhook_data, DiscordChannel.THARGOIDWAR, self.discord_post_complete) else: description = "" if activity.discord_notes is None else activity.discord_notes - if self.bgstally.state.DiscordActivity.get() == DiscordActivity.BGS: - # BGS Only - post to BGS channels - discord_fields:Dict = activity.generate_discord_embed_fields(DiscordActivity.BGS) - self.bgstally.discord.post_embed(f"BGS Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) - elif self.bgstally.state.DiscordActivity.get() == DiscordActivity.THARGOIDWAR: - # TW Only - post to TW channels - discord_fields:Dict = activity.generate_discord_embed_fields(DiscordActivity.THARGOIDWAR) - self.bgstally.discord.post_embed(f"TW Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.THARGOIDWAR, self.discord_post_complete) - else: - # Both - post combined report to BGS channels - discord_fields:Dict = activity.generate_discord_embed_fields(DiscordActivity.BOTH) - self.bgstally.discord.post_embed(f"Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) + discord_fields:dict = activity.generate_discord_embed_fields(DiscordActivity.BGS) + self.bgstally.discord.post_embed(f"BGS Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.BGS, self.discord_post_complete) + discord_fields = activity.generate_discord_embed_fields(DiscordActivity.THARGOIDWAR) + self.bgstally.discord.post_embed(f"TW Activity after tick: {activity.get_title()}", description, discord_fields, activity.discord_webhook_data, DiscordChannel.THARGOIDWAR, self.discord_post_complete) activity.dirty = True # Because discord post ID has been changed @@ -475,7 +446,7 @@ def _scenarios_change(self, notebook: ScrollableNotebook, tab_index: int, Scenar activity.dirty = True - def _update_tab_image(self, notebook: ScrollableNotebook, tab_index: int, EnableAllCheckbutton, system: Dict): + def _update_tab_image(self, notebook: ScrollableNotebook, tab_index: int, EnableAllCheckbutton, system: dict): """ Update the image alongside the tab title """ @@ -496,6 +467,6 @@ def _copy_to_clipboard(self, Form:tk.Frame, activity:Activity): Get all text from the Discord field and put it in the Copy buffer """ Form.clipboard_clear() - Form.clipboard_append(activity.generate_text(self.bgstally.state.DiscordActivity.get(), True)) + Form.clipboard_append(activity.generate_text(DiscordActivity.BOTH, True)) Form.update() From 142b8582c1e04d8c8dc4d469a41e18782a32c6ee Mon Sep 17 00:00:00 2001 From: aussig Date: Fri, 2 Feb 2024 20:39:04 +0000 Subject: [PATCH 5/5] Update CHANGELOG and version for release --- CHANGELOG.md | 2 +- load.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4660cda..3eb5042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## v3.4.0-xx - xxxx-xx-xx +## v3.4.0-a2 - 2024-02-02 ### Changes: diff --git a/load.py b/load.py index e490276..906d1fc 100644 --- a/load.py +++ b/load.py @@ -8,7 +8,7 @@ from bgstally.debug import Debug PLUGIN_NAME = "BGS-Tally" -PLUGIN_VERSION = semantic_version.Version.coerce("3.4.0-a1") +PLUGIN_VERSION = semantic_version.Version.coerce("3.4.0-a2") # Initialise the main plugin class this:BGSTally = BGSTally(PLUGIN_NAME, PLUGIN_VERSION)