Skip to content
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
2 changes: 1 addition & 1 deletion Examples/HostedCommandsBot/HostedCommandsBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>TehGM.Wolfringo.Examples.HostedCommandsBot</RootNamespace>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Examples/HostedCommandsBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
// add wolf client
services.AddWolfClient()
/** Commented methods below override configuration from appsettings.json and appsecrets.json - use them if you want to override, or do not use config files **/
//.SetCredentials("login", "password") -- sets bot credentials. Note: it's recommended to not use this method,
//.SetCredentials("login", "password", "api key") -- sets bot credentials. Note: it's recommended to not use this method,
// and stick to config file that is excluded from the repository - such as appsettings.json in this example
//.SetAutoReconnectAttempts(15) -- sets auto reconnect attempts limit
//.SetAutoReconnectDelay(TimeSpan.FromSeconds(1)) -- sets delay between auto reconnect attempts
Expand Down
3 changes: 2 additions & 1 deletion Examples/HostedCommandsBot/appsecrets-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"WolfClient": {
"LoginUsername": "MyBotUsername",
"LoginPassword": "MyBotPassword",
"LoginType": "Email"
"LoginType": "Email",
"ApiKey": "MyBotApiKey"
}
}
2 changes: 1 addition & 1 deletion Examples/HostedPingBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void Main(string[] args)
services.Configure<HostedWolfClientOptions>(context.Configuration.GetSection("WolfClient"));
services.AddWolfClient()
/** Commented methods below override configuration from appsettings.json and appsecrets.json - use them if you want to override, or do not use config files **/
//.SetCredentials("login", "password") -- sets bot credentials. Note: it's recommended to not use this method,
//.SetCredentials("login", "password", "api key") -- sets bot credentials. Note: it's recommended to not use this method,
// and stick to config file that is excluded from the repository - such as appsettings.json in this example
//.SetAutoReconnectAttempts(15) -- sets auto reconnect attempts limit
//.SetAutoReconnectDelay(TimeSpan.FromSeconds(1)) -- sets delay between auto reconnect attempts
Expand Down
3 changes: 2 additions & 1 deletion Examples/HostedPingBot/appsecrets-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"WolfClient": {
"LoginUsername": "MyBotUsername",
"LoginPassword": "MyBotPassword",
"LoginType": "Email"
"LoginType": "Email",
"ApiKey": "MyBotApiKey"
}
}
2 changes: 2 additions & 0 deletions Examples/SimpleCommandsBot/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Config
public string Username { get; private set; }
[JsonProperty("password")]
public string Password { get; private set; }
[JsonProperty("apiKey")]
public string ApiKey { get; private set; }

public static Config Load()
=> JsonConvert.DeserializeObject<Config>(File.ReadAllText("appsecrets.json"));
Expand Down
2 changes: 2 additions & 0 deletions Examples/SimpleCommandsBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static async Task Main(string[] args)

// create client with builder
_client = new WolfClientBuilder()
// configure API Key
.WithApiKey(Config.Load().ApiKey)
// add logging
.WithLogging(CreateLoggerFactory())
// add commands
Expand Down
3 changes: 2 additions & 1 deletion Examples/SimpleCommandsBot/appsecrets-example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"username": "MyBotUsername",
"password": "MyBotPassword"
"password": "MyBotPassword",
"apiKey": "MyBotApiKey"
}
2 changes: 2 additions & 0 deletions Examples/SimplePingBot/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Config
public string Username { get; private set; }
[JsonProperty("password")]
public string Password { get; private set; }
[JsonProperty("apiKey")]
public string ApiKey { get; private set; }

public static Config Load()
=> JsonConvert.DeserializeObject<Config>(File.ReadAllText("appsecrets.json"));
Expand Down
3 changes: 2 additions & 1 deletion Examples/SimplePingBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ static async Task Main(string[] args)
// optional: create a logger
ILogger<WolfClient> log = CreateLogger<WolfClient>();

