Implement plugin system (#1020)

* Implement basic plugin system

* The dawn of new era

* Add plugins warning

* Move more members to PublicAPI

* Open commands for the plugins

* Add IBotHackNewChat

* Run plugin events in parallel

* Use properties in IPlugin

* Hook our custom plugin into CI to ensure it compiles

* Fix dotnet brain damage

* Add IBotsComparer

* Add code documentation

* Add IBotTradeOffer

* Add IBotTradeOffer example

* Add IBotTradeOfferResults

* Final bulletproofing

* Final renaming
This commit is contained in:
Łukasz Domeradzki
2019-01-10 22:33:07 +01:00
committed by GitHub
parent 62a770479e
commit 0f2a816b92
49 changed files with 3025 additions and 1653 deletions

View File

@@ -0,0 +1,361 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Composition.Convention;
using System.Composition.Hosting;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using ArchiSteamFarm.Json;
using ArchiSteamFarm.Localization;
using Newtonsoft.Json.Linq;
using SteamKit2;
namespace ArchiSteamFarm.Plugins {
internal static class Core {
[ImportMany]
private static ImmutableHashSet<IPlugin> ActivePlugins { get; set; }
internal static bool BotUsesNewChat(Bot bot) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return false;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return true;
}
foreach (IBotHackNewChat plugin in ActivePlugins.OfType<IBotHackNewChat>()) {
try {
if (!plugin.BotUsesNewChat(bot)) {
return false;
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
return true;
}
internal static async Task<StringComparer> GetBotsComparer() {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return StringComparer.Ordinal;
}
IList<StringComparer> results;
try {
results = await Utilities.InParallel(ActivePlugins.OfType<IBotsComparer>().Select(plugin => Task.Run(() => plugin.BotsComparer))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return StringComparer.Ordinal;
}
StringComparer result = results.FirstOrDefault(comparer => comparer != null);
return result ?? StringComparer.Ordinal;
}
internal static bool InitPlugins() {
string pluginsPath = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.PluginsDirectory);
if (!Directory.Exists(pluginsPath)) {
ASF.ArchiLogger.LogGenericTrace(Strings.NothingFound);
return true;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.Initializing, nameof(Plugins)));
HashSet<Assembly> assemblies = new HashSet<Assembly>();
try {
foreach (string assemblyPath in Directory.EnumerateFiles(pluginsPath, "*.dll")) {
Assembly assembly;
try {
assembly = Assembly.LoadFrom(assemblyPath);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
continue;
}
assemblies.Add(assembly);
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return false;
}
if (assemblies.Count == 0) {
ASF.ArchiLogger.LogGenericInfo(Strings.NothingFound);
return true;
}
ConventionBuilder conventions = new ConventionBuilder();
conventions.ForTypesDerivedFrom<IPlugin>().Export<IPlugin>();
ContainerConfiguration configuration = new ContainerConfiguration().WithAssemblies(assemblies, conventions);
try {
using (CompositionHost container = configuration.CreateContainer()) {
ActivePlugins = container.GetExports<IPlugin>().ToImmutableHashSet();
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return false;
}
HashSet<IPlugin> invalidPlugins = new HashSet<IPlugin>();
foreach (IPlugin plugin in ActivePlugins) {
try {
string pluginName = plugin.Name;
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.PluginLoading, pluginName, plugin.Version));
plugin.OnLoaded();
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.PluginLoaded, pluginName));
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
invalidPlugins.Add(plugin);
}
}
ImmutableHashSet<IPlugin> activePlugins = ActivePlugins.Except(invalidPlugins);
if (activePlugins.Count == 0) {
ActivePlugins = null;
return false;
}
ActivePlugins = activePlugins;
ASF.ArchiLogger.LogGenericInfo(Strings.PluginsWarning);
return invalidPlugins.Count == 0;
}
internal static async Task OnASFInitModules(IReadOnlyDictionary<string, JToken> additionalConfigProperties = null) {
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IASF>().Select(plugin => Task.Run(() => plugin.OnASFInit(additionalConfigProperties)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
internal static async Task<string> OnBotCommand(Bot bot, ulong steamID, string message, string[] args) {
if ((bot == null) || (steamID == 0) || string.IsNullOrEmpty(message) || (args == null) || (args.Length == 0)) {
ASF.ArchiLogger.LogNullError(nameof(bot) + " || " + nameof(args));
return null;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return null;
}
IList<string> responses;
try {
responses = await Utilities.InParallel(ActivePlugins.OfType<IBotCommand>().Select(plugin => plugin.OnBotCommand(bot, steamID, message, args))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return null;
}
return string.Join(Environment.NewLine, responses.Where(response => !string.IsNullOrEmpty(response)));
}
internal static async Task OnBotDestroy(Bot bot) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IBot>().Select(plugin => Task.Run(() => plugin.OnBotDestroy(bot)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
internal static async Task OnBotDisconnected(Bot bot, EResult reason) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IBotConnection>().Select(plugin => Task.Run(() => plugin.OnBotDisconnected(bot, reason)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
internal static async Task OnBotInit(Bot bot) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IBot>().Select(plugin => Task.Run(() => plugin.OnBotInit(bot)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
internal static async Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JToken> additionalConfigProperties = null) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IBotModules>().Select(plugin => Task.Run(() => plugin.OnBotInitModules(bot, additionalConfigProperties)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
internal static async Task OnBotLoggedOn(Bot bot) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IBotConnection>().Select(plugin => Task.Run(() => plugin.OnBotLoggedOn(bot)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
internal static async Task<string> OnBotMessage(Bot bot, ulong steamID, string message) {
if ((bot == null) || (steamID == 0) || string.IsNullOrEmpty(message)) {
ASF.ArchiLogger.LogNullError(nameof(bot) + " || " + nameof(message));
return null;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return null;
}
IList<string> responses;
try {
responses = await Utilities.InParallel(ActivePlugins.OfType<IBotMessage>().Select(plugin => plugin.OnBotMessage(bot, steamID, message))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return null;
}
return string.Join(Environment.NewLine, responses.Where(response => !string.IsNullOrEmpty(response)));
}
internal static async Task<bool> OnBotTradeOffer(Bot bot, Steam.TradeOffer tradeOffer) {
if ((bot == null) || (tradeOffer == null)) {
ASF.ArchiLogger.LogNullError(nameof(bot) + " || " + nameof(tradeOffer));
return false;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return false;
}
IList<bool> responses;
try {
responses = await Utilities.InParallel(ActivePlugins.OfType<IBotTradeOffer>().Select(plugin => plugin.OnBotTradeOffer(bot, tradeOffer))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return false;
}
return responses.Any(response => response);
}
internal static async Task OnBotTradeOfferResults(Bot bot, IReadOnlyCollection<Trading.ParseTradeResult> tradeResults) {
if ((bot == null) || (tradeResults == null) || (tradeResults.Count == 0)) {
ASF.ArchiLogger.LogNullError(nameof(bot) + " || " + nameof(tradeResults));
return;
}
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return;
}
try {
await Utilities.InParallel(ActivePlugins.OfType<IBotTradeOfferResults>().Select(plugin => Task.Run(() => plugin.OnBotTradeOfferResults(bot, tradeResults)))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
}
}
}
}

View File

@@ -0,0 +1,36 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IASF : IPlugin {
/// <summary>
/// ASF will call this method right after global config initialization.
/// </summary>
/// <param name="additionalConfigProperties">Extra config properties made out of <see cref="JsonExtensionDataAttribute" />. Can be null if no extra properties are found.</param>
void OnASFInit([CanBeNull] IReadOnlyDictionary<string, JToken> additionalConfigProperties = null);
}
}

View File

@@ -0,0 +1,42 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBot : IPlugin {
/// <summary>
/// ASF will call this method after removing its own references from it, e.g. after config removal.
/// You should ensure that you'll remove any of your own references to this bot instance in timely manner.
/// Doing so will allow the garbage collector to dispose the bot afterwards, refraining from doing so will create a "memory leak" by keeping the reference alive.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
void OnBotDestroy([NotNull] Bot bot);
/// <summary>
/// ASF will call this method after creating the bot object, e.g. after config creation.
/// Bot config is not yet available at this stage. This function will execute only once for every bot object.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
void OnBotInit([NotNull] Bot bot);
}
}

View File

@@ -0,0 +1,39 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotCommand : IPlugin {
/// <summary>
/// ASF will call this method for unrecognized commands.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <param name="steamID">64-bit long unsigned integer of steamID executing the command.</param>
/// <param name="message">Command message in its raw format, stripped of <see cref="GlobalConfig.CommandPrefix" />.</param>
/// <param name="args">Pre-parsed message using standard ASF delimiters.</param>
/// <returns>Response to the command, or null/empty (as the task value) if the command isn't handled by this plugin.</returns>
[NotNull]
Task<string> OnBotCommand([NotNull] Bot bot, ulong steamID, [NotNull] string message, [NotNull] string[] args);
}
}

View File

@@ -0,0 +1,41 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using JetBrains.Annotations;
using SteamKit2;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotConnection : IPlugin {
/// <summary>
/// ASF will call this method when bot gets disconnected from Steam network.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <param name="reason">Reason for disconnection, or <see cref="EResult.OK" /> if the disconnection was initiated by ASF (e.g. as a result of a command).</param>
void OnBotDisconnected([NotNull] Bot bot, EResult reason);
/// <summary>
/// ASF will call this method when bot successfully connects to Steam network.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
void OnBotLoggedOn([NotNull] Bot bot);
}
}

View File

@@ -0,0 +1,35 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotHackNewChat : IPlugin {
/// <summary>
/// ASF will use this property for determining whether the bot should use new chat system.
/// Unless you know what you're doing, you should not implement this property yourself and let ASF decide.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <returns>Boolean indicating whether the bot should use new chat system.</returns>
bool BotUsesNewChat([NotNull] Bot bot);
}
}

View File

@@ -0,0 +1,38 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotMessage : IPlugin {
/// <summary>
/// ASF will call this method for messages that are not commands, so ones that do not start from <see cref="GlobalConfig.CommandPrefix" />.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <param name="steamID">64-bit long unsigned integer of steamID executing the command.</param>
/// <param name="message">Message in its raw format.</param>
/// <returns>Response to the message, or null/empty (as the task value) for silence.</returns>
[NotNull]
Task<string> OnBotMessage([NotNull] Bot bot, ulong steamID, [NotNull] string message);
}
}

View File

@@ -0,0 +1,37 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotModules : IPlugin {
/// <summary>
/// ASF will call this method right after bot config initialization.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <param name="additionalConfigProperties">Extra config properties made out of <see cref="JsonExtensionDataAttribute" />. Can be null if no extra properties are found.</param>
void OnBotInitModules([NotNull] Bot bot, [CanBeNull] IReadOnlyDictionary<string, JToken> additionalConfigProperties = null);
}
}

View File

@@ -0,0 +1,38 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Threading.Tasks;
using ArchiSteamFarm.Json;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotTradeOffer : IPlugin {
/// <summary>
/// ASF will call this method for unhandled (ignored and rejected) trade offers received by the bot.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <param name="tradeOffer">Trade offer related to this callback.</param>
/// <returns>True if the trade offer should be accepted as part of this plugin, false otherwise.</returns>
[NotNull]
Task<bool> OnBotTradeOffer([NotNull] Bot bot, [NotNull] Steam.TradeOffer tradeOffer);
}
}

View File

@@ -0,0 +1,35 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotTradeOfferResults : IPlugin {
/// <summary>
/// ASF will call this method for notifying you about the result of each received trade offer being handled. The method is executed for each batch that can contain 1 or more trade offers.
/// </summary>
/// <param name="bot">Bot object related to this callback.</param>
/// <param name="tradeResults">Trade results related to this callback.</param>
void OnBotTradeOfferResults([NotNull] Bot bot, [NotNull] IReadOnlyCollection<Trading.ParseTradeResult> tradeResults);
}
}

View File

@@ -0,0 +1,36 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IBotsComparer : IPlugin {
/// <summary>
/// ASF will use this property for determining the comparer for the bots.
/// Unless you know what you're doing, you should not implement this property yourself and let ASF decide.
/// </summary>
/// <returns>Comparer that will be used for the bots, as well as bot regexes.</returns>
[NotNull]
StringComparer BotsComparer { get; }
}
}

View File

@@ -0,0 +1,48 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2019 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Plugins {
[PublicAPI]
public interface IPlugin {
/// <summary>
/// ASF will use this property as general plugin identifier for the user.
/// </summary>
/// <returns>String that will be used as the name of this plugin.</returns>
[NotNull]
string Name { get; }
/// <summary>
/// ASF will use this property as version indicator of your plugin to the user.
/// You have a freedom in deciding what versionining you want to use, this is for identification purposes only.
/// </summary>
/// <returns>Version that will be shown to the user when plugin is loaded.</returns>
[NotNull]
Version Version { get; }
/// <summary>
/// ASF will call this method right after plugin initialization.
/// </summary>
void OnLoaded();
}
}