1 // ----------------------------------------------------------------------------------------------
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
9 // Copyright 2015-2024 Ćukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
16 // http://www.apache.org/licenses/LICENSE-2.0
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
25 using System
.Collections
.Generic
;
26 using System
.ComponentModel
;
27 using System
.ComponentModel
.DataAnnotations
;
28 using System
.Composition
;
29 using System
.Diagnostics
.CodeAnalysis
;
30 using System
.Text
.Json
.Serialization
;
31 using System
.Threading
.Tasks
;
32 using ArchiSteamFarm
.Core
;
33 using ArchiSteamFarm
.OfficialPlugins
.MobileAuthenticator
.Localization
;
34 using ArchiSteamFarm
.Plugins
;
35 using ArchiSteamFarm
.Plugins
.Interfaces
;
36 using ArchiSteamFarm
.Steam
;
39 namespace ArchiSteamFarm
.OfficialPlugins
.MobileAuthenticator
;
41 [Export(typeof(IPlugin
))]
42 [SuppressMessage("ReSharper", "MemberCanBeFileLocal")]
43 internal sealed class MobileAuthenticatorPlugin
: OfficialPlugin
, IBotCommand2
, IBotSteamClient
{
46 public override string Name
=> nameof(MobileAuthenticatorPlugin
);
50 public override Version Version
=> typeof(MobileAuthenticatorPlugin
).Assembly
.GetName().Version
?? throw new InvalidOperationException(nameof(Version
));
52 public async Task
<string?> OnBotCommand(Bot bot
, EAccess access
, string message
, string[] args
, ulong steamID
= 0) {
53 ArgumentNullException
.ThrowIfNull(bot
);
55 if (!Enum
.IsDefined(access
)) {
56 throw new InvalidEnumArgumentException(nameof(access
), (int) access
, typeof(EAccess
));
59 ArgumentException
.ThrowIfNullOrEmpty(message
);
61 if ((args
== null) || (args
.Length
== 0)) {
62 throw new ArgumentNullException(nameof(args
));
65 if ((steamID
!= 0) && !new SteamID(steamID
).IsIndividualAccount
) {
66 throw new ArgumentOutOfRangeException(nameof(steamID
));
69 return await Commands
.OnBotCommand(bot
, access
, message
, args
, steamID
).ConfigureAwait(false);
72 public Task
OnBotSteamCallbacksInit(Bot bot
, CallbackManager callbackManager
) {
73 ArgumentNullException
.ThrowIfNull(bot
);
74 ArgumentNullException
.ThrowIfNull(callbackManager
);
76 return Task
.CompletedTask
;
79 public Task
<IReadOnlyCollection
<ClientMsgHandler
>?> OnBotSteamHandlersInit(Bot bot
) {
80 ArgumentNullException
.ThrowIfNull(bot
);
82 SteamUnifiedMessages
? steamUnifiedMessages
= bot
.GetHandler
<SteamUnifiedMessages
>();
84 if (steamUnifiedMessages
== null) {
85 throw new InvalidOperationException(nameof(steamUnifiedMessages
));
88 return Task
.FromResult
<IReadOnlyCollection
<ClientMsgHandler
>?>(new HashSet
<ClientMsgHandler
>(1) { new MobileAuthenticatorHandler(bot.ArchiLogger, steamUnifiedMessages) }
);
91 public override Task
OnLoaded() {
92 Utilities
.WarnAboutIncompleteTranslation(Strings
.ResourceManager
);
94 return Task
.CompletedTask
;