// create client and listen to events we're interested in
// create client, set API Key and listen to events we're interested in
_client = new WolfClientBuilder()
.WithApiKey(Config.Load().ApiKey)
.WithLogging(log)
.Build();
_client.MessageReceived += OnMessageReceived; // This event is raised when client receives and parses any message type.
Expand Down
3 changes: 2 additions & 1 deletion Examples/SimplePingBot/appsecrets-example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"username": "MyBotUsername",
"password": "MyBotPassword"
"password": "MyBotPassword",
"apiKey": "MyBotApiKey"
}
5 changes: 2 additions & 3 deletions Wolfringo.Commands/Wolfringo.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
<RootNamespace>TehGM.Wolfringo.Commands</RootNamespace>
<Version>2.2.0</Version>
<Version>2.2.1</Version>
<Authors>TehGM</Authors>
<Product>Wolfringo</Product>
<Description>Commands System for Wolfringo library.</Description>
Expand All @@ -18,8 +18,7 @@
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<PackageReleaseNotes>
- Add support for Link and Image preview embeds;
- Chat Messages and retrieved chat histories will now have Embeds property properly populated;
Compatibility patch for Wolfringo 2.2.1.
</PackageReleaseNotes>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions Wolfringo.Core/Messages/MessageEventNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,7 @@ public static class MessageEventNames
public const string TipAdd = "tip add";
/// <summary>WOLF Protocol Event name for <see cref="UrlMetadataMessage"/>.</summary>
public const string MetadataUrl = "metadata url";
/// <summary>WOLF Protocol Event name for <see cref="ObjectionEvent"/>.</summary>
public const string Objection = "objection";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public MessageSerializerProviderOptions()
{ MessageEventNames.TipSummary, new DefaultMessageSerializer<TipSummaryMessage>() },
{ MessageEventNames.TipDetail, new DefaultMessageSerializer<TipDetailsMessage>() },
{ MessageEventNames.MetadataUrl, new DefaultMessageSerializer<UrlMetadataMessage>() },
{ MessageEventNames.Objection, new DefaultMessageSerializer<ObjectionEvent>() },
// group join and leave
{ MessageEventNames.GroupMemberAdd, new GroupJoinLeaveMessageSerializer<GroupJoinMessage>() },
{ MessageEventNames.GroupMemberDelete, new GroupJoinLeaveMessageSerializer<GroupLeaveMessage>() },
Expand Down
25 changes: 25 additions & 0 deletions Wolfringo.Core/Messages/Types/ObjectionEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace TehGM.Wolfringo.Messages
{
/// <summary>Represents a WOLF objection error.</summary>
public class ObjectionEvent : IWolfMessage
{
/// <inheritdoc/>
/// <remarks>Equals to <see cref="MessageEventNames.Objection"/>.</remarks>
[JsonIgnore]
public string EventName => MessageEventNames.Objection;

/// <summary>Error message.</summary>
[JsonProperty("message")]
public string Message { get; private set; }
/// <summary>Time in seconds to wait before reconnecting.</summary>
/// <remarks>Value of -1 indicates no reconnect.</remarks>
[JsonProperty("reconnectSeconds")]
public int ReconnectSeconds { get; private set; }

/// <summary>Creates a message instance.</summary>
[JsonConstructor]
protected ObjectionEvent() { }
}
}
8 changes: 7 additions & 1 deletion Wolfringo.Core/WolfClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class WolfClient : IWolfClient, IWolfClientCacheAccessor, IDisposable
protected bool IgnoreOwnChatMessages { get; }
/// <summary>Token used with the connection.</summary>
protected string Token { get; }
/// <summary>API Key used to connect.</summary>
protected string ApiKey { get; }
/// <summary>Socket client used by this WOLF client.</summary>
protected ISocketClient SocketClient { get; }
/// <summary>Callbacks dispatcher used by this WOLF client.</summary>
Expand Down Expand Up @@ -108,6 +110,7 @@ public WolfClient(IServiceProvider services, WolfClientOptions options)
this.IgnoreOwnChatMessages = options.IgnoreOwnChatMessages;
this.Url = options.ServerURL;
this.Device = options.Device;
this.ApiKey = options.ApiKey;
this.Token = tokenProvider.GetToken();

// init dispatcher
Expand Down Expand Up @@ -187,8 +190,9 @@ public async Task ConnectAsync(WolfDevice device, CancellationToken cancellation
this.Clear();
await this.Cache.OnConnectingAsync(this, cancellationToken).ConfigureAwait(false);
this._connectionCts = new CancellationTokenSource();
string path = $"/socket.io/?token={this.Token}&device={device.ToString().ToLowerInvariant()}&EIO=3&transport=websocket&apiKey={this.ApiKey}";
await this.SocketClient.ConnectAsync(
new Uri(new Uri(this.Url), $"/socket.io/?token={this.Token}&device={device.ToString().ToLowerInvariant()}&EIO=3&transport=websocket"),
new Uri(new Uri(this.Url), path),
cancellationToken).ConfigureAwait(false);
}

