Skip to content

Commit 33df543

Browse files
committed
Add !help + code review
1 parent 4a6ae30 commit 33df543

File tree

2 files changed

+56
-109
lines changed

2 files changed

+56
-109
lines changed

ArchiSteamFarm/Bot.cs

Lines changed: 54 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,6 @@ internal Bot(string botName) {
255255
Start().Forget();
256256
}
257257

258-
internal bool IsMaster(ulong steamID) {
259-
if (steamID == 0) {
260-
return false;
261-
}
262-
263-
return steamID == BotConfig.SteamMasterID || IsOwner(steamID);
264-
}
265-
266258
internal async Task AcceptConfirmations(Confirmation.ConfirmationType allowedConfirmationType = Confirmation.ConfirmationType.Unknown) {
267259
if (BotDatabase.SteamGuardAccount == null) {
268260
return;
@@ -342,6 +334,8 @@ internal async Task<string> Response(ulong steamID, string message) {
342334
return ResponseExit(steamID);
343335
case "!farm":
344336
return ResponseFarm(steamID);
337+
case "!help":
338+
return ResponseHelp(steamID);
345339
case "!loot":
346340
return await ResponseSendTrade(steamID).ConfigureAwait(false);
347341
case "!pause":
@@ -378,6 +372,8 @@ internal async Task<string> Response(ulong steamID, string message) {
378372
}
379373
case "!farm":
380374
return ResponseFarm(steamID, args[1]);
375+
case "!help":
376+
return ResponseHelp(steamID, args[1]);
381377
case "!loot":
382378
return await ResponseSendTrade(steamID, args[1]).ConfigureAwait(false);
383379
case "!owns":
@@ -438,6 +434,14 @@ private void Stop() {
438434
Program.OnBotShutdown();
439435
}
440436

437+
private bool IsMaster(ulong steamID) {
438+
if (steamID == 0) {
439+
return false;
440+
}
441+
442+
return steamID == BotConfig.SteamMasterID || IsOwner(steamID);
443+
}
444+
441445
private void ImportAuthenticator(string maFilePath) {
442446
if (BotDatabase.SteamGuardAccount != null || !File.Exists(maFilePath)) {
443447
return;
@@ -495,11 +499,7 @@ private void ImportAuthenticator(string maFilePath) {
495499
}
496500

497501
private async Task<string> ResponsePause(ulong steamID) {
498-
if (steamID == 0) {
499-
return null;
500-
}
501-
502-
if (!IsMaster(steamID)) {
502+
if (steamID == 0 || !IsMaster(steamID)) {
503503
return null;
504504
}
505505

@@ -526,11 +526,7 @@ private static async Task<string> ResponsePause(ulong steamID, string botName) {
526526
}
527527

528528
private string ResponseStatus(ulong steamID) {
529-
if (steamID == 0) {
530-
return null;
531-
}
532-
533-
if (!IsMaster(steamID)) {
529+
if (steamID == 0 || !IsMaster(steamID)) {
534530
return null;
535531
}
536532

@@ -582,11 +578,7 @@ private static string ResponseStatusAll(ulong steamID) {
582578
}
583579

584580
private async Task<string> ResponseSendTrade(ulong steamID) {
585-
if (steamID == 0) {
586-
return null;
587-
}
588-
589-
if (!IsMaster(steamID)) {
581+
if (steamID == 0 || !IsMaster(steamID)) {
590582
return null;
591583
}
592584

@@ -623,11 +615,7 @@ private static async Task<string> ResponseSendTrade(ulong steamID, string botNam
623615
}
624616

625617
private string Response2FA(ulong steamID) {
626-
if (steamID == 0) {
627-
return null;
628-
}
629-
630-
if (!IsMaster(steamID)) {
618+
if (steamID == 0 || !IsMaster(steamID)) {
631619
return null;
632620
}
633621

@@ -653,11 +641,7 @@ private static string Response2FA(ulong steamID, string botName) {
653641
}
654642

655643
private string Response2FAOff(ulong steamID) {
656-
if (steamID == 0) {
657-
return null;
658-
}
659-
660-
if (!IsMaster(steamID)) {
644+
if (steamID == 0 || !IsMaster(steamID)) {
661645
return null;
662646
}
663647

@@ -686,11 +670,7 @@ private static string Response2FAOff(ulong steamID, string botName) {
686670
}
687671

688672
private async Task<string> Response2FAOK(ulong steamID) {
689-
if (steamID == 0) {
690-
return null;
691-
}
692-
693-
if (!IsMaster(steamID)) {
673+
if (steamID == 0 || !IsMaster(steamID)) {
694674
return null;
695675
}
696676

@@ -729,11 +709,7 @@ private static string ResponseExit(ulong steamID) {
729709
}
730710

731711
private string ResponseFarm(ulong steamID) {
732-
if (steamID == 0) {
733-
return null;
734-
}
735-
736-
if (!IsMaster(steamID)) {
712+
if (steamID == 0 || !IsMaster(steamID)) {
737713
return null;
738714
}
739715

@@ -758,12 +734,29 @@ private static string ResponseFarm(ulong steamID, string botName) {
758734
return bot.ResponseFarm(steamID);
759735
}
760736

761-
private async Task<string> ResponseRedeem(ulong steamID, string message, bool validate) {
762-
if (steamID == 0 || string.IsNullOrEmpty(message)) {
737+
private string ResponseHelp(ulong steamID) {
738+
if (steamID == 0 || !IsMaster(steamID)) {
763739
return null;
764740
}
765741

766-
if (!IsMaster(steamID)) {
742+
return "https://github.com/" + Program.GithubRepo + "/wiki/Commands";
743+
}
744+
745+
private static string ResponseHelp(ulong steamID, string botName) {
746+
if (steamID == 0 || string.IsNullOrEmpty(botName)) {
747+
return null;
748+
}
749+
750+
Bot bot;
751+
if (!Bots.TryGetValue(botName, out bot)) {
752+
return "Couldn't find any bot named " + botName + "!";
753+
}
754+
755+
return bot.ResponseHelp(steamID);
756+
}
757+
758+
private async Task<string> ResponseRedeem(ulong steamID, string message, bool validate) {
759+
if (steamID == 0 || string.IsNullOrEmpty(message) || !IsMaster(steamID)) {
767760
return null;
768761
}
769762

@@ -946,11 +939,7 @@ private static string ResponseRestart(ulong steamID) {
946939
}
947940

948941
private async Task<string> ResponseAddLicense(ulong steamID, HashSet<uint> gameIDs) {
949-
if (steamID == 0 || gameIDs == null || gameIDs.Count == 0) {
950-
return null;
951-
}
952-
953-
if (!IsMaster(steamID)) {
942+
if (steamID == 0 || gameIDs == null || gameIDs.Count == 0 || !IsMaster(steamID)) {
954943
return null;
955944
}
956945

@@ -999,11 +988,7 @@ private static async Task<string> ResponseAddLicense(ulong steamID, string botNa
999988
}
1000989

1001990
private async Task<string> ResponseOwns(ulong steamID, string games) {
1002-
if (steamID == 0 || string.IsNullOrEmpty(games)) {
1003-
return null;
1004-
}
1005-
1006-
if (!IsMaster(steamID)) {
991+
if (steamID == 0 || string.IsNullOrEmpty(games) || !IsMaster(steamID)) {
1007992
return null;
1008993
}
1009994

@@ -1055,11 +1040,7 @@ private static async Task<string> ResponseOwns(ulong steamID, string botName, st
10551040
}
10561041

10571042
private async Task<string> ResponsePlay(ulong steamID, HashSet<uint> gameIDs) {
1058-
if (steamID == 0 || gameIDs == null || gameIDs.Count == 0) {
1059-
return null;
1060-
}
1061-
1062-
if (!IsMaster(steamID)) {
1043+
if (steamID == 0 || gameIDs == null || gameIDs.Count == 0 || !IsMaster(steamID)) {
10631044
return null;
10641045
}
10651046

@@ -1107,11 +1088,7 @@ private static async Task<string> ResponsePlay(ulong steamID, string botName, st
11071088
}
11081089

11091090
private async Task<string> ResponseStart(ulong steamID) {
1110-
if (steamID == 0) {
1111-
return null;
1112-
}
1113-
1114-
if (!IsMaster(steamID)) {
1091+
if (steamID == 0 || !IsMaster(steamID)) {
11151092
return null;
11161093
}
11171094

@@ -1137,11 +1114,7 @@ private static async Task<string> ResponseStart(ulong steamID, string botName) {
11371114
}
11381115

11391116
private string ResponseStop(ulong steamID) {
1140-
if (steamID == 0) {
1141-
return null;
1142-
}
1143-
1144-
if (!IsMaster(steamID)) {
1117+
if (steamID == 0 || !IsMaster(steamID)) {
11451118
return null;
11461119
}
11471120

@@ -1167,11 +1140,7 @@ private static string ResponseStop(ulong steamID, string botName) {
11671140
}
11681141

11691142
private string ResponseUnknown(ulong steamID) {
1170-
if (steamID == 0) {
1171-
return null;
1172-
}
1173-
1174-
if (!IsMaster(steamID)) {
1143+
if (steamID == 0 || !IsMaster(steamID)) {
11751144
return null;
11761145
}
11771146

@@ -1414,32 +1383,24 @@ private void OnFreeLicense(SteamApps.FreeLicenseCallback callback) {
14141383
}
14151384

14161385
private void OnChatInvite(SteamFriends.ChatInviteCallback callback) {
1417-
if (callback == null) {
1418-
return;
1419-
}
1420-
1421-
if (!IsMaster(callback.PatronID)) {
1386+
if (callback == null || !IsMaster(callback.PatronID)) {
14221387
return;
14231388
}
14241389

14251390
SteamFriends.JoinChat(callback.ChatRoomID);
14261391
}
14271392

14281393
private async void OnChatMsg(SteamFriends.ChatMsgCallback callback) {
1429-
if (callback == null) {
1430-
return;
1431-
}
1432-
1433-
if (callback.ChatMsgType != EChatEntryType.ChatMsg) {
1434-
return;
1435-
}
1436-
1437-
if (!IsMaster(callback.ChatterID)) {
1394+
if (callback == null || callback.ChatMsgType != EChatEntryType.ChatMsg) {
14381395
return;
14391396
}
14401397

14411398
switch (callback.Message) {
14421399
case "!leave":
1400+
if (!IsMaster(callback.ChatterID)) {
1401+
break;
1402+
}
1403+
14431404
SteamFriends.LeaveChat(callback.ChatRoomID);
14441405
break;
14451406
default:
@@ -1466,38 +1427,23 @@ private void OnFriendsList(SteamFriends.FriendsListCallback callback) {
14661427
if (!IsMaster(friend.SteamID)) {
14671428
break;
14681429
}
1430+
14691431
SteamFriends.AddFriend(friend.SteamID);
14701432
break;
14711433
}
14721434
}
14731435
}
14741436

14751437
private async void OnFriendMsg(SteamFriends.FriendMsgCallback callback) {
1476-
if (callback == null) {
1477-
return;
1478-
}
1479-
1480-
if (callback.EntryType != EChatEntryType.ChatMsg) {
1438+
if (callback == null || callback.EntryType != EChatEntryType.ChatMsg) {
14811439
return;
14821440
}
14831441

14841442
await HandleMessage(callback.Sender, callback.Sender, callback.Message).ConfigureAwait(false);
14851443
}
14861444

14871445
private async void OnFriendMsgHistory(SteamFriends.FriendMsgHistoryCallback callback) {
1488-
if (callback == null) {
1489-
return;
1490-
}
1491-
1492-
if (callback.Result != EResult.OK) {
1493-
return;
1494-
}
1495-
1496-
if (!IsMaster(callback.SteamID)) {
1497-
return;
1498-
}
1499-
1500-
if (callback.Messages.Count == 0) {
1446+
if (callback == null || callback.Result != EResult.OK || callback.Messages.Count == 0 || !IsMaster(callback.SteamID)) {
15011447
return;
15021448
}
15031449

ArchiSteamFarm/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ internal enum EMode : byte {
5959
internal const string ConfigDirectory = "config";
6060
internal const string DebugDirectory = "debug";
6161
internal const string LogFile = "log.txt";
62+
internal const string GithubRepo = "JustArchi/ArchiSteamFarm";
6263
internal const string GlobalConfigFile = ASF + ".json";
6364
internal const string GlobalDatabaseFile = ASF + ".db";
6465

65-
private const string GithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases"; // GitHub API is HTTPS only
66+
private const string GithubReleaseURL = "https://api.github.com/repos/" + GithubRepo + "/releases"; // GitHub API is HTTPS only
6667

6768
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
6869
internal static readonly Version Version = Assembly.GetName().Version;

0 commit comments

Comments
 (0)