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

@@ -24,13 +24,14 @@ using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using ArchiSteamFarm.Localization;
using JetBrains.Annotations;
using NLog;
namespace ArchiSteamFarm.NLog {
internal sealed class ArchiLogger {
public sealed class ArchiLogger {
private readonly Logger Logger;
internal ArchiLogger(string name) {
public ArchiLogger(string name) {
if (string.IsNullOrEmpty(name)) {
throw new ArgumentNullException(nameof(name));
}
@@ -38,6 +39,107 @@ namespace ArchiSteamFarm.NLog {
Logger = LogManager.GetLogger(name);
}
[PublicAPI]
public void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Debug($"{previousMethodName}() {message}");
}
[PublicAPI]
public void LogGenericDebuggingException(Exception exception, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception));
return;
}
if (!Debugging.IsUserDebugging) {
return;
}
Logger.Debug(exception, $"{previousMethodName}()");
}
[PublicAPI]
public void LogGenericError(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Error($"{previousMethodName}() {message}");
}
[PublicAPI]
public void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception));
return;
}
Logger.Error(exception, $"{previousMethodName}()");
}
[PublicAPI]
public void LogGenericInfo(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Info($"{previousMethodName}() {message}");
}
[PublicAPI]
public void LogGenericTrace(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Trace($"{previousMethodName}() {message}");
}
[PublicAPI]
public void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Warn($"{previousMethodName}() {message}");
}
[PublicAPI]
public void LogGenericWarningException(Exception exception, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception));
return;
}
Logger.Warn(exception, $"{previousMethodName}()");
}
[PublicAPI]
public void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(nullObjectName)) {
return;
}
LogGenericError(string.Format(Strings.ErrorObjectIsNull, nullObjectName), previousMethodName);
}
internal void LogChatMessage(bool echo, string message, ulong chatGroupID = 0, ulong chatID = 0, ulong steamID = 0, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message) || (((chatGroupID == 0) || (chatID == 0)) && (steamID == 0))) {
LogNullError(nameof(message) + " || " + "((" + nameof(chatGroupID) + " || " + nameof(chatID) + ") && " + nameof(steamID) + ")");
@@ -120,97 +222,5 @@ namespace ArchiSteamFarm.NLog {
break;
}
}
internal void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Debug($"{previousMethodName}() {message}");
}
internal void LogGenericDebuggingException(Exception exception, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception));
return;
}
if (!Debugging.IsUserDebugging) {
return;
}
Logger.Debug(exception, $"{previousMethodName}()");
}
internal void LogGenericError(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Error($"{previousMethodName}() {message}");
}
internal void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception));
return;
}
Logger.Error(exception, $"{previousMethodName}()");
}
internal void LogGenericInfo(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Info($"{previousMethodName}() {message}");
}
internal void LogGenericTrace(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Trace($"{previousMethodName}() {message}");
}
internal void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message));
return;
}
Logger.Warn($"{previousMethodName}() {message}");
}
internal void LogGenericWarningException(Exception exception, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception));
return;
}
Logger.Warn(exception, $"{previousMethodName}()");
}
internal void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(nullObjectName)) {
return;
}
LogGenericError(string.Format(Strings.ErrorObjectIsNull, nullObjectName), previousMethodName);
}
}
}

View File

@@ -21,8 +21,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using ArchiSteamFarm.Collections;
using JetBrains.Annotations;
using NLog;
using NLog.Targets;
@@ -38,7 +38,7 @@ namespace ArchiSteamFarm.NLog {
private readonly FixedSizeConcurrentQueue<string> HistoryQueue = new FixedSizeConcurrentQueue<string>(DefaultMaxCount);
// This is NLog config property, it must have public get() and set() capabilities
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[PublicAPI]
public byte MaxCount {
get => HistoryQueue.MaxCount;
@@ -55,7 +55,7 @@ namespace ArchiSteamFarm.NLog {
// This parameter-less constructor is intentionally public, as NLog uses it for creating targets
// It must stay like this as we want to have our targets defined in our NLog.config
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[PublicAPI]
public HistoryTarget() { }
internal HistoryTarget(string name) : this() => Name = name;

View File

@@ -22,6 +22,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using NLog;
using NLog.Config;
using NLog.Targets;
@@ -33,18 +34,15 @@ namespace ArchiSteamFarm.NLog {
internal const string TargetName = "Steam";
// This is NLog config property, it must have public get() and set() capabilities
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
[PublicAPI]
public string BotName { get; set; }
// This is NLog config property, it must have public get() and set() capabilities
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
[PublicAPI]
public ulong ChatGroupID { get; set; }
// This is NLog config property, it must have public get() and set() capabilities
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
[PublicAPI]
[RequiredParameter]
public ulong SteamID { get; set; }