Expand Down Expand Up @@ -419,6 +423,8 @@ private async void OnClientMessageReceived(object sender, SocketMessageEventArgs
// if welcome is already logged in, we can populate userID
if (msg is WelcomeEvent welcome && welcome.LoggedInUser != null)
this.CurrentUserID = welcome.LoggedInUser.ID;
else if (msg is ObjectionEvent objection)
this.Log?.LogError("Server objected: {Message}", objection.Message);

// cache
if (this.Cache != null)
Expand Down
11 changes: 11 additions & 0 deletions Wolfringo.Core/WolfClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public WolfClientBuilder WithBetaServerURL()
public WolfClientBuilder WithDevice(WolfDevice device)
=> this.ConfigureOptions(options => options.Device = device);

// API KEY
/// <summary>Sets API Key to connect with.</summary>
/// <param name="apiKey">API Key to connect with.</param>
/// <returns>Current builder instance.</returns>
public WolfClientBuilder WithApiKey(string apiKey)
{
if (string.IsNullOrWhiteSpace(apiKey))
throw new ArgumentNullException(nameof(apiKey));
return this.ConfigureOptions(options => options.ApiKey = apiKey);
}

/// <summary>Allows configuring options for Wolf Client.</summary>
/// <param name="configure">Delegate that can be used for options configuration.</param>
/// <returns>Current builder instance.</returns>
Expand Down
2 changes: 2 additions & 0 deletions Wolfringo.Core/WolfClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class WolfClientOptions
/// <summary>Default device to pass to the server when connecting.</summary>
public const WolfDevice DefaultDevice = WolfDevice.Bot;

/// <summary>API Key to connect with. Must match the account that will be used to connect.</summary>
public string ApiKey { get; set; }
/// <summary>WOLF server URL to connect to.</summary>
public string ServerURL { get; set; } = DefaultServerURL;
/// <summary>Device to connect as.</summary>
Expand Down
18 changes: 4 additions & 14 deletions Wolfringo.Core/Wolfringo.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,23 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net9.0</TargetFrameworks>
<RootNamespace>TehGM.Wolfringo</RootNamespace>
<Version>2.2.0</Version>
<Version>2.2.1</Version>
<Authors>TehGM</Authors>
<Product>Wolfringo</Product>
<RepositoryUrl>https://github.com/TehGM/Wolfringo</RepositoryUrl>
<Copyright>Copyright (c) 2020 TehGM</Copyright>
<Description>A .NET Library for WOLF (previously Palringo)</Description>
<PackageProjectUrl>https://wolfringo.tehgm.net</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<AssemblyVersion>2.2.1.0</AssemblyVersion>
<FileVersion>2.2.1.0</FileVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageTags>wolf palringo wolfringo pal bot client</PackageTags>
<PackageIcon>wolfringo_logo.png</PackageIcon>
<PackageReleaseNotes>
- Add IChatEmbedDeserializer to allow deserialization of chat embeds;
- Add support for Link and Image preview embeds;
- Chat Messages and retrieved chat histories will now have Embeds property properly populated;
- ChatMessageSendingOptions provide 2 predefined statics: DisableEmbeds and DisableLinkDetection;
- Update UrlMetadataMessage to use headers with version 2;
- Fix an error when a message containing an embed is received;
- Fix link metadata message not having a serializer registered with the provider;
- ChatMessageSerializer now has a constructor that takes a IChatEmbedDeserializer;
- ChatHistoryResponseSerializer now has a constructor that takes a IChatEmbedDeserializer;
- Removed unnecessary locks in CommandsSystem, MessageSerializerProvider and ResponseSerializerProvider;
- BuildDefaultServiceProvider protected methods are marked as obsolete in WolfClient and CommandsSystem;
- Support connecting with API Key.
</PackageReleaseNotes>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion Wolfringo.Hosting/HostedWolfClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ private void CreateClient()
{
IgnoreOwnChatMessages = options.IgnoreOwnChatMessages,
Device = options.Device,
ServerURL = options.ServerURL
ServerURL = options.ServerURL,
ApiKey = options.ApiKey
});

