@@ -17,9 +17,7 @@ public sealed class ASFAchievementManager : IBotSteamClient, IBotMessage, IBotCo
17
17
public string Name => "ASF Achievement Manager" ;
18
18
public Version Version => typeof ( ASFAchievementManager ) . Assembly . GetName ( ) . Version ;
19
19
20
- public void OnLoaded ( ) {
21
- ASF . ArchiLogger . LogGenericInfo ( "ASF Achievement Manager Plugin by Ryzhehvost, powered by ginger cats" ) ;
22
- }
20
+ public void OnLoaded ( ) => ASF . ArchiLogger . LogGenericInfo ( "ASF Achievement Manager Plugin by Ryzhehvost, powered by ginger cats" ) ;
23
21
24
22
public async Task < string > OnBotMessage ( [ NotNull ] Bot bot , ulong steamID , [ NotNull ] string message ) {
25
23
if ( ! bot . HasPermission ( steamID , BotConfig . EPermission . Master ) ) {
@@ -59,9 +57,7 @@ public async Task<string> OnBotMessage([NotNull] Bot bot, ulong steamID, [NotNul
59
57
}
60
58
}
61
59
62
- public async Task < string > OnBotCommand ( [ NotNull ] Bot bot , ulong steamID , [ NotNull ] string message , string [ ] args ) {
63
- return await OnBotMessage ( bot , steamID , string . Join ( " " , args ) ) . ConfigureAwait ( false ) ;
64
- }
60
+ public async Task < string > OnBotCommand ( [ NotNull ] Bot bot , ulong steamID , [ NotNull ] string message , string [ ] args ) => await OnBotMessage ( bot , steamID , string . Join ( " " , args ) ) . ConfigureAwait ( false ) ;
65
61
66
62
public void OnBotSteamCallbacksInit ( [ NotNull ] Bot bot , [ NotNull ] CallbackManager callbackManager ) { }
67
63
@@ -91,11 +87,10 @@ private static async Task<string> ResponseAchievementList(Bot bot, string appids
91
87
gamesToGetAchievements . Add ( gameID ) ;
92
88
}
93
89
94
- //maybe just do it with foreach? It won't be parallel anyway.
95
- List < string > responses = new List < string > ( ) ;
96
- foreach ( uint appID in gamesToGetAchievements ) {
97
- responses . Add ( await AchievementHandler . GetAchievements ( bot , appID ) . ConfigureAwait ( false ) ) ;
98
- }
90
+
91
+ IList < string > results = await Utilities . InParallel ( gamesToGetAchievements . Select ( appID => Task . Run < string > ( ( ) => AchievementHandler . GetAchievements ( bot , appID ) ) ) ) . ConfigureAwait ( false ) ;
92
+
93
+ List < string > responses = new List < string > ( results . Where ( result => ! string . IsNullOrEmpty ( result ) ) ) ;
99
94
100
95
return responses . Count > 0 ? bot . Commands . FormatBotResponse ( string . Join ( Environment . NewLine , responses ) ) : null ;
101
96
@@ -123,8 +118,7 @@ private static async Task<string> ResponseAchievementList(string botNames, strin
123
118
124
119
125
120
private static async Task < string > ResponseAchievementSet ( Bot bot , string appid , string AchievementNumbers , bool set = true ) {
126
- uint appId ;
127
- if ( ! uint . TryParse ( appid , out appId ) ) {
121
+ if ( ! uint . TryParse ( appid , out uint appId ) ) {
128
122
return bot . Commands . FormatBotResponse ( string . Format ( Strings . ErrorIsInvalid , nameof ( appId ) ) ) ;
129
123
}
130
124
@@ -148,7 +142,7 @@ private static async Task<string> ResponseAchievementSet(Bot bot, string appid,
148
142
return bot . Commands . FormatBotResponse ( string . Format ( Strings . ErrorIsEmpty , "Achievements list" ) ) ;
149
143
}
150
144
}
151
- return bot . Commands . FormatBotResponse ( await AchievementHandler . SetAchievements ( bot , appId , achievements , set ) . ConfigureAwait ( false ) ) ;
145
+ return bot . Commands . FormatBotResponse ( await Task . Run < string > ( ( ) => AchievementHandler . SetAchievements ( bot , appId , achievements , set ) ) . ConfigureAwait ( false ) ) ;
152
146
}
153
147
154
148
private static async Task < string > ResponseAchievementSet ( string botNames , string appid , string AchievementNumbers , bool set = true ) {
@@ -165,48 +159,7 @@ private static async Task<string> ResponseAchievementSet(string botNames, string
165
159
166
160
return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
167
161
}
168
- /*
169
- private static async Task<string> ResponseAchievementReset(Bot bot, string appid, string AchievementNumbers) {
170
- uint appId;
171
- if (!uint.TryParse(appid, out appId)) {
172
- return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorIsInvalid, nameof(appId)));
173
- }
174
-
175
- if (!AchievementHandlers.TryGetValue(bot, out AchievementHandler AchievementHandler)) {
176
- return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(AchievementHandlers)));
177
- }
178
-
179
- HashSet<uint> achievements = new HashSet<uint>();
180
-
181
- string[] achievementStrings = AchievementNumbers.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
182
-
183
- foreach (string achievement in achievementStrings) {
184
- if (!uint.TryParse(achievement, out uint achievementNumber) || (achievementNumber == 0)) {
185
- return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorParsingObject, nameof(achievement)));
186
- }
187
-
188
- achievements.Add(achievementNumber);
189
- }
190
-
191
- return bot.Commands.FormatBotResponse(await AchievementHandler.SetAchievements(bot, appId, achievements,false).ConfigureAwait(false));
192
-
193
- }
194
162
195
- private static async Task<string> ResponseAchievementReset(string botNames, string appid, string AchievementNumbers) {
196
-
197
- HashSet<Bot> bots = Bot.GetBots(botNames);
198
-
199
- if ((bots == null) || (bots.Count == 0)) {
200
- return Commands.FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
201
- }
202
-
203
- IList<string> results = await Utilities.InParallel(bots.Select(bot => ResponseAchievementReset(bot, appid, AchievementNumbers))).ConfigureAwait(false);
204
-
205
- List<string> responses = new List<string>(results.Where(result => !string.IsNullOrEmpty(result)));
206
-
207
- return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
208
- }
209
- */
210
163
}
211
164
212
165
}
0 commit comments