Skip to content

Commit

Permalink
Merge pull request #31 from tumugin/develop
Browse files Browse the repository at this point in the history
ver 1.5リリース
  • Loading branch information
tumugin authored Nov 12, 2019
2 parents 3637603 + 73fb183 commit fd36c71
Show file tree
Hide file tree
Showing 82 changed files with 1,378 additions and 1,391 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_PATH: "vendor/bundler"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,7 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc

# Ruby
vendor/bundler/
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "FluentWPF"]
path = FluentWPF
url = https://github.com/tumugin/FluentWPF.git
[submodule "foo_nowplayingv2/SDK"]
path = foo_nowplayingv2/SDK
url = https://github.com/tumugin/foobar2000_sdk.git
16 changes: 16 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Ignore inline messages which lay outside a diff's range of PR
github.dismiss_out_of_range_messages

# PR
if github.pr_title.include? "[WIP]" || github.pr_labels.include?("WIP")
warn("PR is classed as Work in Progress")
end

# Warn when there is a big PR
warn("a large PR") if git.lines_of_code > 500

# Warn when PR has no assignees
warn("A pull request must have some assignees") if github.pr_json["assignee"].nil?

resharper_inspectcode.base_path = Dir.pwd
resharper_inspectcode.report "report.xml"
1 change: 0 additions & 1 deletion FluentWPF
Submodule FluentWPF deleted from e38f83
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem 'danger'
gem 'danger-resharper_inspectcode'
70 changes: 70 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ansi (1.5.0)
ast (2.4.0)
claide (1.0.3)
claide-plugins (0.9.2)
cork
nap
open4 (~> 1.3)
colored2 (3.1.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (6.1.0)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
cork (~> 0.1)
faraday (~> 0.9)
faraday-http-cache (~> 2.0)
git (~> 1.5)
kramdown (~> 2.0)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (~> 4.7)
terminal-table (~> 1)
danger-plugin-api (1.0.0)
danger (> 2.0)
danger-resharper_inspectcode (1.0.2)
danger-plugin-api (~> 1.0)
oga (~> 2.15)
faraday (0.17.0)
multipart-post (>= 1.2, < 3)
faraday-http-cache (2.0.0)
faraday (~> 0.8)
git (1.5.0)
kramdown (2.1.0)
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
multipart-post (2.1.1)
nap (1.1.0)
no_proxy_fix (0.1.2)
octokit (4.14.0)
sawyer (~> 0.8.0, >= 0.5.3)
oga (2.15)
ast
ruby-ll (~> 2.1)
open4 (1.3.4)
public_suffix (4.0.1)
ruby-ll (2.1.2)
ansi
ast
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
unicode-display_width (1.6.0)

PLATFORMS
ruby

DEPENDENCIES
danger
danger-resharper_inspectcode

BUNDLED WITH
1.17.2
2 changes: 1 addition & 1 deletion MusicBeeNPPlugin/MusicBeeNPPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\NowPlayingV2\bin\Release\</OutputPath>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
98 changes: 98 additions & 0 deletions NowPlayingCore/ConfigConverter/MastodonClientConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Text;
using Mastonet;
using Mastonet.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace NowPlayingCore.ConfigConverter
{
class MastodonClientConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var mastodonClient = value as MastodonClient;
if (mastodonClient == null)
{
writer.WriteNull();
return;
}

writer.WriteStartObject();

writer.WritePropertyName("AppRegistration");
writer.WriteStartObject();
if (mastodonClient.AppRegistration != null)
{
writer.WritePropertyName("ClientId");
writer.WriteValue(mastodonClient.AppRegistration.ClientId);
writer.WritePropertyName("ClientSecret");
writer.WriteValue(mastodonClient.AppRegistration.ClientSecret);
writer.WritePropertyName("Id");
writer.WriteValue(mastodonClient.AppRegistration.Id);
writer.WritePropertyName("Instance");
writer.WriteValue(mastodonClient.AppRegistration.Instance);
writer.WritePropertyName("RedirectUri");
writer.WriteValue(mastodonClient.AppRegistration.RedirectUri);
writer.WritePropertyName("Scope");
writer.WriteValue(mastodonClient.AppRegistration.Scope);
}
else
{
writer.WriteNull();
}

writer.WriteEndObject();

writer.WritePropertyName("AuthToken");
writer.WriteStartObject();
if (mastodonClient.AuthToken != null)
{
writer.WritePropertyName("AccessToken");
writer.WriteValue(mastodonClient.AuthToken.AccessToken);
writer.WritePropertyName("TokenType");
writer.WriteValue(mastodonClient.AuthToken.TokenType);
writer.WritePropertyName("Scope");
writer.WriteValue(mastodonClient.AuthToken.Scope);
writer.WritePropertyName("CreatedAt");
writer.WriteValue(mastodonClient.AuthToken.CreatedAt);
}
else
{
writer.WriteNull();
}

writer.WriteEndObject();

writer.WriteEndObject();
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
var appRegistration = new AppRegistration();
var authToken = new Auth();
var jsonObject = JObject.Load(reader);
appRegistration.ClientId = jsonObject["AppRegistration"]["ClientId"].Value<string>();
appRegistration.ClientSecret = jsonObject["AppRegistration"]["ClientSecret"].Value<string>();
appRegistration.Id = jsonObject["AppRegistration"]["Id"].Value<long>();
appRegistration.Instance = jsonObject["AppRegistration"]["Instance"].Value<string>();
appRegistration.RedirectUri = jsonObject["AppRegistration"]["RedirectUri"].Value<string>();
var scope = jsonObject["AppRegistration"]["Scope"].Value<long>();
appRegistration.Scope = (Scope) Enum.ToObject(typeof(Scope), scope);

authToken.AccessToken = jsonObject["AuthToken"]["AccessToken"].Value<string>();
authToken.TokenType = jsonObject["AuthToken"]["TokenType"].Value<string>();
authToken.Scope = jsonObject["AuthToken"]["Scope"].Value<string>();
authToken.CreatedAt = jsonObject["AuthToken"]["CreatedAt"].Value<string>();

return new MastodonClient(appRegistration, authToken);
}

public override bool CanConvert(Type objectType)
{
return objectType == typeof(MastodonClient);
}
}
}
48 changes: 48 additions & 0 deletions NowPlayingCore/ConfigConverter/TwitterAuthTokenConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
using CoreTweet;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NowPlayingCore.Tsumugi;

