Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

add Twitch OAuth-Token-Authentication #7

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# VS Code Stuff
.vscode/

# User-specific files
*.rsuser
*.suo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29025.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLiveChecker", "TwitchLiveChecker.csproj", "{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLiveChecker", "TwitchLiveChecker\TwitchLiveChecker.csproj", "{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Debug|x64.ActiveCfg = Debug|x64
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Debug|x64.Build.0 = Debug|x64
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Release|Any CPU.Build.0 = Release|Any CPU
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Release|x64.ActiveCfg = Release|x64
{75F3E380-DA4B-4C6D-AB1A-6B125E17AA20}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion TwitchLiveChecker/App.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Application x:Class="TwitchLiveChecker.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TwitchLiveChecker" StartupUri="MainWindow.xaml">
<Application x:Class="TwitchLiveChecker.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TwitchLiveChecker" StartupUri="View/MainWindow.xaml">
<Application.Resources>

<ResourceDictionary>
Expand Down
104 changes: 104 additions & 0 deletions TwitchLiveChecker/Classes/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;

namespace TwitchConfig
{
class Config
{
public List<string> Channels { get; set; }
public Dictionary<string, string> oauth = new Dictionary<string, string>
{
{ "authtoken", "" },
{ "refreshtoken", "" }
};

public static Config GetConfig()
{
if (File.Exists(SystemConfig.Environment["configfile"]))
{
string filecontents = File.ReadAllText(SystemConfig.Environment["configfile"]);
Config config = JsonConvert.DeserializeObject<Config>(filecontents);

return config;
}
else
{
Config config = new Config();
config.Channels = new List<string> { "miekii", "darkviperau", "wardiii" };

File.WriteAllText(SystemConfig.Environment["configfile"], JsonConvert.SerializeObject(config));
return config;
}
}

public bool Reload()
{
Config config;
if (File.Exists(SystemConfig.Environment["configfile"]))
{
string filecontents = File.ReadAllText(SystemConfig.Environment["configfile"]);
config = JsonConvert.DeserializeObject<Config>(filecontents);
}
else
{
config = new Config();
config.Channels = new List<string> { "darkviperau", "miekii", "wardiii" };

File.WriteAllText(SystemConfig.Environment["configfile"], JsonConvert.SerializeObject(config));
}

config.Channels.Sort();
this.Channels = config.Channels;
this.oauth = config.oauth;

return true;
}

public bool Save()
{
this.Channels.Sort();
File.WriteAllText(SystemConfig.Environment["configfile"], JsonConvert.SerializeObject(this));
return true;
}

public static bool WriteConfig( Config config )
{
File.WriteAllText(SystemConfig.Environment["configfile"], JsonConvert.SerializeObject(config));
return true;
}

public bool ChannelExists( string channel )
{
return this.Channels.Contains(channel.ToLower()) ? true : false;
}

public bool AddChannel( string channel )
{
if (ChannelExists(channel))
{
return false;
}
else
{
Channels.Add(channel.ToLower());
Save();
return true;
}
}

public bool RemoveChannel( string channel )
{
if (ChannelExists(channel))
{
Channels.Remove(channel.ToLower());
Save();
return true;
}
else
{
return false;
}
}
}
}
33 changes: 33 additions & 0 deletions TwitchLiveChecker/Classes/SystemConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TwitchConfig
{
class SystemConfig
{
public static Dictionary<string, string> Application = new Dictionary<string, string>
{
{ "clientid", "drx70rx00ev71cq1jax7i4ji3ywib0" },
{ "clientsecret", "enrlbcqa312829q3e39q0z67kqgz9x" }
};

public static Dictionary<string, string> Environment = new Dictionary<string, string>
{
{ "configfile", $"{Directory.GetCurrentDirectory()}/config.json" },
{ "redirect_uri", "http://localhost:58214" }
};

public static Dictionary<string, string> Twitch = new Dictionary<string, string>
{
{ "oauth_loginurl", "https://id.twitch.tv/oauth2/authorize" },
{ "oauth_tokenurl", "https://id.twitch.tv/oauth2/token" },
{ "oauth_revocationurl", "https://id.twitch.tv/oauth2/revoke" },
{ "api_channelurl", "https://api.twitch.tv/helix/streams" },
{ "api_usersurl", "https://api.twitch.tv/helix/users" }
};
}
}
10 changes: 10 additions & 0 deletions TwitchLiveChecker/Classes/TwitchAPIChannelResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json.Linq;

namespace TwitchLiveChecker
{
class TwitchAPIChannelResponse
{
public TwitchChannel[] data { get ; set; }
public JObject pagination { get; set; }
}
}
66 changes: 66 additions & 0 deletions TwitchLiveChecker/Classes/TwitchChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TwitchLiveChecker
{
class TwitchChannel
{
public string id { get; set; }
public string user_id { get; set; }
public string user_name { get; set; }
public string game_id { get; set; }
public string type { get; set; }
public string title { get; set; }
public int viewer_count { get; set; }
public string started_at { get; set; }
public string language { get; set; }
public string thumbnail_url { get; set; }
public string[] tag_ids { get; set; }

public DateTime StartTime
{
get
{
return DateTime.Parse(started_at);
}
}

public string LiveString
{
get
{
if (type == "live")
{
TimeSpan ts = DateTime.Now.Subtract(StartTime);
return $"live for {ts.Hours}h {ts.Minutes}m";
}
else
{
return "offline";
}
}
}

public TwitchChannel(string username)
{
user_name = username;
type = "unknown";
title = "";
}

public TwitchChannel(string username, string status)
{
user_name = username;
type = status;
type = "";
}

public TwitchChannel()
{

}
}
}
15 changes: 15 additions & 0 deletions TwitchLiveChecker/Classes/TwitchOAuthToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TwitchLiveChecker
{
class TwitchOAuthToken
{
public string access_token { get; set; }
public int expires_in { get; set; }
public string refresh_token { get; set; }
public List<string> scope { get; set; }
public string token_type { get; set; }
}
}
29 changes: 29 additions & 0 deletions TwitchLiveChecker/Classes/TwitchUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TwitchLiveChecker
{
public class TwitchUser
{
public string id { get; set; }
public string login { get; set; }
public string display_name { get; set; }
public string type { get; set; }
public string broadcaster_type { get; set; }
public string description { get; set; }
public string profile_image_url { get; set; }
public string offline_image_url { get; set; }
public int view_count { get; set; }
public string email { get; set; }
}

public class TwitchUserResponse
{
public List<TwitchUser> data { get; set; }
}


}
73 changes: 0 additions & 73 deletions TwitchLiveChecker/ConfigManager.cs

This file was deleted.

Loading