// sub to events
Expand Down
2 changes: 2 additions & 0 deletions Wolfringo.Hosting/HostedWolfClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class HostedWolfClientOptions
/// <summary>Whether the hosted client should automatically login when connected.</summary>
/// <remarks>Defaults to true.</remarks>
public bool AutoLogin { get; set; } = true;
/// <summary>API Key to connect with. Must match the account that will be used to connect.</summary>
public string ApiKey { get; set; }
/// <summary>Username to use as login when automatically logging in.</summary>
public string LoginUsername { get; set; }
/// <summary>Password to authenticate with when automatically logging in.</summary>
Expand Down
14 changes: 14 additions & 0 deletions Wolfringo.Hosting/WolfClientServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,25 @@ public static IHostedWolfClientServiceBuilder AddWolfClient(this IServiceCollect
/// <seealso cref="HostedWolfClientOptions.LoginUsername"/>
/// <seealso cref="HostedWolfClientOptions.LoginPassword"/>
/// <seealso cref="HostedWolfClientOptions.LoginType"/>
[Obsolete("WOLF is making changes to require API Key to connect. Use overload that accepts API Key as a parameter")]
public static IHostedWolfClientServiceBuilder SetCredentials(this IHostedWolfClientServiceBuilder builder, string login, string password, WolfLoginType loginType = WolfLoginType.Email)
=> builder.SetCredentials(login, password, null, loginType);

/// <summary>Sets login credentials.</summary>
/// <param name="builder">Hosted WOLF Client Service builder.</param>
/// <param name="login">Login.</param>
/// <param name="password">Password.</param>
/// <param name="apiKey">API Key. Must match API Key assigned for this user.</param>
/// <param name="loginType">Login Type.</param>
/// <seealso cref="HostedWolfClientOptions.LoginUsername"/>
/// <seealso cref="HostedWolfClientOptions.LoginPassword"/>
/// <seealso cref="HostedWolfClientOptions.LoginType"/>
public static IHostedWolfClientServiceBuilder SetCredentials(this IHostedWolfClientServiceBuilder builder, string login, string password, string apiKey, WolfLoginType loginType = WolfLoginType.Email)
=> builder.Configure(options =>
{
options.LoginUsername = login;
options.LoginPassword = password;
options.ApiKey = apiKey;
options.LoginType = loginType;
});

Expand Down
4 changes: 2 additions & 2 deletions Wolfringo.Hosting/Wolfringo.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.0;net9.0</TargetFrameworks>
<Version>2.2.0</Version>
<Version>2.2.1</Version>
<Authors>TehGM</Authors>
<Copyright>Copyright (c) 2020 TehGM</Copyright>
<PackageProjectUrl>https://wolfringo.tehgm.net</PackageProjectUrl>
Expand All @@ -17,7 +17,7 @@
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<PackageReleaseNotes>
Compatibility patch for Wolfringo 2.2.0.
- Support connecting with API Key.
</PackageReleaseNotes>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
18 changes: 4 additions & 14 deletions Wolfringo/Wolfringo.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Wolfringo</id>
<version>2.2.0</version>
<version>2.2.1</version>
<title>Wolfringo</title>
<authors>TehGM</authors>
<owners>TehGM</owners>
Expand All @@ -16,24 +16,14 @@
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<copyright>Copyright (c) 2020 TehGM</copyright>
<releaseNotes>
- Add IChatEmbedDeserializer to allow deserialization of chat embeds;
- Add support for Link and Image preview embeds;
- Chat Messages and retrieved chat histories will now have Embeds property properly populated;
- ChatMessageSendingOptions provide 2 predefined statics: DisableEmbeds and DisableLinkDetection;
- Update UrlMetadataMessage to use headers with version 2;
- Fix an error when a message containing an embed is received;
- Fix link metadata message not having a serializer registered with the provider;
- ChatMessageSerializer now has a constructor that takes a IChatEmbedDeserializer;
- ChatHistoryResponseSerializer now has a constructor that takes a IChatEmbedDeserializer;
- Removed unnecessary locks in CommandsSystem, MessageSerializerProvider and ResponseSerializerProvider;
- BuildDefaultServiceProvider protected methods are marked as obsolete in WolfClient and CommandsSystem;
- Support connecting with API Key.
</releaseNotes>
<dependencies>
<group>
<dependency id="Wolfringo.Core" version="2.2.0" />
<dependency id="Wolfringo.Core" version="2.2.1" />
<dependency id="Wolfringo.Utilities" version="2.2.0" />
<dependency id="Wolfringo.Utilities.Interactive" version="2.0.0" />
<dependency id="Wolfringo.Commands" version="2.2.0"/>
<dependency id="Wolfringo.Commands" version="2.2.1"/>
</group>
</dependencies>
</metadata>
Expand Down
Loading
Loading