Skip to content

Commit

Permalink
Remove settings for enabling Discord BGS / TW / Both - now handled by…
Browse files Browse the repository at this point in the history
… new Discord webhook matrix. Closes #104.
  • Loading branch information
aussig committed Jan 30, 2024
1 parent 1933d28 commit 9ff3c69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 57 deletions.
7 changes: 2 additions & 5 deletions bgstally/state.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -25,15 +25,14 @@ 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))
self.EnableOverlayTWProgress:tk.StringVar = tk.StringVar(value=config.get_str('BGST_EnableOverlayTWProgress', default=CheckStates.STATE_ON))
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=""))
Expand Down Expand Up @@ -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())
Expand All @@ -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 "")
15 changes: 5 additions & 10 deletions bgstally/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 13 additions & 42 deletions bgstally/windows/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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')


Expand All @@ -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

Expand Down Expand Up @@ -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
"""
Expand All @@ -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()

0 comments on commit 9ff3c69

Please sign in to comment.