Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some things in the discord profile #1939

Merged
merged 4 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<TextBlock HorizontalAlignment="Left" Margin="0,10" TextWrapping="Wrap" MaxWidth="824">
<Run Text="Support for BetterDiscord requires a plugin so that Aurora is able to fetch the variables from the client." />
</TextBlock>
<Button x:Name="patchButton" Content="Install BD Plugin" HorizontalAlignment="Left" Width="132" Margin="0,0,0,0" Click="PatchButton_Click"/>
<Button x:Name="unpatchButton" Content="Uninstall BD Plugin" HorizontalAlignment="Left" VerticalAlignment="Top" Width="132" Margin="0,10,0,0" Click="UnpatchButton_Click"/>
<Button x:Name="patchButton" Content="Install BD Plugin" HorizontalAlignment="Left" Width="150" Margin="0,0,0,0" Click="PatchButton_Click"/>
<Button x:Name="unpatchButton" Content="Uninstall BD Plugin" HorizontalAlignment="Left" VerticalAlignment="Top" Width="150" Margin="0,10,0,0" Click="UnpatchButton_Click"/>
<Button x:Name="manualPatchButton" Content="Install BD Plugin Manually" HorizontalAlignment="Left" Width="150" Margin="0,10,0,0" Click="ManualPatchButton_Click"/>
</StackPanel>
</TabItem>
</TabControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ namespace Aurora.Profiles.Discord
/// Interaction logic for Control_Minecraft.xaml
/// </summary>
public partial class Control_Discord : UserControl {

private Application profile;

public Control_Discord(Application profile) {
this.profile = profile;

InitializeComponent();
SetSettings();

SetSettings();

profile.ProfileChanged += (sender, e) => SetSettings();
}
Expand All @@ -47,23 +45,48 @@ private void GameEnabled_Checked(object sender, RoutedEventArgs e) {

private void PatchButton_Click(object sender, RoutedEventArgs e)
{
InstallPlugin();
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string pluginDirectory = Path.Combine(appdata, "BetterDiscord", "plugins");

if (!Directory.Exists(pluginDirectory))
Directory.CreateDirectory(pluginDirectory);

string pluginFile = Path.Combine(pluginDirectory, "AuroraGSI.plugin.js");
WriteFile(pluginFile);
}

private void UnpatchButton_Click(object sender, RoutedEventArgs e)
{
UninstallPlugin();
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string path = Path.Combine(appdata, "BetterDiscord", "plugins", "AuroraGSI.plugin.js");

if (File.Exists(path))
{
File.Delete(path);
MessageBox.Show("Plugin uninstalled successfully");
return;
}
else
{
MessageBox.Show("Plugin not found.");
return;
}
}

private void InstallPlugin()
private void ManualPatchButton_Click(object sender, RoutedEventArgs e)
{
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string pluginDirectory = Path.Combine(appdata, "BetterDiscord", "plugins");
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;

if (!Directory.Exists(pluginDirectory))
Directory.CreateDirectory(pluginDirectory);
string pluginFile = Path.Combine(dialog.SelectedPath, "AuroraGSI.plugin.js");
WriteFile(pluginFile);
}
}

string pluginFile = Path.Combine(pluginDirectory, "AuroraGSI.plugin.js");
private void WriteFile(string pluginFile)
{
if (File.Exists(pluginFile))
{
MessageBox.Show("Plugin already installed");
Expand All @@ -83,23 +106,5 @@ private void InstallPlugin()
MessageBox.Show("Error installng plugin: " + e.Message);
}
}

private void UninstallPlugin()
{
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string path = Path.Combine(appdata, "BetterDiscord", "plugins", "AuroraGSI.plugin.js");

if (File.Exists(path))
{
File.Delete(path);
MessageBox.Show("Plugin uninstalled successfully");
return;
}
else
{
MessageBox.Show("Plugin not found.");
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord {

public class DiscordProfile : ApplicationProfile {

public DiscordProfile() : base() { }

public override void Reset() {
base.Reset();

Expand Down Expand Up @@ -59,8 +55,6 @@ public override void Reset() {
_Sequence = new KeySequence(new DeviceKeys[] { DeviceKeys.PRINT_SCREEN, DeviceKeys.SCROLL_LOCK, DeviceKeys.PAUSE_BREAK })
}
}, new OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanGSIBoolean("User/UnreadMessages"))),


};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,19 @@
using System.Text;
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord.GSI {
namespace Aurora.Profiles.Discord.GSI
{
public class GameState_Discord : GameState<GameState_Discord>
{
public ProviderNode Provider => NodeFor<ProviderNode>("provider");

public class GameState_Discord : GameState<GameState_Discord> {
public UserNode User => NodeFor<UserNode>("user");

private ProviderNode _Provider;
private UserNode _User;
private GuildNode _Guild;
private TextNode _Text;
private VoiceNode _Voice;
public GuildNode Guild => NodeFor<GuildNode>("guild");

/// <summary>
/// Provider node provides information about the data source so that Aurora can update the correct gamestate.
/// </summary>
public ProviderNode Provider {
get {
if (_Provider == null)
_Provider = new ProviderNode(_ParsedData["provider"]?.ToString() ?? "");
return _Provider;
}
}

public UserNode User
{
get
{
if (_User == null)
_User = new UserNode(_ParsedData["user"]?.ToString() ?? "");
return _User;
}
}
public TextNode Text => NodeFor<TextNode>("text");

public GuildNode Guild
{
get
{
if (_Guild == null)
_Guild = new GuildNode(_ParsedData["guild"]?.ToString() ?? "");
return _Guild;
}
}
public TextNode Text {
get {
if (_Text == null)
_Text = new TextNode(_ParsedData["text"]?.ToString() ?? "");
return _Text;
}
}

public VoiceNode Voice {
get {
if (_Voice == null)
_Voice = new VoiceNode(_ParsedData["voice"]?.ToString() ?? "");
return _Voice;
}
}
public VoiceNode Voice => NodeFor<VoiceNode>("voice");

/// <summary>
/// Creates a default GameState_Discord instance.
Expand All @@ -78,6 +36,6 @@ public GameState_Discord(string JSONstring) : base(JSONstring) { }
/// Creates a GameState_Discord instance based on the data from the passed GameState instance.
/// </summary>
public GameState_Discord(IGameState other) : base(other) { }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord.GSI.Nodes {
public class GuildNode : Node<GuildNode> {
public class GuildNode : AutoJsonNode<GuildNode> {
public long Id;
public string Name;

public long Id = 0;
public string Name = String.Empty;

internal GuildNode() : base() { }
internal GuildNode(string json) : base(json) {
Id = GetLong("id");
Name = GetString("name");
}
internal GuildNode(string json) : base(json) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord.GSI.Nodes {

public enum DiscordTextType
{
Undefined = -1,
Expand All @@ -14,18 +13,11 @@ public enum DiscordTextType
GroupChat = 3
}


public class TextNode : Node<TextNode> {

public class TextNode : AutoJsonNode<TextNode> {
public long Id = 0;
public string Name;
public int Type;
public DiscordTextType Type;

internal TextNode() : base() { }
internal TextNode(string json) : base(json) {
Id = GetLong("id");
Name = GetString("name");
Type = GetInt("type");
}
internal TextNode(string json) : base(json) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord.GSI.Nodes {

public enum DiscordStatus
{
Undefined,
Expand All @@ -15,24 +14,33 @@ public enum DiscordStatus
Invisible
}


public class UserNode : Node<UserNode> {

public class UserNode : AutoJsonNode<UserNode> {
public long Id = 0;
public string Status = "";
public bool SelfMute = false;
public bool SelfDeafen = false;
public bool Mentions = false;
public bool UnreadMessages = false;

internal UserNode() : base() { }
[AutoJsonIgnore] public DiscordStatus Status;
[AutoJsonPropertyName("self_mute")] public bool SelfMute;
[AutoJsonPropertyName("self_deafen")] public bool SelfDeafen;
public bool Mentions;
[AutoJsonPropertyName("unread_messages")] public bool UnreadMessages;

internal UserNode(string json) : base(json) {
Id = GetLong("id");
Status = GetString("status");
SelfMute = GetBool("self_mute");
SelfDeafen = GetBool("self_deafen");
Mentions = GetBool("mentions");
UnreadMessages = GetBool("unread_messages");
Status = GetStatus(GetString("status"));
}

private static DiscordStatus GetStatus(string status)
{
switch (status)
{
case "online":
return DiscordStatus.Online;
case "dnd":
return DiscordStatus.DoNotDisturb;
case "invisible":
return DiscordStatus.Invisible;
case "idle":
return DiscordStatus.Idle;
default:
return DiscordStatus.Undefined;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord.GSI.Nodes {

public enum DiscordVoiceType
{
Undefined = -1,
Call = 1,
VoiceChannel = 2,
}

public class VoiceNode : Node<VoiceNode> {

public class VoiceNode : AutoJsonNode<VoiceNode> {
public long Id = 0;
public string Name;
public int Type;

public DiscordVoiceType Type;

internal VoiceNode() : base() { }
internal VoiceNode(string json) : base(json) {
Id = GetLong("id");
Name = GetString("name");
Type = GetInt("type");
}
internal VoiceNode(string json) : base(json) { }
}
}