Skip to content

Commit

Permalink
C# Rewrite, simple functions only so far but more will be added.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1d3v committed May 14, 2024
1 parent 5326a0f commit d90ed72
Show file tree
Hide file tree
Showing 84 changed files with 141,910 additions and 560 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/python-package.yml

This file was deleted.

25 changes: 25 additions & 0 deletions Naticord.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.34729.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Naticord", "Naticord\Naticord.csproj", "{1383FE7A-AB28-48C3-A477-E35655E31D5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1383FE7A-AB28-48C3-A477-E35655E31D5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1383FE7A-AB28-48C3-A477-E35655E31D5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1383FE7A-AB28-48C3-A477-E35655E31D5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1383FE7A-AB28-48C3-A477-E35655E31D5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CE8FF17F-663A-4879-ABE4-846C1DEA6955}
EndGlobalSection
EndGlobal
141 changes: 141 additions & 0 deletions Naticord/Login.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Naticord/Login.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.IO;
using System.Net;
using System.Windows.Forms;

namespace Naticord
{
public partial class Login : Form
{
private const string TokenFileName = "token.txt";

public Login()
{
InitializeComponent();
}

private void loginButton_Click(object sender, EventArgs e)
{
string accessToken = accessTokenTextBox.Text.Trim();

if (string.IsNullOrEmpty(accessToken))
{
MessageBox.Show("Please enter your Discord access token.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

PerformLogin(accessToken);
}

private void PerformLogin(string accessToken)
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // TLS 1.2

using (var webClient = new WebClient())
{
webClient.Headers[HttpRequestHeader.Authorization] = accessToken;

try
{
string userProfileJson = webClient.DownloadString("https://discord.com/api/v9/users/@me");

SaveToken(accessToken);

Naticord naticordForm = new Naticord(accessToken);
naticordForm.Show();

this.Hide();
}
catch (WebException ex)
{
MessageBox.Show("Failed to login. Please enter a valid token! Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

private void SaveToken(string accessToken)
{
try
{
string homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

string filePath = Path.Combine(homeDirectory, TokenFileName);

File.WriteAllText(filePath, "token=" + accessToken);
}
catch (Exception ex)
{
MessageBox.Show("Failed to save token: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void Login_Load(object sender, EventArgs e)
{

}
}
}
Loading

0 comments on commit d90ed72

Please sign in to comment.