localized playing rotate commands
This commit is contained in:
		| @@ -1,5 +1,4 @@ | ||||
| using Discord; | ||||
| using Discord.Commands; | ||||
| using Discord.Commands; | ||||
| using Discord.WebSocket; | ||||
| using NadekoBot.Attributes; | ||||
| using NadekoBot.Extensions; | ||||
| @@ -8,7 +7,6 @@ using NadekoBot.Services.Database.Models; | ||||
| using NLog; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Diagnostics; | ||||
| using System.Linq; | ||||
| using System.Threading; | ||||
| using System.Threading.Tasks; | ||||
| @@ -20,14 +18,15 @@ namespace NadekoBot.Modules.Administration | ||||
|         [Group] | ||||
|         public class PlayingRotateCommands : NadekoSubmodule | ||||
|         { | ||||
|             private static Logger _log { get; } | ||||
|             public static List<PlayingStatus> RotatingStatusMessages { get; } | ||||
|             public static bool RotatingStatuses { get; private set; } = false; | ||||
|             private static Timer _t { get; } | ||||
|             public static volatile bool RotatingStatuses; | ||||
|             private readonly object _locker = new object(); | ||||
|             private new static Logger _log { get; } | ||||
|             private static readonly Timer _t; | ||||
|  | ||||
|             private class TimerState | ||||
|             { | ||||
|                 public int Index { get; set; } = 0; | ||||
|                 public int Index { get; set; } | ||||
|             } | ||||
|  | ||||
|             static PlayingRotateCommands() | ||||
| @@ -37,8 +36,6 @@ namespace NadekoBot.Modules.Administration | ||||
|                 RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages; | ||||
|                 RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses; | ||||
|  | ||||
|  | ||||
|  | ||||
|                 _t = new Timer(async (objState) => | ||||
|                 { | ||||
|                     try | ||||
| @@ -46,26 +43,24 @@ namespace NadekoBot.Modules.Administration | ||||
|                         var state = (TimerState)objState; | ||||
|                         if (!RotatingStatuses) | ||||
|                             return; | ||||
|                         else | ||||
|                         { | ||||
|                             if (state.Index >= RotatingStatusMessages.Count) | ||||
|                                 state.Index = 0; | ||||
|                         if (state.Index >= RotatingStatusMessages.Count) | ||||
|                             state.Index = 0; | ||||
|  | ||||
|                             if (!RotatingStatusMessages.Any()) | ||||
|                                 return; | ||||
|                             var status = RotatingStatusMessages[state.Index++].Status; | ||||
|                             if (string.IsNullOrWhiteSpace(status)) | ||||
|                                 return; | ||||
|                             PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value())); | ||||
|                             var shards = NadekoBot.Client.Shards; | ||||
|                             for (int i = 0; i < shards.Count; i++) | ||||
|                         if (!RotatingStatusMessages.Any()) | ||||
|                             return; | ||||
|                         var status = RotatingStatusMessages[state.Index++].Status; | ||||
|                         if (string.IsNullOrWhiteSpace(status)) | ||||
|                             return; | ||||
|                         PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value())); | ||||
|                         var shards = NadekoBot.Client.Shards; | ||||
|                         for (int i = 0; i < shards.Count; i++) | ||||
|                         { | ||||
|                             var curShard = shards.ElementAt(i); | ||||
|                             ShardSpecificPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value(curShard))); | ||||
|                             try { await shards.ElementAt(i).SetGameAsync(status).ConfigureAwait(false); } | ||||
|                             catch (Exception ex) | ||||
|                             { | ||||
|                                 ShardSpecificPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value(shards.ElementAt(i)))); | ||||
|                                 try { await shards.ElementAt(i).SetGameAsync(status).ConfigureAwait(false); } | ||||
|                                 catch (Exception ex) | ||||
|                                 { | ||||
|                                     _log.Warn(ex); | ||||
|                                 } | ||||
|                                 _log.Warn(ex); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
| @@ -107,17 +102,20 @@ namespace NadekoBot.Modules.Administration | ||||
|             [OwnerOnly] | ||||
|             public async Task RotatePlaying() | ||||
|             { | ||||
|                 using (var uow = DbHandler.UnitOfWork()) | ||||
|                 lock (_locker) | ||||
|                 { | ||||
|                     var config = uow.BotConfig.GetOrCreate(); | ||||
|                     using (var uow = DbHandler.UnitOfWork()) | ||||
|                     { | ||||
|                         var config = uow.BotConfig.GetOrCreate(); | ||||
|  | ||||
|                     RotatingStatuses = config.RotatingStatuses = !config.RotatingStatuses; | ||||
|                     await uow.CompleteAsync(); | ||||
|                         RotatingStatuses = config.RotatingStatuses = !config.RotatingStatuses; | ||||
|                         uow.Complete(); | ||||
|                     } | ||||
|                 } | ||||
|                 if (RotatingStatuses) | ||||
|                     await Context.Channel.SendConfirmAsync("🆗 **Rotating playing status enabled.**").ConfigureAwait(false); | ||||
|                     await ReplyConfirmLocalized("ropl_enabled").ConfigureAwait(false); | ||||
|                 else | ||||
|                     await Context.Channel.SendConfirmAsync("ℹ️ **Rotating playing status disabled.**").ConfigureAwait(false); | ||||
|                     await ReplyConfirmLocalized("ropl_disabled").ConfigureAwait(false); | ||||
|             } | ||||
|  | ||||
|             [NadekoCommand, Usage, Description, Aliases] | ||||
| @@ -133,7 +131,7 @@ namespace NadekoBot.Modules.Administration | ||||
|                     await uow.CompleteAsync(); | ||||
|                 } | ||||
|  | ||||
|                 await Context.Channel.SendConfirmAsync("✅ **Added.**").ConfigureAwait(false); | ||||
|                 await ReplyConfirmLocalized("ropl_added").ConfigureAwait(false); | ||||
|             } | ||||
|  | ||||
|             [NadekoCommand, Usage, Description, Aliases] | ||||
| @@ -141,11 +139,13 @@ namespace NadekoBot.Modules.Administration | ||||
|             public async Task ListPlaying() | ||||
|             { | ||||
|                 if (!RotatingStatusMessages.Any()) | ||||
|                     await Context.Channel.SendErrorAsync("❎ **No rotating playing statuses set.**"); | ||||
|                     await ReplyErrorLocalized("ropl_not_set").ConfigureAwait(false); | ||||
|                 else | ||||
|                 { | ||||
|                     var i = 1; | ||||
|                     await Context.Channel.SendConfirmAsync($"ℹ️ {Context.User.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}"))); | ||||
|                     await ReplyConfirmLocalized("ropl_list", | ||||
|                             string.Join("\n\t", RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}"))) | ||||
|                         .ConfigureAwait(false); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
| @@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Administration | ||||
|             { | ||||
|                 index -= 1; | ||||
|  | ||||
|                 string msg = ""; | ||||
|                 string msg; | ||||
|                 using (var uow = DbHandler.UnitOfWork()) | ||||
|                 { | ||||
|                     var config = uow.BotConfig.GetOrCreate(); | ||||
| @@ -168,7 +168,7 @@ namespace NadekoBot.Modules.Administration | ||||
|                     RotatingStatusMessages.RemoveAt(index); | ||||
|                     await uow.CompleteAsync(); | ||||
|                 } | ||||
|                 await Context.Channel.SendConfirmAsync($"🗑 **Removed the the playing message:** {msg}").ConfigureAwait(false); | ||||
|                 await ReplyConfirmLocalized("reprm", msg).ConfigureAwait(false); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
							
								
								
									
										55
									
								
								src/NadekoBot/Resources/ResponseStrings.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										55
									
								
								src/NadekoBot/Resources/ResponseStrings.Designer.cs
									
									
									
										generated
									
									
									
								
							| @@ -447,6 +447,61 @@ namespace NadekoBot.Resources { | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Removed the playing message: {0}. | ||||
|         /// </summary> | ||||
|         public static string administration_reprm { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("administration_reprm", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Added.. | ||||
|         /// </summary> | ||||
|         public static string administration_ropl_added { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("administration_ropl_added", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Rotating playing status disabled.. | ||||
|         /// </summary> | ||||
|         public static string administration_ropl_disabled { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("administration_ropl_disabled", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Rotating playing status enabled.. | ||||
|         /// </summary> | ||||
|         public static string administration_ropl_enabled { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("administration_ropl_enabled", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Here is a list of rotating statuses: | ||||
|         ///{0}. | ||||
|         /// </summary> | ||||
|         public static string administration_ropl_list { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("administration_ropl_list", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to No rotating playing statuses set.. | ||||
|         /// </summary> | ||||
|         public static string administration_ropl_not_set { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("administration_ropl_not_set", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to soft-banned (kicked). | ||||
|         /// </summary> | ||||
|   | ||||
| @@ -431,6 +431,25 @@ | ||||
|   <data name="administration_old_topic" xml:space="preserve"> | ||||
|     <value>Old Topic</value> | ||||
|   </data> | ||||
|   <data name="administration_reprm" xml:space="preserve"> | ||||
|     <value>Removed the playing message: {0}</value> | ||||
|   </data> | ||||
|   <data name="administration_ropl_added" xml:space="preserve"> | ||||
|     <value>Added.</value> | ||||
|   </data> | ||||
|   <data name="administration_ropl_disabled" xml:space="preserve"> | ||||
|     <value>Rotating playing status disabled.</value> | ||||
|   </data> | ||||
|   <data name="administration_ropl_enabled" xml:space="preserve"> | ||||
|     <value>Rotating playing status enabled.</value> | ||||
|   </data> | ||||
|   <data name="administration_ropl_list" xml:space="preserve"> | ||||
|     <value>Here is a list of rotating statuses: | ||||
| {0}</value> | ||||
|   </data> | ||||
|   <data name="administration_ropl_not_set" xml:space="preserve"> | ||||
|     <value>No rotating playing statuses set.</value> | ||||
|   </data> | ||||
|   <data name="administration_soft_banned_pl" xml:space="preserve"> | ||||
|     <value>soft-banned (kicked)</value> | ||||
|     <comment>PLURAL</comment> | ||||
| @@ -514,6 +533,12 @@ | ||||
|   <data name="administraton_user_unbanned" xml:space="preserve"> | ||||
|     <value>User Unbanned</value> | ||||
|   </data> | ||||
|   <data name="adminsitration_migration_done" xml:space="preserve"> | ||||
|     <value>Migration done!</value> | ||||
|   </data> | ||||
|   <data name="adminsitration_migration_error" xml:space="preserve"> | ||||
|     <value>Error while migrating, check bot's console for more information.</value> | ||||
|   </data> | ||||
|   <data name="adminsitration_presence_updates" xml:space="preserve"> | ||||
|     <value>Presence Updates</value> | ||||
|   </data> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user