namespace NowPlayingCore.ConfigConverter
{
class TwitterAuthTokenConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var authToken = value as Tokens;
if (authToken == null)
{
writer.WriteNull();
return;
}

writer.WriteStartObject();
writer.WritePropertyName("AccessToken");
writer.WriteValue(authToken.AccessToken);
writer.WritePropertyName("AccessTokenSecret");
writer.WriteValue(authToken.AccessTokenSecret);
writer.WritePropertyName("UserId");
writer.WriteValue(authToken.UserId);
writer.WritePropertyName("ScreenName");
writer.WriteValue(authToken.ScreenName);
writer.WriteEndObject();
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
var jsonObject = JObject.Load(reader);
return Tokens.Create(APIKey.CONSUMER_KEY, APIKey.CONSUMER_SECRET,
jsonObject["AccessToken"].Value<string>(), jsonObject["AccessTokenSecret"].Value<string>(),
jsonObject["UserId"].Value<long>(), jsonObject["ScreenName"].Value<string>());
}

public override bool CanConvert(Type objectType)
{
return objectType == typeof(Tokens);
}
}
}
12 changes: 6 additions & 6 deletions NowPlayingCore/Core/AccountContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ public abstract class AccountContainer : INotifyPropertyChanged

[JsonIgnore] public abstract string ID { get; }

public string Name { get; set; }
public string Name { get; set; } = default!;

[JsonIgnore] public abstract int MaxTweetLength { get; }

public abstract void UpdateCache();
public abstract Task UpdateCache();

public abstract void UpdateStatus(string UpdateText);
public abstract Task UpdateStatus(string UpdateText);

public abstract void UpdateStatus(string UpdateText, string base64image);
public abstract Task UpdateStatus(string UpdateText, string base64image);

public abstract int CountText(string text);

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler PropertyChanged = default!;

protected virtual void OnPropertyChanged(string propertyName = null)
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Expand Down
38 changes: 21 additions & 17 deletions NowPlayingCore/Core/MastodonAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,65 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Mastonet;
using Mastonet.Entities;
using Newtonsoft.Json;
using NowPlayingCore.ConfigConverter;

namespace NowPlayingCore.Core
{
public class MastodonAccount : AccountContainer
{
public MastodonClient mastodonClient;
[JsonConverter(typeof(MastodonClientConverter))]
public MastodonClient MastodonClient { get; set; }

//Will be called on Json.NET deserialization
[JsonConstructor]
#nullable disable
private MastodonAccount()
{
}
#nullable enable

public MastodonAccount(MastodonClient client)
{
mastodonClient = client;
UpdateCache();
MastodonClient = client;
}

[JsonProperty] private string IDCache = "";
public override string ID => $"{IDCache}({mastodonClient.Instance})";
public override string ID => $"{IDCache}({MastodonClient.Instance})";

public override int MaxTweetLength => 500;

public override void UpdateCache()
public override async Task UpdateCache()
{
var account = mastodonClient.GetCurrentUser().Result;
var account = await MastodonClient.GetCurrentUser();
IDCache = account.UserName;
Name = account.DisplayName;
}

public override void UpdateStatus(string UpdateText)
public override async Task UpdateStatus(string UpdateText)
{
mastodonClient.PostStatus(UpdateText, Visibility.Public).Wait();
await MastodonClient.PostStatus(UpdateText, Visibility.Public);
}

public override void UpdateStatus(string UpdateText, string base64image)
public override async Task UpdateStatus(string UpdateText, string base64image)
{
UpdateStatus(UpdateText, base64image, Visibility.Public);
await UpdateStatus(UpdateText, base64image, Visibility.Public);
}

public void UpdateStatus(string UpdateText, Visibility visibility)
public async Task UpdateStatus(string UpdateText, Visibility visibility)
{
mastodonClient.PostStatus(UpdateText, visibility).Wait();
await MastodonClient.PostStatus(UpdateText, visibility);
}

public void UpdateStatus(string UpdateText, string base64image, Visibility visibility)
public async Task UpdateStatus(string UpdateText, string base64image, Visibility visibility)
{
byte[] data = System.Convert.FromBase64String(base64image);
MemoryStream ms = new MemoryStream(data);
var ms = new MemoryStream(data);
var filetype = Matsuri.ImageTool.GetFileTypeFromBytes(data);
var attachment = mastodonClient.UploadMedia(ms, $"nowplaying.{filetype}").Result;
var attachment = await MastodonClient.UploadMedia(ms, $"nowplaying.{filetype}");
ms.Dispose();
mastodonClient.PostStatus(UpdateText, mediaIds: new[] {attachment.Id}, visibility: visibility)
.Wait();
await MastodonClient.PostStatus(UpdateText, mediaIds: new[] {attachment.Id}, visibility: visibility);
}

public override int CountText(string text) => CountTextStatic(text);
Expand Down
Loading

0 comments on commit fd36c71

Please sign in to comment.